Ruby on Rails: Switch from test_unit to rspec

2019-01-30 02:13发布

I'm going through a tutorial that has suggested using rspec, but I have already gone through a lot of default rails installation. I really don't want to have to redo the installation at all. Anyway, when I run

$ rails g integration_test named

I get

  invoke  test_unit
  create    test/integration/named_test.rb

When I run bundle, various rspec gems are listed, but test_unit is not. The tutorial seems to have rails invoke rspec instead of test_unit without doing anything additional. How do I get rails to use rspec with the integration test generator command?

9条回答
神经病院院长
2楼-- · 2019-01-30 02:51

What I found that I did that some of the other methods works still is to check my spelling....I had what @tovodeverett had grouping rspec-rails with :development and :test but spelt development incorrectly. That fixed my issue but I was generating tests with test_unit instead of rspec.

查看更多
够拽才男人
3楼-- · 2019-01-30 02:51

In config/application, add this code

 config.generators do |g|
       g.test_framework  :rspec
       g.integration_tool :rspec
 end
查看更多
我欲成王,谁敢阻挡
4楼-- · 2019-01-30 02:54

In your config/application.rb file :

config.generators do |g|
  g.test_framework :rspec
end

Now when you run your generators (example rails generate scaffold post), you get rspec test files. Remember to restart your server. For more information on generators see:

RailsCasts #216 Generators in Rails 3

If you really want to use the integration_test generator you'll need to specifically modify the command:

rails g integration_test named --integration-tool=rspec
查看更多
登录 后发表回答