mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
Use the :request type for RSpec example groups
This commit is contained in:
parent
fb16abb308
commit
558e7b2d4d
3 changed files with 18 additions and 8 deletions
13
README.rdoc
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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -3,8 +3,8 @@ require 'capybara/rspec'
|
|||
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue