Reputation: 455
In my class Foo, I have:
belongs_to :assessment_type
validate :assessment_type, presence: true
My RSpec test has:
it { is_expected.to validate_presence_of(:assessment_type) }
The test fails with this error:
1) Foo should require assessment_type to be set
Failure/Error: it { is_expected.to validate_presence_of(:assessment_type) }
Expected errors to include "can't be blank" when assessment_type is set to nil, got errors: ["can't be blank (attribute: \"name\", value: nil)", "can't be blank (attribute: \"description\", value: nil)", "can't be blank (attribute: \"logo\", value: nil)", "can't be blank (attribute: \"url_code\", value: nil)", "can't be blank (attribute: \"starts_at\", value: nil)", "can't be blank (attribute: \"contract\", value: nil)", "can't be blank (attribute: \"organization\", value: nil)"]
All of the attributes listed in the errors string (name, description, ...) have the same validate
statement as assessment_type.
Why is this failing?
Upvotes: 0
Views: 119
Reputation: 455
I found the problem. This line:
validate :assessment_type, presence: true
should be
validates :assessment_type, presence: true
Upvotes: 1