我已经遵循了所有可以在线查找使用Rspec 2和Mocha配置Rails 3的步骤.在我的宝石文件中:
group :development do gem 'rails3-generators' gem "rspec",'>= 2.0.0.beta.19' gem "rspec-rails",'>= 2.0.0.beta.19' end group :test do gem "faker" gem "rspec",'>= 2.0.0.beta.19' gem "machinist",'>= 2.0.0.beta1' gem "mocha" gem "capybara",">= 0.3.9" end
在spec / spec_helper.rb中:
RSpec.configure do |config| config.mock_with :mocha config.fixture_path = "#{::Rails.root}/spec/fixtures" config.use_transactional_fixtures = true end
不过,当我使用Rails生成器
rails generate scaffold foo name:string
…我在spec / controllers / foos_controller_spec.rb中得到以下内容:
def mock_foo(stubs={}) @mock_foo ||= mock_model(Foo,stubs).as_null_object end
…这当然会导致所有规格失败.
有人知道我失踪了吗?
提前致谢.
解决方法
在application.rb中,您将需要以下内容:
config.generators do |g| g.test_framework :rspec end
更多信息:
http://guides.rubyonrails.org/generators.html#customizing-your-workflow