2017-03-08 7 views
1

質問:Rails 5を使用する& Minitest-Railsには、新しいRailsアプリケーションのデフォルトをSpec-styleテストに設定する方法がありますか?デフォルトでMinitest-Railsの仕様書テスト

私はTDDを教えています。私たちが新しいアプリを作るたびに学生に変換させなければならないのは面倒です。

+1

あなたは 'rails new my_app -T'を使ってテストをスキップし、' rspec'をgemfileに追加して 'rspec init'を実行することができます。それは普通私がお勧めするものです – Anthony

+0

@anthonyええ、私はテストのためにrspecの代わりにMinitestを使いたいと思っています。 –

答えて

0

だから、@sonnaは私が探していたものの90%を持っていました。

私はと

-d postgresql 
-m ~/.template.rb 

、テンプレートと.railsrcファイル作成の助けになってしまった:

# .template.rb 
# Gems we've talked about in class, but which have absolutely nothing to do 
# with setting up spec-style testing. 
# Included here for convenience. 
gem_group :development do 
    # Improve the error message you get in the browser 
    gem 'better_errors' 

    # Use pry for rails console 
    gem 'pry-rails' 
end 

# Add some extra minitest support 
gem_group :test do 
    gem 'minitest-rails' 
    gem 'minitest-reporters' 
end 

# Add some code to some files to support spec-style testing 
# For these injections, indentation matters! 
inject_into_file 'config/application.rb', after: "class Application < Rails::Application\n" do 
    <<-'RUBY' 
    # Force new test files to be generated in the minitest-spec style 
    config.generators do |g| 
     g.test_framework :minitest, spec: true 
    end 
    RUBY 
end 

# Things to do after all the gems have been installed 
after_bundle do 
    # Run rails generate minitest:install 
    generate "minitest:install", "--force" 

    # Add minitest reporters support. This must be run after 
    # rails generate minitest:install, because that command 
    # changes test/test_helper.rb 
    inject_into_file 'test/test_helper.rb', after: 'require "minitest/rails"' do 
    <<-'RUBY' 

require "minitest/reporters" # for Colorized output 

# For colorful output! 
Minitest::Reporters.use!(
    Minitest::Reporters::SpecReporter.new, 
    ENV, 
    Minitest.backtrace_filter 
) 
    RUBY 
    end 
end 

これはspec-を使用してDBためのpostgres、およびMinitestレールとの私のプロジェクトを設定しますminitest-reportersを含んでいます。

0

あなたは、コンフィギュレーション、次のとtemplate.rbファイルを作成することができます:

gem_group :development, :test do 
    gem "rspec-rails" 
end 

after_bundle do 
    `rails g rspec:install` 
end 

をし、それがRailsのRSpecのを追加し、新しいRailsアプリケーションを構築する次のコマンドを

rails new my_app -T -m /path/to/template.rb 

を使用して新規のRailsプロジェクトをビルドしますgemfileにgemを追加し、RSpecのインストール手順を実行します。

そうでなければ、あらかじめビルドされたRails Gitリポジトリを提供し、その上に構築することができます。

参考文献:

+0

おかげさまで、私はrspecを使うのではなく、代わりにMinitestを使っています。 しかし、テンプレートは移動する方法かもしれません。 –

0

それはあなただけで追加する必要がconfig/application.rbで次のようになります。

config.generators do |g| g.test_framework :minitest, spec: true end

しかし、Minitest-Railsをデフォルトの仕様スタイルにする自動方法はありません。

私はrspecに行くことができましたが、初めからMinitestの生徒にMinitestを教えているので、Minitestにとどまっていました。