Closed jmuheim closed 9 years ago
+1 for this feature :)
+1 (please, pretty please)
Here is a naive RSpec matcher which simply checks whether the validator is present for the respective attribute. It does not check the options or whether there is an if
or unless
conditional applied to the validation.
RSpec::Matchers.define :validate_timeliness_of do |attribute|
match do |model|
model._validators[attribute.to_sym].detect do |validator|
validator.class == ActiveModel::Validations::TimelinessValidator &&
validator.attributes.include?(attribute)
end
end
failure_message_for_should do |actual|
"expect #{attribute} to validate timeliness of"
end
failure_message_for_should_not do |actual|
"expect #{attribute} to not validate timeliness of"
end
end
I did have such a matcher in earlier versions but I didn't find there is much value in such a matcher. But please create your own gem (e.g validates_timeliness-rpec) to explore it.
Is there something like this yet?