forked from collectiveidea/json_spec
/
expectations_test.rb
38 lines (28 loc) · 1.15 KB
/
expectations_test.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
require "test_helper"
describe "User", :to_json do
let(:user) { OpenStruct.new id: 42, first_name: "Steve", last_name: "Richert", friends: [] }
let(:names) { %({"first_name":"Steve","last_name":"Richert"}) }
subject { user.to_json }
it "includes names" do
user.to_json.must be_json_eql(names).excluding("friends")
end
it { must be_json_eql(names).excluding("friends") }
must { be_json_eql(names).excluding("friends") }
it "includes the ID" do
user.to_json.must have_json_path("id")
user.to_json.must have_json_type(Integer).at_path("id")
end
it { must have_json_path("id") }
must { have_json_path("id") }
it { must have_json_type(Integer).at_path("id") }
must { have_json_type(Integer).at_path("id") }
it "includes friends" do
user.to_json.must have_json_size(0).at_path("friends")
friend = OpenStruct.new first_name: "Catie", last_name: "Richert"
user.friends << friend
user.to_json.must have_json_size(1).at_path("friends")
user.to_json.must include_json(friend.to_json).at_path("friends")
end
it { must have_json_size(0).at_path("friends") }
must { have_json_size(0).at_path("friends") }
end