Permalink
Browse files

Only mix in Capybara into :type => :acceptance examples

  • Loading branch information...
1 parent 9b7e6c7 commit bdde00afd7e412ba4c1632ec70b30648e505c14c @jnicklas jnicklas committed Jan 9, 2011
Showing with 27 additions and 12 deletions.
  1. +11 −6 README.rdoc
  2. +9 −5 lib/capybara/rspec.rb
  3. +7 −1 spec/rspec_spec.rb
View
@@ -90,15 +90,20 @@ If you prefer RSpec to using Cucumber, you can use the built in RSpec support:
You can now use it in your examples:
- it "signs me in" do
- within("#session") do
- fill_in 'Login', :with => 'user@example.com'
- fill_in 'Password', :with => 'password'
+ describe "the signup process", :type => :acceptance do
+ it "signs me in" do
+ within("#session") do
+ fill_in 'Login', :with => 'user@example.com'
+ fill_in 'Password', :with => 'password'
+ end
+ click_link 'Sign in'
end
- click_link 'Sign in'
end
-RSpec's metadata feature can be used to switch to a different driver. Use the
+Capybara is only included for examples which have the type
+<tt>:acceptance</tt>.
+
+RSpec's metadata feature can be used to switch to a different driver. Use
<tt>:js => true</tt> to switch to the javascript driver, or provide a
<tt>:driver</tt> option to switch to one specific driver. For example:
View
@@ -2,13 +2,17 @@
require 'capybara/dsl'
RSpec.configure do |config|
- config.include Capybara
+ config.include Capybara, :type => :acceptance
config.after do
- Capybara.reset_sessions!
- Capybara.use_default_driver
+ if example.metadata[:type] == :acceptance
+ Capybara.reset_sessions!
+ Capybara.use_default_driver
+ end
end
config.before do
- Capybara.current_driver = Capybara.javascript_driver if example.metadata[:js]
- Capybara.current_driver = example.metadata[:driver] if example.metadata[:driver]
+ if example.metadata[:type] == :acceptance
+ Capybara.current_driver = Capybara.javascript_driver if example.metadata[:js]
+ Capybara.current_driver = example.metadata[:driver] if example.metadata[:driver]
+ end
end
end
View
@@ -3,7 +3,7 @@
Capybara.app = TestApp
-describe 'capybara/rspec' do
+describe 'capybara/rspec', :type => :acceptance do
it "should include Capybara in rpsec" do
visit('/foo')
page.body.should include('Another World')
@@ -39,3 +39,9 @@
Capybara.current_driver.should == :culerity
end
end
+
+describe 'capybara/rspec', :type => :other do
+ it "should not include Capybara" do
+ expect { visit('/') }.to raise_error(NoMethodError)
+ end
+end

0 comments on commit bdde00a

Please sign in to comment.