Class: JSONAPI::Resources::Matchers::HaveModelName

Inherits:
Object
  • Object
show all
Defined in:
lib/jsonapi/resources/matchers/have_model_name.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ HaveModelName

Returns a new instance of HaveModelName.



8
9
10
# File 'lib/jsonapi/resources/matchers/have_model_name.rb', line 8

def initialize(name)
  self.expected_model_name = name
end

Instance Attribute Details

#expected_model_nameObject

Returns the value of attribute expected_model_name.



6
7
8
# File 'lib/jsonapi/resources/matchers/have_model_name.rb', line 6

def expected_model_name
  @expected_model_name
end

#resourceObject

Returns the value of attribute resource.



6
7
8
# File 'lib/jsonapi/resources/matchers/have_model_name.rb', line 6

def resource
  @resource
end

Instance Method Details

#descriptionObject



17
18
19
# File 'lib/jsonapi/resources/matchers/have_model_name.rb', line 17

def description
  %Q(have model name `#{expected_model_name}`)
end

#failure_messageObject



21
22
23
24
# File 'lib/jsonapi/resources/matchers/have_model_name.rb', line 21

def failure_message
  resource_name = resource.class.name.demodulize
  %Q(expected `#{resource_name}` to have the model name `#{expected_model_name}`)
end

#matches?(resource) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
15
# File 'lib/jsonapi/resources/matchers/have_model_name.rb', line 12

def matches?(resource)
  self.resource = resource
  self.resource.class._model_name.to_s == self.expected_model_name.to_s
end