forked from thoughtbot/shoulda-matchers
/
attribute_changed_value_error.rb
45 lines (37 loc) · 1.45 KB
/
attribute_changed_value_error.rb
1
2
3
4
5
6
7
8
9
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
37
38
39
40
41
42
43
44
45
module Shoulda
module Matchers
module ActiveModel
class AllowValueMatcher
# @private
class AttributeChangedValueError < Shoulda::Matchers::Error
attr_accessor :matcher_name, :model, :attribute_name, :value_written,
:value_read
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
def successful?
false
end
end
end
end
end
end