Permalink
Browse files

Forgot to eval the json block against the situation

  • Loading branch information...
1 parent 6bac7b6 commit cc3acfabfdbacf1d75487e59dcad6c84e48f4a77 @gus gus committed May 12, 2010
Showing with 10 additions and 10 deletions.
  1. +7 −8 lib/chicago/riot/macros.rb
  2. +3 −2 test/riot_macros_test.rb
@@ -29,15 +29,14 @@ def asserts_location(expected_path)
# asserts_json_response({"foo" => "bar"})
# asserts_json_response('{"foo":"bar"}')
# asserts_json_response("text/javascript;charset=utf-8", {"foo" => "bar"})
- # asserts_json_response { {"foo" => @some_value} }
- # asserts_json_response("text/javascript;charset=utf-8") { {"foo" => @some_value} }
+ # asserts_json_response { {"foo" => @some_value}.to_json }
+ # asserts_json_response("text/javascript;charset=utf-8") { {"foo" => @some_value}.to_json }
def asserts_json_response(*args, &block)
- json = block_given? ? instance_eval(&block) : args.pop
-
- json = json.to_json unless json.instance_of?(String)
- asserts("response body has JSON") do
- last_response.body
- end.equals(json)
+ unless block_given?
+ json = args.pop
+ json = json.to_json unless json.instance_of?(String)
+ end
+ asserts("response body has JSON") { last_response.body }.equals(&(block || lambda {json}))
asserts_content_type(args.empty? ? 'application/json' : args.shift)
end
@@ -35,8 +35,9 @@
end # with special content-type
context "with content expectation provided as block" do
+ helper(:bar_value) { "bar" }
setup { get('/json-with-content-type') }
- asserts_json_response("text/javascript;charset=utf-8") { {:foo => "bar"} }
- end # with special content-type
+ asserts_json_response("text/javascript;charset=utf-8") { {:foo => bar_value}.to_json }
+ end # with content expectation provided as block
end # json response
end

0 comments on commit cc3acfa

Please sign in to comment.