Class: ElabsMatchers::Matchers::Persist::PersistMatcher

Inherits:
Struct
  • Object
show all
Defined in:
lib/elabs_matchers/matchers/persist.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#attributeObject

Returns the value of attribute attribute

Returns:

  • (Object)

    the current value of attribute



6
7
8
# File 'lib/elabs_matchers/matchers/persist.rb', line 6

def attribute
  @attribute
end

#recordObject (readonly)

Returns the value of attribute record.



7
8
9
# File 'lib/elabs_matchers/matchers/persist.rb', line 7

def record
  @record
end

#valueObject

Returns the value of attribute value

Returns:

  • (Object)

    the current value of value



6
7
8
# File 'lib/elabs_matchers/matchers/persist.rb', line 6

def value
  @value
end

Instance Method Details

#descriptionObject



28
29
30
# File 'lib/elabs_matchers/matchers/persist.rb', line 28

def description
  "persist #{attribute}"
end

#failure_messageObject Also known as: failure_message_for_should



18
19
20
# File 'lib/elabs_matchers/matchers/persist.rb', line 18

def failure_message
  "Expected #{attribute} to be persisted and retain its value of #{value.inspect} but the value was #{@final_value.inspect}."
end

#failure_message_when_negatedObject Also known as: failure_message_for_should_not



23
24
25
# File 'lib/elabs_matchers/matchers/persist.rb', line 23

def failure_message_when_negated
  "Expected #{attribute} not to be persisted and retain its value of #{value.inspect} but it did."
end

#matches?(record) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
12
13
14
15
16
# File 'lib/elabs_matchers/matchers/persist.rb', line 9

def matches?(record)
  record.send(:"#{attribute}=", value)
  record.save!
  record = record.class.find(record.id)
  @final_value = record.send(attribute)

  @final_value == value
end