LoginSignup
28
23

More than 5 years have passed since last update.

rails g 実行時テストファイルを作らないようにする方法

Last updated at Posted at 2015-09-04

1.アプリケーション作成時にtestファイルを作らないようにする

rails newする際、次のようなオプションを指定して実行します。

ターミナル
& rails new myApp -T

-Tオプション(または--skip-test-unit)をつけることで、test::unitを組み込まない状態でrails newができます。

2.すでに作成したアプリケーションに対して適用する場合

application.rbファイルのclass Application < Rails::Application内を次のように編集します。

application.rb
module Practice
  class Application < Rails::Application
    # ---------------追記部分--------------
    config.generators do |g|
        g.test_framework false
    end
    #----------------追記終了--------------
    # Settings in config/environments/* take precedence over those specified here.
    # Application configuration should go into files in config/initializers
    # -- all .rb files in that directory are automatically loaded.

    # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
    # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
    # config.time_zone = 'Central Time (US & Canada)'

    # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
    # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
    # config.i18n.default_locale = :de
  end
end

このように記述することでrails g modelなどを実行した時、テストファイルを作成することがなくなります。

参考url

1.rails g コマンドでテストを作らないようにする方法
2.Rails ドキュメント railsコマンド(rails)
3.Railsのgenerateコマンドを俺好みに設定する
4.Ruby on Rails: Switch from test_unit to rspec
(g.test_frameworkの指定の仕方を参考にしました。)

28
23
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
28
23