Skip to content

Commit 1386cb7

Browse files
committed
Standardise meta spec and add symbolized source doc
Refactored the meta spec to align it with the pattern provided in the links and attributes specs. Incorporate symbolized source document tests inline with the attributes and relationships specs
1 parent 2d6fe92 commit 1386cb7

File tree

1 file changed

+39
-18
lines changed

1 file changed

+39
-18
lines changed

spec/jsonapi/meta_spec.rb

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,46 @@
1-
RSpec.describe JSONAPI::RSpec, '#have_meta' do
2-
context 'when providing no value' do
3-
it 'succeeds when meta is present' do
4-
expect('meta' => {}).to have_meta
5-
end
1+
RSpec.describe JSONAPI::RSpec do
2+
json_doc =
3+
{
4+
'meta' => {
5+
'foo' => 'bar'
6+
}
7+
}
68

7-
it 'fails when meta is absent' do
8-
expect({}).not_to have_meta
9-
end
10-
end
9+
symbol_doc =
10+
{
11+
meta: {
12+
foo: 'bar'
13+
}
14+
}
1115

12-
context 'when providing a value' do
13-
it 'succeeds when meta matches' do
14-
expect('meta' => { foo: 'bar' }).to have_meta(foo: 'bar')
15-
end
16+
describe '#have_meta' do
17+
[json_doc, symbol_doc].each do |doc|
18+
subject { doc }
19+
before(:each) { RSpec.configuration.allow_symbolized_jsonapi = (doc == symbol_doc) }
1620

17-
it 'fails when meta mismatches' do
18-
expect('meta' => { foo: 'bar' }).not_to have_meta(bar: 'baz')
19-
end
21+
context 'when providing no value' do
22+
it 'succeeds when meta is present' do
23+
is_expected.to have_meta
24+
end
25+
26+
it 'fails when meta is absent' do
27+
expect({}).not_to have_meta
28+
end
29+
end
30+
31+
context 'when providing a value' do
32+
it 'succeeds when meta matches' do
33+
is_expected.to have_meta('foo' => 'bar')
34+
end
35+
36+
it 'fails when meta mismatches' do
37+
is_expected.not_to have_meta('foo' => 'baz')
38+
end
2039

21-
it 'fails when meta is absent' do
22-
expect({}).not_to have_meta(foo: 'bar')
40+
it 'fails when meta is absent' do
41+
expect({}).not_to have_meta('foo' => 'bar')
42+
end
43+
end
2344
end
2445
end
2546
end

0 commit comments

Comments
 (0)