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 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: 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. 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: https://github.com/blazingcloud/cucumber_lesson -- Posted via http://www.ruby-forum.com/.
David Chelimsky
2010-Dec-18 20:47 UTC
[rspec-users] Configuring RSpec for Integration Test
On Dec 18, 2010, at 2:11 PM, Sarah Allen 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-caThat blog post was based on a beta version of rspec-rails 2 before we got the integration worked out :) 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> > > 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: > 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.> > 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: > https://github.com/blazingcloud/cucumber_lesson
On Sat, Dec 18, 2010 at 2:47 PM, David Chelimsky <dchelimsky at gmail.com>wrote:> On Dec 18, 2010, at 2:11 PM, Sarah Allen 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> > That blog post was based on a beta version of rspec-rails 2 before we got > the integration worked out :) > > 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 > > > > > > > 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: > > 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. > > > > > 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: > > https://github.com/blazingcloud/cucumber_lesson > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20101218/ec76d55a/attachment.html>
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, > DavidI 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 -- Posted via http://www.ruby-forum.com/.
David Chelimsky
2010-Dec-18 23:54 UTC
[rspec-users] Configuring RSpec for Integration Test
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
Getting back to this after the holidays... David Chelimsky 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/ > } > endI 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 -- Posted via http://www.ruby-forum.com/.
David Chelimsky
2011-Jan-07 15:01 UTC
[rspec-users] Configuring RSpec for Integration Test
On Jan 7, 2011, at 8:41 AM, Sarah Allen wrote:> Getting back to this after the holidays... > > David Chelimsky 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-capybaraIn 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> > Thanks! > Sarah
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 -- Posted via http://www.ruby-forum.com/.
David Chelimsky
2011-Jan-07 15:21 UTC
[rspec-users] Configuring RSpec for Integration Test
On Jan 7, 2011, at 9:12 AM, Sarah Allen 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> > Thanks! > Sarah