-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
json_spec.rb
53 lines (42 loc) · 1.48 KB
/
json_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
require_relative '../spec_helper'
module Aws
describe Json do
describe '.load' do
subject(:load) { described_class.load(raw_json) }
shared_examples 'loads JSON correctly' do
let(:raw_json) { '{ "foo": "bar" }' }
it 'returns a hash with the JSON' do
expect(subject).to eq('foo' => 'bar')
end
context 'not JSON' do
# OJ gem raises EncodingError in this case
# OJ can also raise JSON::ParserError if using Oj.mimic_JSON
let(:raw_json) { '<ServiceUnavailableException/>' }
it 'raises a ParseError' do
expect { subject }.to raise_error(Aws::Json::ParseError)
end
end
context 'invalid JSON' do
let(:raw_json) { '{ "steve": }' }
it 'raises a ParseError' do
expect { subject }.to raise_error(Aws::Json::ParseError)
end
end
end
context 'when using oj gem' do
include_examples 'loads JSON correctly'
end
context 'when using bundled json' do
before do
engine, load_options, dump_options, errors =
described_class.send(:json_engine)
stub_const('Aws::Json::ENGINE', engine)
stub_const('Aws::Json::ENGINE_LOAD_OPTIONS', load_options)
stub_const('Aws::Json::ENGINE_DUMP_OPTIONS', dump_options)
stub_const('Aws::Json::ENGINE_ERRORS', errors)
end
include_examples 'loads JSON correctly'
end
end
end
end