13

I've followed all of the steps that I've been able to find online for configuring Rails 3 with Rspec 2 and Mocha. In my 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

And in 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

Still, when I use the Rails generator...

rails generate scaffold foo name:string

...I get the following in spec/controllers/foos_controller_spec.rb:

  def mock_foo(stubs={})
    @mock_foo ||= mock_model(Foo, stubs).as_null_object
  end

...which of course causes all specs to fail.

Does anyone know what I'm missing?

Thanks in advance.

Vega
  • 27,856
  • 27
  • 95
  • 103
Corey
  • 231
  • 1
  • 5
  • 1
    I am looking at this same problem now. Did you find a solution to it? I decided to just change the tests to use mocha and then turn it into a generator. – stellard Oct 26 '10 at 14:37
  • Just a note here.. you can use rspec, rspec-rails and capybara in your Gemfile without specifying the version now. They are compatible with Rails 3 now. – johnmcaliley Feb 12 '11 at 15:04
  • I'm having the same problem. I'm tempted to modify the existing generators but I don't want to duplicate something someone else has already done. – Paul Leader Apr 14 '11 at 15:13

1 Answers1

4

In application.rb you'll need something like the following:

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

Further information available here:

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

raggi
  • 1,290
  • 9
  • 12