Getting Rails 3 Generators with Rspec 2 and Mocha
Asked Answered
M

1

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.

Melindamelinde answered 2/8, 2010 at 20:19 Comment(3)
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.Walloon
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.Unblessed
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.Whoso
A
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

Argal answered 6/3, 2011 at 10:48 Comment(1)
When setting RSpec as my test framework, I still get the RSpec mocking, not the mocha mocking.Gantz

© 2022 - 2024 — McMap. All rights reserved.