Permalink
Browse files

respond_with matcher all cases covered

  • Loading branch information...
1 parent 10637cf commit 0a5c6b912d39f8320292e5b0b0ab3b474d84cbfd @croaky croaky committed with jferris Feb 5, 2009
@@ -22,15 +22,23 @@ def failure_message
"Expected status to be #{@status}"
end
+ def negative_failure_message
+ "Did not expect status to be #{@status} but was #{response_code}"
+ end
+
protected
def correct_status_code?
- @controller.response.response_code == @status
+ response_code == @status
end
def correct_status_code_range?
@status.is_a?(Range) &&
- @status.include?(@controller.response.response_code)
+ @status.include?(response_code)
+ end
+
+ def response_code
+ @controller.response.response_code
end
def symbol_to_status_code(potential_symbol)
@@ -14,6 +14,10 @@ class RespondWithMatcherTest < Test::Unit::TestCase # :nodoc:
should "accept responding with :success" do
assert_accepts respond_with(:success), @controller
end
+
+ should "reject responding with another status" do
+ assert_rejects respond_with(:error), @controller
+ end
end
context "a controller responding with redirect" do
@@ -28,6 +32,10 @@ class RespondWithMatcherTest < Test::Unit::TestCase # :nodoc:
should "accept responding with :redirect" do
assert_accepts respond_with(:redirect), @controller
end
+
+ should "reject responding with another status" do
+ assert_rejects respond_with(:error), @controller
+ end
end
context "a controller responding with missing" do
@@ -42,6 +50,10 @@ class RespondWithMatcherTest < Test::Unit::TestCase # :nodoc:
should "accept responding with :missing" do
assert_accepts respond_with(:missing), @controller
end
+
+ should "reject responding with another status" do
+ assert_rejects respond_with(:success), @controller
+ end
end
context "a controller responding with error" do
@@ -56,6 +68,10 @@ class RespondWithMatcherTest < Test::Unit::TestCase # :nodoc:
should "accept responding with :error" do
assert_accepts respond_with(:error), @controller
end
+
+ should "reject responding with another status" do
+ assert_rejects respond_with(:success), @controller
+ end
end
context "a controller responding with not implemented" do
@@ -70,6 +86,20 @@ class RespondWithMatcherTest < Test::Unit::TestCase # :nodoc:
should "accept responding with :not_implemented" do
assert_accepts respond_with(:not_implemented), @controller
end
+
+ should "reject responding with another status" do
+ assert_rejects respond_with(:success), @controller
+ end
+ end
+
+ context "a controller raising an error" do
+ setup do
+ @controller = build_response { raise RailsError }
+ end
+
+ should "reject responding with any status" do
+ assert_rejects respond_with(:success), @controller
+ end
end
end

0 comments on commit 0a5c6b9

Please sign in to comment.