Module: RSpecJSONAPISerializer::Matchers
- Defined in:
- lib/rspec_jsonapi_serializer/matchers.rb,
lib/rspec_jsonapi_serializer/matchers/base.rb,
lib/rspec_jsonapi_serializer/matchers/have_id_matcher.rb,
lib/rspec_jsonapi_serializer/matchers/have_one_matcher.rb,
lib/rspec_jsonapi_serializer/matchers/belong_to_matcher.rb,
lib/rspec_jsonapi_serializer/matchers/have_link_matcher.rb,
lib/rspec_jsonapi_serializer/matchers/have_many_matcher.rb,
lib/rspec_jsonapi_serializer/matchers/have_meta_matcher.rb,
lib/rspec_jsonapi_serializer/matchers/have_type_matcher.rb,
lib/rspec_jsonapi_serializer/matchers/association_matcher.rb,
lib/rspec_jsonapi_serializer/matchers/have_attribute_matcher.rb,
lib/rspec_jsonapi_serializer/matchers/have_link_matchers/as_matcher.rb,
lib/rspec_jsonapi_serializer/matchers/have_meta_matchers/as_matcher.rb,
lib/rspec_jsonapi_serializer/matchers/have_attribute_matchers/as_matcher.rb,
lib/rspec_jsonapi_serializer/matchers/association_matchers/serializer_matcher.rb,
lib/rspec_jsonapi_serializer/matchers/association_matchers/id_method_name_matcher.rb,
lib/rspec_jsonapi_serializer/matchers/association_matchers/object_method_name_matcher.rb
Defined Under Namespace
Modules: AssociationMatchers, HaveAttributeMatchers, HaveLinkMatchers, HaveMetaMatchers Classes: AssociationMatcher, Base, BelongToMatcher, HaveAttributeMatcher, HaveIdMatcher, HaveLinkMatcher, HaveManyMatcher, HaveMetaMatcher, HaveOneMatcher, HaveTypeMatcher
Instance Method Summary collapse
-
#belong_to(expected) ⇒ Object
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).
-
#have_attribute(expected) ⇒ Object
(also: #serialize_attribute)
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”.
-
#have_id(expected) ⇒ Object
This allows us to assert ids on a serializer, e.g.: expect(serializer).to have_id(:slug).
-
#have_link(expected) ⇒ Object
(also: #serialize_link)
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”.
-
#have_many(expected) ⇒ Object
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).
-
#have_meta(expected) ⇒ Object
(also: #serialize_meta)
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”.
-
#have_one(expected) ⇒ Object
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).
-
#have_type(expected) ⇒ Object
This allows us to assert types on a serializer, e.g.: expect(serializer).to have_type(:salesforce_serializer).
Instance Method Details
#belong_to(expected) ⇒ Object
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)
20 21 22 |
# File 'lib/rspec_jsonapi_serializer/matchers.rb', line 20 def belong_to(expected) BelongToMatcher.new(expected) end |
#have_attribute(expected) ⇒ Object Also known as: serialize_attribute
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(‘[email protected]’)
28 29 30 |
# File 'lib/rspec_jsonapi_serializer/matchers.rb', line 28 def have_attribute(expected) HaveAttributeMatcher.new(expected) end |
#have_id(expected) ⇒ Object
This allows us to assert ids on a serializer, e.g.: expect(serializer).to have_id(:slug)
36 37 38 |
# File 'lib/rspec_jsonapi_serializer/matchers.rb', line 36 def have_id(expected) HaveIdMatcher.new(expected) end |
#have_link(expected) ⇒ Object Also known as: serialize_link
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’)
44 45 46 |
# File 'lib/rspec_jsonapi_serializer/matchers.rb', line 44 def have_link(expected) HaveLinkMatcher.new(expected) end |
#have_many(expected) ⇒ Object
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)
56 57 58 |
# File 'lib/rspec_jsonapi_serializer/matchers.rb', line 56 def have_many(expected) HaveManyMatcher.new(expected) end |
#have_meta(expected) ⇒ Object Also known as: serialize_meta
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’)
64 65 66 |
# File 'lib/rspec_jsonapi_serializer/matchers.rb', line 64 def (expected) HaveMetaMatcher.new(expected) end |
#have_one(expected) ⇒ Object
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)
76 77 78 |
# File 'lib/rspec_jsonapi_serializer/matchers.rb', line 76 def have_one(expected) HaveOneMatcher.new(expected) end |
#have_type(expected) ⇒ Object
This allows us to assert types on a serializer, e.g.: expect(serializer).to have_type(:salesforce_serializer)
82 83 84 |
# File 'lib/rspec_jsonapi_serializer/matchers.rb', line 82 def have_type(expected) HaveTypeMatcher.new(expected) end |