Exception: Shoulda::Matchers::ActiveModel::AllowValueMatcher::AttributeChangedValueError

Inherits:
Error
  • Object
show all
Defined in:
lib/shoulda/matchers/active_model/allow_value_matcher/attribute_changed_value_error.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Error

create, #initialize, #inspect

Constructor Details

This class inherits a constructor from Shoulda::Matchers::Error

Instance Attribute Details

#attribute_nameObject

Returns the value of attribute attribute_name.



7
8
9
# File 'lib/shoulda/matchers/active_model/allow_value_matcher/attribute_changed_value_error.rb', line 7

def attribute_name
  @attribute_name
end

#matcher_nameObject

Returns the value of attribute matcher_name.



7
8
9
# File 'lib/shoulda/matchers/active_model/allow_value_matcher/attribute_changed_value_error.rb', line 7

def matcher_name
  @matcher_name
end

#modelObject

Returns the value of attribute model.



7
8
9
# File 'lib/shoulda/matchers/active_model/allow_value_matcher/attribute_changed_value_error.rb', line 7

def model
  @model
end

#value_readObject

Returns the value of attribute value_read.



7
8
9
# File 'lib/shoulda/matchers/active_model/allow_value_matcher/attribute_changed_value_error.rb', line 7

def value_read
  @value_read
end

#value_writtenObject

Returns the value of attribute value_written.



7
8
9
# File 'lib/shoulda/matchers/active_model/allow_value_matcher/attribute_changed_value_error.rb', line 7

def value_written
  @value_written
end

Instance Method Details

#messageObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/shoulda/matchers/active_model/allow_value_matcher/attribute_changed_value_error.rb', line 10

def message
  Shoulda::Matchers.word_wrap <<-MESSAGE
The #{matcher_name} matcher attempted to set :#{attribute_name} on
#{model.name} to #{value_written.inspect}, but when the attribute was
read back, it had stored #{value_read.inspect} instead.

This creates a problem because it means that the model is behaving in a
way that is interfering with the test -- there's a mismatch between the
test that you wrote and test that we actually ran.

There are a couple of reasons why this could be happening:

* ActiveRecord is typecasting the incoming value.
* The writer method for :#{attribute_name} has been overridden so that
  incoming values are changed in some way.

If this exception makes sense to you and you wish to bypass it, try
adding the `ignoring_interference_by_writer` qualifier onto the end of
your matcher. If the test still does not pass after that, then you may
need to do something different.

If you need help, feel free to ask a question on the shoulda-matchers
issues list:

https://github.com/thoughtbot/shoulda-matchers/issues
  MESSAGE
end

#successful?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/shoulda/matchers/active_model/allow_value_matcher/attribute_changed_value_error.rb', line 38

def successful?
  false
end