Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add test for malformed JSON parsing

  • Loading branch information...
commit ae63bc66a397140b58f8525a386d5e94291bc7c1 1 parent 2a82360
@remiprev authored
Showing with 5 additions and 0 deletions.
  1. +5 −0 spec/middleware/first_level_parse_json_spec.rb
View
5 spec/middleware/first_level_parse_json_spec.rb
@@ -5,6 +5,7 @@
subject { described_class.new }
let(:body_without_errors) { "{\"id\": 1, \"name\": \"Tobias Fünke\", \"metadata\": 3}" }
let(:body_with_errors) { "{\"id\": 1, \"name\": \"Tobias Fünke\", \"errors\": { \"name\": [ \"not_valid\", \"should_be_present\" ] }, \"metadata\": 3}" }
+ let(:body_with_malformed_json) { "wut." }
it "parses body as json" do
subject.parse(body_without_errors).tap do |json|
@@ -30,6 +31,10 @@
subject.parse(body_with_errors)[:errors].should eq({:name => [ 'not_valid', 'should_be_present']})
end
+ it 'ensures that malformed JSON throws an exception' do
+ expect { subject.parse(body_with_malformed_json) }.to raise_error(MultiJson::LoadError)
+ end
+
context 'with status code 204' do
it 'returns an empty body' do
env = { :status => 204 }
Please sign in to comment.
Something went wrong with that request. Please try again.