Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Use the :request type for RSpec example groups

  • Loading branch information...
commit 558e7b2d4d0fd3a2d73542b971d6129d40984dbf 1 parent fb16abb
@joliss joliss authored
Showing with 18 additions and 8 deletions.
  1. +9 −4 README.rdoc
  2. +7 −2 lib/capybara/rspec.rb
  3. +2 −2 spec/rspec_spec.rb
View
13 README.rdoc
@@ -90,7 +90,7 @@ by adding the following line (typically to your <tt>spec_helper.rb</tt> file):
You can now use it in your examples:
- describe "the signup process", :type => :acceptance do
+ describe "the signup process", :type => :request do
it "signs me in" do
within("#session") do
fill_in 'Login', :with => 'user@example.com'
@@ -100,9 +100,14 @@ You can now use it in your examples:
end
end
-Capybara is only included for examples which have the type
-<tt>:acceptance</tt>. (Note that if you use the <tt>rspec-rails</tt> gem,
-Capybara is also included in controller, request, and mailer examples.)
+Capybara is only included for examples with <tt>:type => :request</tt> (or
+<tt>:acceptance</tt> for compatibility).
+
+Note that if you use the <tt>rspec-rails</tt> gem, <tt>:type => :request</tt>
+is automatically set on all files under <tt>spec/requests</tt> (and also
+<tt>spec/integration</tt>), so that's a good directory to place your Capybara specs
+in. <tt>rspec-rails</tt> will also automatically include Capybara in
+<tt>:controller</tt> and <tt>:mailer</tt> examples.
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
View
9 lib/capybara/rspec.rb
@@ -1,18 +1,23 @@
require 'capybara'
require 'capybara/dsl'
+require 'rspec/core'
require 'capybara/rspec_matchers'
RSpec.configure do |config|
+ config.include Capybara, :type => :request
config.include Capybara, :type => :acceptance
+ config.include Capybara::RSpecMatchers, :type => :request
config.include Capybara::RSpecMatchers, :type => :acceptance
+ # The before and after blocks must run instantaneously, because Capybara
+ # might not actually be used in all examples where it's included.
config.after do
- if example.metadata[:type] == :acceptance
+ if self.class.include?(Capybara)
Capybara.reset_sessions!
Capybara.use_default_driver
end
end
config.before do
- if example.metadata[:type] == :acceptance
+ if self.class.include?(Capybara)
Capybara.current_driver = Capybara.javascript_driver if example.metadata[:js]
Capybara.current_driver = example.metadata[:driver] if example.metadata[:driver]
end
View
4 spec/rspec_spec.rb
@@ -3,8 +3,8 @@
Capybara.app = TestApp
-describe 'capybara/rspec', :type => :acceptance do
- it "should include Capybara in rpsec" do
+describe 'capybara/rspec', :type => :request do
+ it "should include Capybara in rspec" do
visit('/foo')
page.body.should include('Another World')
end
Please sign in to comment.
Something went wrong with that request. Please try again.