Permalink
Browse files

Ability to provide expected content-type to asserts_json_response

  • Loading branch information...
1 parent 4724aa5 commit d84be4a6ad2931fb987b1b35bc08ae0763f1db54 @gus gus committed May 10, 2010
Showing with 24 additions and 2 deletions.
  1. +4 −2 lib/chicago/riot/macros.rb
  2. +20 −0 test/riot_tests/riot_macros_test.rb
@@ -25,8 +25,10 @@ def asserts_location(expected_path)
end.matches(expected_path)
end
- def asserts_json_response(json)
- asserts_content_type 'application/json'
+ def asserts_json_response(*args)
+ content_type = args.length > 1 ? args.shift : 'application/json'
+ json = args.shift
+ asserts_content_type content_type
json = json.to_json unless json.instance_of?(String)
json
@@ -5,11 +5,31 @@
mock_app {
helpers Sinatra::Chicago::Responders
get("/redirector") { redirect '/foo/bar' }
+
+ get("/basic-json") do
+ content_type 'application/json'
+ {:foo => "bar"}.to_json
+ end
+
+ get("/json-with-content-type") do
+ content_type 'text/javascript', :charset => "utf-8"
+ {:foo => "bar"}.to_json
+ end
}
end
context "asserts redirected to" do
setup { get('/redirector') }
asserts_redirected_to('/foo/bar')
end # asserts redirected to
+
+ context "basic json response" do
+ setup { get('/basic-json') }
+ asserts_json_response({:foo => "bar"})
+ end # asserts redirected to
+
+ context "json response with special content-type" do
+ setup { get('/json-with-content-type') }
+ asserts_json_response("text/javascript;charset=utf-8", {:foo => "bar"})
+ end # asserts redirected to
end

0 comments on commit d84be4a

Please sign in to comment.