diff --git a/lib/webrat/core/session.rb b/lib/webrat/core/session.rb index 04e25af..5b6beb5 100644 --- a/lib/webrat/core/session.rb +++ b/lib/webrat/core/session.rb @@ -82,7 +82,7 @@ module Webrat end def success_code? - (200..299).include?(response_code) + (200..499).include?(response_code) end def exception_caught? diff --git a/spec/api/clicks_area_spec.rb b/spec/api/clicks_area_spec.rb index c7fbc29..ffb9562 100644 --- a/spec/api/clicks_area_spec.rb +++ b/spec/api/clicks_area_spec.rb @@ -21,10 +21,22 @@ describe "clicks_area" do Berlin EOS - @session.response_code = 404 + @session.response_code = 501 lambda { @session.clicks_area "Berlin" }.should raise_error end + [200, 300, 400, 499].each do |status| + it "should consider the status code as success" do + @session.response_body = <<-EOS + + Berlin + + EOS + @session.response_code = status + lambda { @session.clicks_area "Berlin" }.should_not raise_error + end + end + it "should fail if the area doesn't exist" do @session.response_body = <<-EOS diff --git a/spec/api/clicks_button_spec.rb b/spec/api/clicks_button_spec.rb index 8fcf495..553e9aa 100644 --- a/spec/api/clicks_button_spec.rb +++ b/spec/api/clicks_button_spec.rb @@ -50,10 +50,22 @@ describe "clicks_button" do EOS - @session.response_code = 404 + @session.response_code = 501 lambda { @session.clicks_button }.should raise_error end + [200, 300, 400, 499].each do |status| + it "should consider the status code as success" do + @session.response_body = <<-EOS +
+ +
+ EOS + @session.response_code = status + lambda { @session.clicks_button }.should_not raise_error + end + end + it "should submit the first form by default" do @session.response_body = <<-EOS
diff --git a/spec/api/clicks_link_spec.rb b/spec/api/clicks_link_spec.rb index d0a1f46..5d5a633 100644 --- a/spec/api/clicks_link_spec.rb +++ b/spec/api/clicks_link_spec.rb @@ -155,10 +155,20 @@ describe "clicks_link" do @session.response_body = <<-EOS Link text EOS - @session.response_code = 404 + @session.response_code = 501 lambda { @session.clicks_link "Link text" }.should raise_error end + [200, 300, 400, 499].each do |status| + it "should consider the status code as success" do + @session.response_body = <<-EOS + Link text + EOS + @session.response_code = status + lambda { @session.clicks_link "Link text" }.should_not raise_error + end + end + it "should fail is the link doesn't exist" do @session.response_body = <<-EOS Link text diff --git a/spec/api/visits_spec.rb b/spec/api/visits_spec.rb index df1ccb4..b6baaa4 100644 --- a/spec/api/visits_spec.rb +++ b/spec/api/visits_spec.rb @@ -12,10 +12,17 @@ describe "visits" do end it "should assert valid response" do - @session.response_code = 404 + @session.response_code = 501 lambda { @session.visits("/") }.should raise_error end + [200, 300, 400, 499].each do |status| + it "should consider the status code as success" do + @session.response_code = status + lambda { @session.visits("/") }.should_not raise_error + end + end + it "should require a visit before manipulating page" do lambda { @session.fills_in "foo", :with => "blah" }.should raise_error end @@ -33,4 +40,4 @@ describe "visits with referer" do @session.visits("/") end -end \ No newline at end of file +end