module RSpecJSONAPISerializer::Matchers
Public Instance Methods
This allows us to assert attributes on a serializer, e.g.: expect(serializer).to belong_to
(:team) If you have a custom serializer, you can assert its value with the `serializer` submatcher expect(serializer).to belong_to
(:team).serializer(TeamSerializer) If you have a custom id, you can assert its value with the `id_method_name` submatcher expect(serializer).to belong_to
(:team).id_method_name(:team_slug)
# File lib/rspec_jsonapi_serializer/matchers.rb, line 20 def belong_to(expected) BelongToMatcher.new(expected) end
This allows us to assert attributes on a serializer, e.g.: expect(serializer).to have_attribute
(:email) You can test custom attributes by using the submatcher “as”. expect(serializer).to have_attribute
(:email).as('john.doe@example.com')
# File lib/rspec_jsonapi_serializer/matchers.rb, line 28 def have_attribute(expected) HaveAttributeMatcher.new(expected) end
This allows us to assert ids on a serializer, e.g.: expect(serializer).to have_id
(:slug)
# File lib/rspec_jsonapi_serializer/matchers.rb, line 36 def have_id(expected) HaveIdMatcher.new(expected) end
This allows us to assert links on a serializer, e.g.: expect(serializer).to have_link
(:self) You can test custom links by using the submatcher “as”. expect(serializer).to have_link
(:self).as('example.com/users/1')
# File lib/rspec_jsonapi_serializer/matchers.rb, line 44 def have_link(expected) HaveLinkMatcher.new(expected) end
This allows us to assert attributes on a serializer, e.g.: expect(serializer).to have_many
(:teams) If you have a custom serializer, you can assert its value with the `serializer` submatcher expect(serializer).to have_many
(:teams).serializer(TeamSerializer) If you have a custom id, you can assert its value with the `id_method_name` submatcher expect(serializer).to have_many
(:teams).id_method_name(:team_slugs)
# File lib/rspec_jsonapi_serializer/matchers.rb, line 56 def have_many(expected) HaveManyMatcher.new(expected) end
This allows us to assert metadata on a serializer, e.g.: expect(serializer).to have_meta
(:foo) You can test custom metadata by using the submatcher “as”. expect(serializer).to have_meta
(:foo).as('bar')
# File lib/rspec_jsonapi_serializer/matchers.rb, line 64 def have_meta(expected) HaveMetaMatcher.new(expected) end
This allows us to assert attributes on a serializer, e.g.: expect(serializer).to have_one
(:team) If you have a custom serializer, you can assert its value with the `serializer` submatcher expect(serializer).to have_one
(:team).serializer(TeamSerializer) If you have a custom id, you can assert its value with the `id_method_name` submatcher expect(serializer).to have_one
(:team).id_method_name(:team_slug)
# File lib/rspec_jsonapi_serializer/matchers.rb, line 76 def have_one(expected) HaveOneMatcher.new(expected) end
This allows us to assert types on a serializer, e.g.: expect(serializer).to have_type
(:salesforce_serializer)
# File lib/rspec_jsonapi_serializer/matchers.rb, line 82 def have_type(expected) HaveTypeMatcher.new(expected) end