Module: EvelpidonTestHelpers::ActiveModel::AttributeValidations::Assertions
- Included in:
- ActiveSupport::TestCase
- Defined in:
- lib/evelpidon_test_helpers/active_model/attribute_validations.rb
Instance Method Summary collapse
-
#assert_invalid_attribute(object, attribute, message = "") ⇒ Object
Asserts that the given
attribute
on the givenActiveModel
contains at least one error. -
#assert_valid_attribute(object, attribute, message = "") ⇒ Object
Asserts that the given
attribute
on the givenActiveModel
contains no errors.
Instance Method Details
#assert_invalid_attribute(object, attribute, message = "") ⇒ Object
Asserts that the given attribute
on the given ActiveModel
contains at least one error.
16 17 18 19 20 21 22 |
# File 'lib/evelpidon_test_helpers/active_model/attribute_validations.rb', line 16 def assert_invalid_attribute(object, attribute, = "") object.valid? errors_on_attribute = object.errors[attribute].length = object.errors[attribute].join(',') << "\nExpected at least one error on #{attribute} but got #{errors_on_attribute} :\n#{}" assert errors_on_attribute > 0, end |
#assert_valid_attribute(object, attribute, message = "") ⇒ Object
Asserts that the given attribute
on the given ActiveModel
contains no errors. If not, the error message is the joint string of the errors on this attribute
.
7 8 9 10 11 12 13 |
# File 'lib/evelpidon_test_helpers/active_model/attribute_validations.rb', line 7 def assert_valid_attribute(object, attribute, = "") object.valid? errors_on_attribute = object.errors[attribute].length = object.errors[attribute].join(',') << "\nExpected zero errors on #{attribute} but got #{errors_on_attribute} :\n#{}" assert_equal 0, errors_on_attribute, end |