module RSpecJSONAPISerializer::Matchers

Public Instance Methods

belong_to(expected) click to toggle source

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
have_attribute(expected) click to toggle source

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
Also aliased as: serialize_attribute
have_id(expected) click to toggle source

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
have_many(expected) click to toggle source

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
have_meta(expected) click to toggle source

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
Also aliased as: serialize_meta
have_one(expected) click to toggle source

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
have_type(expected) click to toggle source

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
serialize_attribute(expected)
Alias for: have_attribute
serialize_meta(expected)
Alias for: have_meta