public
Fork of freelancing-god/active-matchers
Description: Helpful rspec matchers for testing validations and associations.
Homepage: http://am.freelancing-gods.com
Clone URL: git://github.com/Narnach/active-matchers.git
Added error messages to the confirm_unique matcher.
Narnach (author)
Mon Jul 07 08:11:53 -0700 2008
commit  5bd4f9c5943f8ab29f353a6d41e3564eebe01b5d
tree    35c3b5b2cbb0b4376db658e1f7b4f6e5b3c7bc9a
parent  3849a2171571e4ec6dfbe3fe5288d0ec1d226590
...
122
123
124
125
 
 
 
 
126
127
128
 
 
 
 
129
130
131
 
 
 
 
 
132
133
134
...
122
123
124
 
125
126
127
128
129
130
 
131
132
133
134
135
136
 
137
138
139
140
141
142
143
144
0
@@ -122,13 +122,23 @@ module ActiveMatchers
0
         # Create second, which will be invalid because unique values
0
         # are duplicated
0
         obj = @model.send @new_action, @base_attributes
0
- return false if obj.valid?
0
+ if obj.valid?
1
+ @error = "#{@model.name} should not be valid when it is a duplicate"
0
+ return false
0
+ end
0
         # Change the values of the unique attributes to remove collisions
0
         @attributes.each do |attribute|
0
- return false if obj.errors.on(attribute).empty?
0
+ if obj.errors.on(attribute).empty?
0
+ @error = "#{@model.name} should have a value collision for #{attribute}"
0
+ return false
0
+ end
0
           obj.send "#{attribute.to_s}=", "#{@base_attributes[attribute]} - Edit"
0
         end
0
- return obj.valid?
0
+ unless obj.valid?
0
+ @error = "#{@model.name} should be valid without duplicate values"
0
+ return false
0
+ end
0
+ true
0
       end
0
       
0
       def confirm_one_of_many

Comments

  • I’m going to go through and change all the error messages to something like:

    Model.valid? should be true when …, but returned false

    It’s a little more verbose but it clearly shows what is going on in the matcher.

  • Narnach Tue Jul 08 04:29:24 -0700 2008

    That sounds like a good plan. Clarity is good with error messages.