質問:Rails 5を使用する& Minitest-Railsには、新しいRailsアプリケーションのデフォルトをSpec-styleテストに設定する方法がありますか?デフォルトでMinitest-Railsの仕様書テスト
私はTDDを教えています。私たちが新しいアプリを作るたびに学生に変換させなければならないのは面倒です。
質問:Rails 5を使用する& Minitest-Railsには、新しいRailsアプリケーションのデフォルトをSpec-styleテストに設定する方法がありますか?デフォルトでMinitest-Railsの仕様書テスト
私はTDDを教えています。私たちが新しいアプリを作るたびに学生に変換させなければならないのは面倒です。
だから、@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を含んでいます。
あなたは、コンフィギュレーション、次のと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リポジトリを提供し、その上に構築することができます。
参考文献:
おかげさまで、私はrspecを使うのではなく、代わりにMinitestを使っています。 しかし、テンプレートは移動する方法かもしれません。 –
それはあなただけで追加する必要がconfig/application.rb
で次のようになります。
config.generators do |g| g.test_framework :minitest, spec: true end
しかし、Minitest-Railsをデフォルトの仕様スタイルにする自動方法はありません。
私はrspecに行くことができましたが、初めからMinitestの生徒にMinitestを教えているので、Minitestにとどまっていました。
あなたは 'rails new my_app -T'を使ってテストをスキップし、' rspec'をgemfileに追加して 'rspec init'を実行することができます。それは普通私がお勧めするものです – Anthony
@anthonyええ、私はテストのためにrspecの代わりにMinitestを使いたいと思っています。 –