Configuring RSpec for Integration Test

In using RSpec for integration testing with Capybara, I was surprised
thave I needed to do extra configuration. I started with the config
from this blog post:

and I pared it down to only what I needed to write an integration test,
and ended up with

require ‘action_dispatch’
require ‘capybara/rails’
require ‘capybara/dsl’

module RSpec::Rails
module IntegrationExampleGroup
include ActionDispatch::Integration::Runner
include Capybara

def app
    ::Rails.application
end

RSpec.configure do |c|
  c.include self, :example_group => { :file_path =>

/\bspec/integration// }
end

end
end

I understand why I would need special config to include Capybara, but I
don’t understand why I need to define app and include the
ActionDisplatch stuff – I thought that would come automagically with
rspec-rails by just including spec_helper.

My whole little test project is here:

Before I give this to other folks as example code, I would really like
to understand it and know if there is an easier/better/more recommended
way to do this.

Thanks,
Sarah
work http://blazingcloud.net/
personal blog http://www.ultrasaurus.com

p.s. I know cucumber is an alternate way. I’m doing a compare/contrast.
The cucumber version is here:

On Dec 18, 2010, at 2:11 PM, Sarah A. wrote:

In using RSpec for integration testing with Capybara, I was surprised
thave I needed to do extra configuration. I started with the config
from this blog post:
http://codingfrontier.com/integration-testing-setup-with-rspec-2-and-ca

That blog post was based on a beta version of rspec-rails 2 before we
got the integration worked out :slight_smile:

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

module IntegrationExampleGroup
end
https://github.com/blazingcloud/rspec-capybara

Before I give this to other folks as example code, I would really like
to understand it and know if there is an easier/better/more recommended
way to do this.

David C. 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.

Thanks,
Sarah

On Sat, Dec 18, 2010 at 2:47 PM, David C.
[email protected]wrote:

On Dec 18, 2010, at 2:11 PM, Sarah A. wrote:

In using RSpec for integration testing with Capybara, I was surprised
thave I needed to do extra configuration. I started with the config
from this blog post:
http://codingfrontier.com/integration-testing-setup-with-rspec-2-and-ca

Also, you might want to check out Steak… it runs inside Rspec, I have
been
using in lieu of Cucumber starting this week and I am very happy and
enjoying the process:

https://github.com/cavalle/steak

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

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

On Jan 7, 2011, at 8:41 AM, Sarah A. wrote:

end
I tried the approach with an include and it worked fine, which I pushed
to a branch here:

https://github.com/blazingcloud/rspec-capybara/tree/simple_custom_spec_directory_config

Also, just changing the directory name to “requests” worked fine too:
https://github.com/blazingcloud/rspec-capybara

In the 2.4 release it works for spec/integration as well:
http://blog.davidchelimsky.net/2011/01/02/rspec-240-is-released/

I couldn’t find anywhere this was documented. Did I miss a page? If so,
maybe we can write a blog post post and improve the SEO on this basic
bit of info. Or point to where it should be documented and maybe we can
help with that.

Should be documented here: http://relishapp.com/rspec/rspec-rails

Info on contributing/helping is here:
http://blog.davidchelimsky.net/2010/12/23/rspec-2-documentation-2/

Any help would be wonderful!

Cheers,
David

Getting back to this after the holidays…

David C. wrote in post #969342:

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

I tried the approach with an include and it worked fine, which I pushed
to a branch here:
https://github.com/blazingcloud/rspec-capybara/tree/simple_custom_spec_directory_config

Also, just changing the directory name to “requests” worked fine too:
https://github.com/blazingcloud/rspec-capybara

I couldn’t find anywhere this was documented. Did I miss a page? If so,
maybe we can write a blog post post and improve the SEO on this basic
bit of info. Or point to where it should be documented and maybe we can
help with that.

Thanks!
Sarah

On Jan 7, 2011, at 9:12 AM, Sarah A. wrote:

I don’t see any cucumber scenarios on integration testing with webrat or
capybara. Did I miss those?

You did not! They are just missing.

or should we add some?

Yes! Please!!!

We have a couple of volunteer interns at Blazing Cloud who are learning
TDD and may be able to help with docs. I just want to be sure to steep
them in the right direction.

Awesome. TIA.

Cheers,
David

I don’t see any cucumber scenarios on integration testing with webrat or
capybara. Did I miss those? or should we add some?

We have a couple of volunteer interns at Blazing Cloud who are learning
TDD and may be able to help with docs. I just want to be sure to steep
them in the right direction.

Thanks!
Sarah