Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting Rails 3 Generators with Rspec 2 and Mocha

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.

like image 373
Corey Avatar asked Aug 02 '10 20:08

Corey


1 Answers

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

like image 161
raggi Avatar answered Sep 30 '22 20:09

raggi