mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
Move remaining driver specs
This commit is contained in:
parent
1be49963e6
commit
d5334f6827
4 changed files with 126 additions and 171 deletions
|
@ -1,125 +0,0 @@
|
|||
# encoding: utf-8
|
||||
require 'spec_helper'
|
||||
require 'stringio'
|
||||
|
||||
describe Capybara::RackTest::Driver do
|
||||
before do
|
||||
@driver = TestSessions::RackTest.driver
|
||||
end
|
||||
|
||||
it "should throw an error when no rack app is given" do
|
||||
running do
|
||||
Capybara::RackTest::Driver.new(nil)
|
||||
end.should raise_error(ArgumentError)
|
||||
end
|
||||
|
||||
describe '#reset!' do
|
||||
it { @driver.visit('/foo'); lambda { @driver.reset! }.should change(@driver, :current_url).to('') }
|
||||
|
||||
it 'should reset headers' do
|
||||
@driver.header('FOO', 'BAR')
|
||||
@driver.visit('/get_header')
|
||||
@driver.body.should include('BAR')
|
||||
|
||||
@driver.reset!
|
||||
@driver.visit('/get_header')
|
||||
@driver.body.should_not include('BAR')
|
||||
end
|
||||
|
||||
it 'should reset response' do
|
||||
@driver.visit('/foo')
|
||||
lambda { @driver.response }.should_not raise_error
|
||||
@driver.reset!
|
||||
lambda { @driver.response }.should raise_error
|
||||
end
|
||||
|
||||
it 'should request response' do
|
||||
@driver.visit('/foo')
|
||||
lambda { @driver.request }.should_not raise_error
|
||||
@driver.reset!
|
||||
lambda { @driver.request }.should raise_error
|
||||
end
|
||||
end
|
||||
|
||||
describe ':headers option' do
|
||||
it 'should always set headers' do
|
||||
@driver = Capybara::RackTest::Driver.new(TestApp, :headers => {'HTTP_FOO' => 'foobar'})
|
||||
@driver.visit('/get_header')
|
||||
@driver.body.should include('foobar')
|
||||
end
|
||||
|
||||
it 'should keep headers on link clicks' do
|
||||
@driver = Capybara::RackTest::Driver.new(TestApp, :headers => {'HTTP_FOO' => 'foobar'})
|
||||
@driver.visit('/header_links')
|
||||
@driver.find('.//a').first.click
|
||||
@driver.body.should include('foobar')
|
||||
end
|
||||
|
||||
it 'should keep headers on form submit' do
|
||||
@driver = Capybara::RackTest::Driver.new(TestApp, :headers => {'HTTP_FOO' => 'foobar'})
|
||||
@driver.visit('/header_links')
|
||||
@driver.find('.//input').first.click
|
||||
@driver.body.should include('foobar')
|
||||
end
|
||||
|
||||
it 'should keep headers on redirects' do
|
||||
@driver = Capybara::RackTest::Driver.new(TestApp, :headers => {'HTTP_FOO' => 'foobar'})
|
||||
@driver.visit('/get_header_via_redirect')
|
||||
@driver.body.should include('foobar')
|
||||
end
|
||||
end
|
||||
|
||||
describe ':follow_redirects option' do
|
||||
it "defaults to following redirects" do
|
||||
@driver = Capybara::RackTest::Driver.new(TestApp)
|
||||
|
||||
@driver.visit('/redirect')
|
||||
@driver.response.header['Location'].should be_nil
|
||||
@driver.browser.current_url.should eq "#{@driver.browser.current_host}/landed"
|
||||
end
|
||||
|
||||
it "is possible to not follow redirects" do
|
||||
@driver = Capybara::RackTest::Driver.new(TestApp, :follow_redirects => false)
|
||||
|
||||
@driver.visit('/redirect')
|
||||
@driver.response.header['Location'].should eq "#{@driver.browser.current_host}/redirect_again"
|
||||
@driver.browser.current_url.should eq "#{@driver.browser.current_host}/redirect"
|
||||
end
|
||||
end
|
||||
|
||||
describe ':redirect_limit option' do
|
||||
context "with default redirect limit" do
|
||||
before do
|
||||
@driver = Capybara::RackTest::Driver.new(TestApp)
|
||||
end
|
||||
|
||||
it "should follow 5 redirects" do
|
||||
@driver.visit("/redirect/5/times")
|
||||
@driver.body.should include('redirection complete')
|
||||
end
|
||||
|
||||
it "should not follow more than 6 redirects" do
|
||||
running do
|
||||
@driver.visit("/redirect/6/times")
|
||||
end.should raise_error(Capybara::InfiniteRedirectError)
|
||||
end
|
||||
end
|
||||
|
||||
context "with 21 redirect limit" do
|
||||
before do
|
||||
@driver = Capybara::RackTest::Driver.new(TestApp, :redirect_limit => 21)
|
||||
end
|
||||
|
||||
it "should follow 21 redirects" do
|
||||
@driver.visit("/redirect/21/times")
|
||||
@driver.body.should include('redirection complete')
|
||||
end
|
||||
|
||||
it "should not follow more than 21 redirects" do
|
||||
running do
|
||||
@driver.visit("/redirect/22/times")
|
||||
end.should raise_error(Capybara::InfiniteRedirectError)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,46 +0,0 @@
|
|||
require 'spec_helper'
|
||||
require 'rbconfig'
|
||||
|
||||
describe Capybara::Selenium::Driver do
|
||||
before do
|
||||
@driver = TestSessions::Selenium.driver
|
||||
end
|
||||
|
||||
unless RbConfig::CONFIG['host_os'] =~ /mswin|mingw/
|
||||
it "should not interfere with forking child processes" do
|
||||
# Launch a browser, which registers the at_exit hook
|
||||
browser = Capybara::Selenium::Driver.new(TestApp).browser
|
||||
|
||||
# Fork an unrelated child process. This should not run the code in the at_exit hook.
|
||||
begin
|
||||
pid = fork { "child" }
|
||||
Process.wait2(pid)[1].exitstatus.should == 0
|
||||
rescue NotImplementedError
|
||||
# Fork unsupported (e.g. on JRuby)
|
||||
end
|
||||
|
||||
browser.quit
|
||||
end
|
||||
end
|
||||
|
||||
describe "exit codes" do
|
||||
before do
|
||||
@current_dir = Dir.getwd
|
||||
Dir.chdir(File.join(File.dirname(__FILE__), '..', '..'))
|
||||
end
|
||||
|
||||
after do
|
||||
Dir.chdir(@current_dir)
|
||||
end
|
||||
|
||||
it "should have return code 1 when running selenium_driver_rspec_failure.rb" do
|
||||
`rspec spec/fixtures/selenium_driver_rspec_failure.rb`
|
||||
$?.exitstatus.should be 1
|
||||
end
|
||||
|
||||
it "should have return code 0 when running selenium_driver_rspec_success.rb" do
|
||||
`rspec spec/fixtures/selenium_driver_rspec_success.rb`
|
||||
$?.exitstatus.should be 0
|
||||
end
|
||||
end
|
||||
end
|
|
@ -62,3 +62,91 @@ describe Capybara::Session do
|
|||
it_should_behave_like "session with status code support"
|
||||
end
|
||||
end
|
||||
|
||||
describe Capybara::RackTest::Driver do
|
||||
before do
|
||||
@driver = TestSessions::RackTest.driver
|
||||
end
|
||||
|
||||
describe ':headers option' do
|
||||
it 'should always set headers' do
|
||||
@driver = Capybara::RackTest::Driver.new(TestApp, :headers => {'HTTP_FOO' => 'foobar'})
|
||||
@driver.visit('/get_header')
|
||||
@driver.body.should include('foobar')
|
||||
end
|
||||
|
||||
it 'should keep headers on link clicks' do
|
||||
@driver = Capybara::RackTest::Driver.new(TestApp, :headers => {'HTTP_FOO' => 'foobar'})
|
||||
@driver.visit('/header_links')
|
||||
@driver.find('.//a').first.click
|
||||
@driver.body.should include('foobar')
|
||||
end
|
||||
|
||||
it 'should keep headers on form submit' do
|
||||
@driver = Capybara::RackTest::Driver.new(TestApp, :headers => {'HTTP_FOO' => 'foobar'})
|
||||
@driver.visit('/header_links')
|
||||
@driver.find('.//input').first.click
|
||||
@driver.body.should include('foobar')
|
||||
end
|
||||
|
||||
it 'should keep headers on redirects' do
|
||||
@driver = Capybara::RackTest::Driver.new(TestApp, :headers => {'HTTP_FOO' => 'foobar'})
|
||||
@driver.visit('/get_header_via_redirect')
|
||||
@driver.body.should include('foobar')
|
||||
end
|
||||
end
|
||||
|
||||
describe ':follow_redirects option' do
|
||||
it "defaults to following redirects" do
|
||||
@driver = Capybara::RackTest::Driver.new(TestApp)
|
||||
|
||||
@driver.visit('/redirect')
|
||||
@driver.response.header['Location'].should be_nil
|
||||
@driver.browser.current_url.should eq "#{@driver.browser.current_host}/landed"
|
||||
end
|
||||
|
||||
it "is possible to not follow redirects" do
|
||||
@driver = Capybara::RackTest::Driver.new(TestApp, :follow_redirects => false)
|
||||
|
||||
@driver.visit('/redirect')
|
||||
@driver.response.header['Location'].should eq "#{@driver.browser.current_host}/redirect_again"
|
||||
@driver.browser.current_url.should eq "#{@driver.browser.current_host}/redirect"
|
||||
end
|
||||
end
|
||||
|
||||
describe ':redirect_limit option' do
|
||||
context "with default redirect limit" do
|
||||
before do
|
||||
@driver = Capybara::RackTest::Driver.new(TestApp)
|
||||
end
|
||||
|
||||
it "should follow 5 redirects" do
|
||||
@driver.visit("/redirect/5/times")
|
||||
@driver.body.should include('redirection complete')
|
||||
end
|
||||
|
||||
it "should not follow more than 6 redirects" do
|
||||
running do
|
||||
@driver.visit("/redirect/6/times")
|
||||
end.should raise_error(Capybara::InfiniteRedirectError)
|
||||
end
|
||||
end
|
||||
|
||||
context "with 21 redirect limit" do
|
||||
before do
|
||||
@driver = Capybara::RackTest::Driver.new(TestApp, :redirect_limit => 21)
|
||||
end
|
||||
|
||||
it "should follow 21 redirects" do
|
||||
@driver.visit("/redirect/21/times")
|
||||
@driver.body.should include('redirection complete')
|
||||
end
|
||||
|
||||
it "should not follow more than 21 redirects" do
|
||||
running do
|
||||
@driver.visit("/redirect/22/times")
|
||||
end.should raise_error(Capybara::InfiniteRedirectError)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -25,5 +25,43 @@ describe Capybara::Session do
|
|||
it_should_behave_like "session with window support"
|
||||
it_should_behave_like "session without headers support"
|
||||
it_should_behave_like "session without status code support"
|
||||
|
||||
unless RbConfig::CONFIG['host_os'] =~ /mswin|mingw/
|
||||
it "should not interfere with forking child processes" do
|
||||
# Launch a browser, which registers the at_exit hook
|
||||
browser = Capybara::Selenium::Driver.new(TestApp).browser
|
||||
|
||||
# Fork an unrelated child process. This should not run the code in the at_exit hook.
|
||||
begin
|
||||
pid = fork { "child" }
|
||||
Process.wait2(pid)[1].exitstatus.should == 0
|
||||
rescue NotImplementedError
|
||||
# Fork unsupported (e.g. on JRuby)
|
||||
end
|
||||
|
||||
browser.quit
|
||||
end
|
||||
end
|
||||
|
||||
describe "exit codes" do
|
||||
before do
|
||||
@current_dir = Dir.getwd
|
||||
Dir.chdir(File.join(File.dirname(__FILE__), '..', '..'))
|
||||
end
|
||||
|
||||
after do
|
||||
Dir.chdir(@current_dir)
|
||||
end
|
||||
|
||||
it "should have return code 1 when running selenium_driver_rspec_failure.rb" do
|
||||
`rspec spec/fixtures/selenium_driver_rspec_failure.rb`
|
||||
$?.exitstatus.should be 1
|
||||
end
|
||||
|
||||
it "should have return code 0 when running selenium_driver_rspec_success.rb" do
|
||||
`rspec spec/fixtures/selenium_driver_rspec_success.rb`
|
||||
$?.exitstatus.should be 0
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue