[rspec-users] Configuring RSpec for Integration Test

David Chelimsky dchelimsky at gmail.com
Sat Dec 18 18:54:08 EST 2010


On Dec 18, 2010, at 5:32 PM, Sarah Allen wrote:

> David Chelimsky wrote in post #969325:
>> Per "Webrat and Capybara" on http://relishapp.com/rspec/rspec-rails, all
>> you should need now is this in your Gemfile:
>> 
>>  gem "capybara"
>> 
>> Cheers,
>> David
> 
> I did that, but then it didn't recognize my named route "root_path" or 
> the capybara method "visit"
> 
> I wondered whether it was because I was creating a new "integration" 
> directory that needed it's own special config somehow... but I'm just 
> guessing.

Yes - that's the problem. For rspec to do what it does implicitly you need to put things in a standard set of directories. What you're thinking of as integration specs go in spec/requests.

If you need to use spec/integration instead, then you'll need to tell RSpec to include RSpec::Rails::RequestExampleGroup in those examples. You can do that on a per group basis, like this:

describe "something" do
  include RSpec::Rails::RequestExampleGroup
  ...
end

Or globally like this:

RSpec.configure do |config|
  config.include RSpec::Rails::RequestExampleGroup,
                 :example_group => {
		   :file_path => /spec\/integration/
                 }
end

Or via a combination of config and per-group metadata, like this:

RSpec.configure do |config|
  config.include RSpec::Rails::RequestExampleGroup, :type => :integration
end

describe "something", :type => :integration do
  ..
end

HTH,
David


More information about the rspec-users mailing list