Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

  • Loading branch information...
commit e9f7ace2d432d7fb23843b388a4ae5ee419f8e07 1 parent 3ad2781
Justin Knowlden gus authored
8 lib/riot/action_controller/context_macros/asserts_response.rb
@@ -2,8 +2,12 @@ module RiotRails
2 2 module ActionController
3 3 module AssertsResponse
4 4
5   - def asserts_response
6   - asserts("response") { response }
  5 + def asserts_response(method_name=nil)
  6 + if method_name
  7 + asserts("response ##{method_name.to_s}") { response.send(method_name) }
  8 + else
  9 + asserts("response") { response }
  10 + end
7 11 end
8 12
9 13 end # AssertsResponse
31 test/action_controller/context_macros/asserts_response_test.rb
@@ -6,13 +6,32 @@
6 6 asserts("asserts_response returns") { topic.asserts_response }.raises(NoMethodError)
7 7 end # for context not representing an ActionController
8 8
  9 + helper(:situation) do
  10 + a_situation = Riot::Situation.new
  11 + a_situation.helper(:response) { OpenStruct.new(:status => 200) }
  12 + a_situation
  13 + end
  14 +
9 15 setup { Riot::Context.new(RoomsController) {} }
10 16
11   - asserts("asserts_response returns") { topic.asserts_response }.kind_of(Riot::Assertion)
  17 + context "when referenced without arguments" do
  18 + setup do
  19 + # situation = Riot::Situation.new
  20 + # situation.helper(:response) { OpenStruct.new(:status => 200) }
  21 + topic.asserts_response
  22 + end
  23 +
  24 + asserts_topic.kind_of(Riot::Assertion)
  25 + asserts(:to_s).equals("asserts response")
  26 +
  27 + asserts("the result of assertion responds to :status") do
  28 + topic.responds_to(:status).run(situation).first
  29 + end.equals(:pass)
  30 + end # when referenced without arguments
12 31
13   - asserts("the result of assertion responds to :status") do
14   - situation = Riot::Situation.new
15   - situation.helper(:response) { OpenStruct.new(:status => 200) }
16   - topic.asserts_response.responds_to(:status).run(situation).first
17   - end.equals(:pass)
  32 + context "with method name provided" do
  33 + setup { topic.asserts_response(:status).equals(200) }
  34 + asserts(:to_s).equals("asserts response #status")
  35 + asserts("output of running the test") { topic.run(situation).first }.equals(:pass)
  36 + end
18 37 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.