Created
August 21, 2010 16:32
-
-
Save nruth/542529 to your computer and use it in GitHub Desktop.
Capybara rack-test response status code checking
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe "when some redirect mappings are present in the Medify::PAGE_REDIRECTS hash" do | |
before(:each) do | |
Medify::PAGE_REDIRECTS['/abstract-reasoning-subtest-advice-by-medify'] = '/advice-pages/abstract-reasoning-subtest-advice-by-medify' | |
Medify::PAGE_REDIRECTS['/decision-analysis-subtest-advice-by-medify'] = '/advice-pages/decision-analysis-subtest-advice-by-medify' | |
end | |
describe "GET :show, :path => abstract-reasoning-subtest-advice-by-medify" do | |
subject {get :show, :path => 'abstract-reasoning-subtest-advice-by-medify'} | |
it {should be_redirect} | |
it {should redirect_to('/advice-pages/abstract-reasoning-subtest-advice-by-medify')} | |
it "should redirect with status 301 Moved Permanently" do | |
subject | |
assert_response :moved_permanently | |
end | |
end | |
describe "GET :show, :path => decision-analysis-subtest-advice-by-medify" do | |
subject {get :show, :path => 'decision-analysis-subtest-advice-by-medify'} | |
it {should be_redirect} | |
it {should redirect_to('/advice-pages/decision-analysis-subtest-advice-by-medify')} | |
it "should redirect with status 301 Moved Permanently" do | |
subject | |
assert_response :moved_permanently | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
When /^I use the "([^"]*)" I should be redirected to "([^"]*)" with status code (\d+)$/ do |old_url, redirect_url, status_code| | |
current_driver = Capybara.current_session.driver | |
raise "untested driver, step probably wont work" unless current_driver.is_a? Capybara::Driver::RackTest | |
response = current_driver.get old_url | |
URI.parse(response.location).path.should == redirect_url | |
response.status.should == status_code.to_i | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment