Permalink
Browse files

since multi_json is a runtime dependency now, don't need to rescue Lo…

…adError in this test
  • Loading branch information...
1 parent 607917c commit 0de0af0721e6e1a57e10f75ba2a62d5082366776 @seamusabshere committed Oct 22, 2011
Showing with 24 additions and 30 deletions.
  1. +24 −30 test/spec_rack_post_body_content_type_parser.rb
@@ -1,40 +1,34 @@
require 'test/spec'
require 'rack/mock'
-begin
- require 'rack/contrib/post_body_content_type_parser'
+require 'rack/contrib/post_body_content_type_parser'
- context "Rack::PostBodyContentTypeParser" do
-
- specify "should parse 'application/json' requests" do
- params = params_for_request '{"key":"value"}', "application/json"
- params['key'].should.equal "value"
- end
-
- specify "should parse 'application/json; charset=utf-8' requests" do
- params = params_for_request '{"key":"value"}', "application/json; charset=utf-8"
- params['key'].should.equal "value"
- end
-
- specify "should parse 'application/json' requests with empty body" do
- params = params_for_request "", "application/json"
- params.should.equal({})
- end
-
- specify "shouldn't affect form-urlencoded requests" do
- params = params_for_request("key=value", "application/x-www-form-urlencoded")
- params['key'].should.equal "value"
- end
+context "Rack::PostBodyContentTypeParser" do
+ specify "should parse 'application/json' requests" do
+ params = params_for_request '{"key":"value"}', "application/json"
+ params['key'].should.equal "value"
end
- def params_for_request(body, content_type)
- env = Rack::MockRequest.env_for "/", {:method => "POST", :input => body, "CONTENT_TYPE" => content_type}
- app = lambda { |env| [200, {'Content-Type' => 'text/plain'}, Rack::Request.new(env).POST] }
- Rack::PostBodyContentTypeParser.new(app).call(env).last
+ specify "should parse 'application/json; charset=utf-8' requests" do
+ params = params_for_request '{"key":"value"}', "application/json; charset=utf-8"
+ params['key'].should.equal "value"
end
-rescue LoadError => e
- # Missing dependency JSON, skipping tests.
- STDERR.puts "WARN: Skipping Rack::PostBodyContentTypeParser tests (json not installed)"
+ specify "should parse 'application/json' requests with empty body" do
+ params = params_for_request "", "application/json"
+ params.should.equal({})
+ end
+
+ specify "shouldn't affect form-urlencoded requests" do
+ params = params_for_request("key=value", "application/x-www-form-urlencoded")
+ params['key'].should.equal "value"
+ end
+
+end
+
+def params_for_request(body, content_type)
+ env = Rack::MockRequest.env_for "/", {:method => "POST", :input => body, "CONTENT_TYPE" => content_type}
+ app = lambda { |env| [200, {'Content-Type' => 'text/plain'}, Rack::Request.new(env).POST] }
+ Rack::PostBodyContentTypeParser.new(app).call(env).last
end

0 comments on commit 0de0af0

Please sign in to comment.