Implemented a response_code method in the Capybara::Driver::Base class that raises Capybara::NotSupportedByDriverError.

This commit is contained in:
Gareth Townsend 2010-06-07 11:13:57 +10:00
parent 46962e1278
commit 072e697130
11 changed files with 47 additions and 0 deletions

View File

@ -25,6 +25,10 @@ class Capybara::Driver::Base
def response_headers
raise Capybara::NotSupportedByDriverError
end
def response_code
raise Capybara::NotSupportedByDriverError
end
def body
raise NotImplementedError

View File

@ -35,6 +35,7 @@ module Capybara
def_delegator :driver, :cleanup!
def_delegator :driver, :current_url
def_delegator :driver, :response_headers
def_delegator :driver, :response_code
def_delegator :driver, :visit
def_delegator :driver, :body
def_delegator :driver, :source

View File

@ -130,6 +130,22 @@ shared_examples_for "driver with header support" do
end
end
shared_examples_for "driver with response code support" do
it "should make the response code available through response_code" do
@driver.visit('/with_simple_html')
@driver.response_code.should == '200'
end
end
shared_examples_for "driver without response code support" do
it "should raise when trying to access the response code available through response_code" do
@driver.visit('/with_simple_html')
lambda {
@driver.response_code
}.should raise_error(Capybara::NotSupportedByDriverError)
end
end
shared_examples_for "driver with frame support" do
describe '#within_frame' do
before(:each) do

View File

@ -0,0 +1,19 @@
shared_examples_for "session with response code support" do
describe '#response_code' do
it "should return response codes" do
@session.visit('/with_simple_html')
@session.response_code.should == '200'
end
end
end
shared_examples_for "session without response code support" do
describe "#response_code" do
before{ @session.visit('/with_simple_html') }
it "should raise an error" do
running {
@session.response_code
}.should raise_error(Capybara::NotSupportedByDriverError)
end
end
end

View File

@ -9,6 +9,7 @@ if RUBY_PLATFORM =~ /java/
it_should_behave_like "driver"
it_should_behave_like "driver with javascript support"
it_should_behave_like "driver with header support"
it_should_behave_like "driver without response code support"
end
else

View File

@ -8,5 +8,6 @@ describe Capybara::Driver::Culerity do
it_should_behave_like "driver"
it_should_behave_like "driver with javascript support"
it_should_behave_like "driver with header support"
it_should_behave_like "driver without response code support"
end

View File

@ -13,5 +13,6 @@ describe Capybara::Driver::RackTest do
it_should_behave_like "driver"
it_should_behave_like "driver with header support"
it_should_behave_like "driver without response code support"
end

View File

@ -20,4 +20,5 @@ describe Capybara::Driver::Culerity do
it_should_behave_like "driver"
it_should_behave_like "driver with javascript support"
it_should_behave_like "driver with header support"
it_should_behave_like "driver without response code support"
end

View File

@ -21,6 +21,7 @@ if RUBY_PLATFORM =~ /java/
it_should_behave_like "session"
it_should_behave_like "session with javascript support"
it_should_behave_like "session with headers support"
it_should_behave_like "session without response code support"
end
else
puts "#{File.basename(__FILE__)} requires JRuby; skipping.."

View File

@ -21,5 +21,6 @@ describe Capybara::Session do
it_should_behave_like "session"
it_should_behave_like "session with javascript support"
it_should_behave_like "session with headers support"
it_should_behave_like "session without response code support"
end
end

View File

@ -29,5 +29,6 @@ describe Capybara::Session do
it_should_behave_like "session"
it_should_behave_like "session without javascript support"
it_should_behave_like "session with headers support"
it_should_behave_like "session without response code support"
end
end