Skip to content
Browse files

asserts_repsonse now takes a method name to be called on the response

  • Loading branch information...
1 parent 3ad2781 commit e9f7ace2d432d7fb23843b388a4ae5ee419f8e07 @gus gus committed May 18, 2010
View
8 lib/riot/action_controller/context_macros/asserts_response.rb
@@ -2,8 +2,12 @@ module RiotRails
module ActionController
module AssertsResponse
- def asserts_response
- asserts("response") { response }
+ def asserts_response(method_name=nil)
+ if method_name
+ asserts("response ##{method_name.to_s}") { response.send(method_name) }
+ else
+ asserts("response") { response }
+ end
end
end # AssertsResponse
View
31 test/action_controller/context_macros/asserts_response_test.rb
@@ -6,13 +6,32 @@
asserts("asserts_response returns") { topic.asserts_response }.raises(NoMethodError)
end # for context not representing an ActionController
+ helper(:situation) do
+ a_situation = Riot::Situation.new
+ a_situation.helper(:response) { OpenStruct.new(:status => 200) }
+ a_situation
+ end
+
setup { Riot::Context.new(RoomsController) {} }
- asserts("asserts_response returns") { topic.asserts_response }.kind_of(Riot::Assertion)
+ context "when referenced without arguments" do
+ setup do
+ # situation = Riot::Situation.new
+ # situation.helper(:response) { OpenStruct.new(:status => 200) }
+ topic.asserts_response
+ end
+
+ asserts_topic.kind_of(Riot::Assertion)
+ asserts(:to_s).equals("asserts response")
+
+ asserts("the result of assertion responds to :status") do
+ topic.responds_to(:status).run(situation).first
+ end.equals(:pass)
+ end # when referenced without arguments
- asserts("the result of assertion responds to :status") do
- situation = Riot::Situation.new
- situation.helper(:response) { OpenStruct.new(:status => 200) }
- topic.asserts_response.responds_to(:status).run(situation).first
- end.equals(:pass)
+ context "with method name provided" do
+ setup { topic.asserts_response(:status).equals(200) }
+ asserts(:to_s).equals("asserts response #status")
+ asserts("output of running the test") { topic.run(situation).first }.equals(:pass)
+ end
end # An asserts_response context macro

0 comments on commit e9f7ace

Please sign in to comment.
Something went wrong with that request. Please try again.