views:

28

answers:

1

Summary: Failed unit tests tell me which assert (file:line) failed, but not which validation resulted in the failure.

More info: I have 11 validations in one of my models. Unit testing is great, whether I run `rake test:units --trace' or 'ruby -Itest test/unit/mymodel_test.rb'. However, despite the fact that it tells me exactly which assert() failed me, I am not told which validation failed. I must be missing something obvious, because I can't ask Google this question well enough to get an answer.

Thanks :)

+1  A: 

You could always take a look at the object errors for the invalid attribute.

class Person
   validates_presence_of :name
end

person = Person.new
person.valid?  # => false

person.errors[:name]  # =>  "can't be blank"
person.errors.full_messages  # => ["Name can't be blank"]

Take a look at the ActiveRecord::Errors docs for more info.

Oshuma
Thanks, Oshuma. While this isn't exactly what I need, it did lead me to experimenting with the debugger for unit tests.
JD