使用Rspec 2和Mocha获取Rails 3生成器

时间:2010-08-02 20:19:14

标签: ruby ruby-on-rails-3 rspec mocha

我已经按照我在网上找到的所有步骤来配置Rails 3和Mocha的Rails 3。在我的Gemfile中:

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 "rspec-rails", '>= 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

...当然会导致所有规格都失败。

有谁知道我错过了什么?

提前致谢。

1 个答案:

答案 0 :(得分:4)

在application.rb中,您需要以下内容:

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

此处提供更多信息:

http://guides.rubyonrails.org/generators.html#customizing-your-workflow