Class: RiotRails::ActiveRecord::IsInvalidWhenMacro
- Inherits:
-
AssertionMacro
- Object
- Riot::AssertionMacro
- AssertionMacro
- RiotRails::ActiveRecord::IsInvalidWhenMacro
- Defined in:
- lib/riot/active_record/assertion_macros.rb
Overview
An ActiveRecord assertion that expects to fail with invalid value for an attribute. Optionally, the error message can be provided as the exact string or as regular expression.
context "a User" do
setup { User.new }
topic.is_invalid_when :email, "fake", "is invalid"
topic.is_invalid_when :email, "another fake", /invalid/
end
Instance Method Summary collapse
Methods inherited from AssertionMacro
Instance Method Details
#evaluate(actual, attribute, value, expected_error = nil) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/riot/active_record/assertion_macros.rb', line 83 def evaluate(actual, attribute, value, expected_error=nil) actual_errors = Array(error_from_writing_value(actual, attribute, value)) if actual_errors.empty? fail("expected #{attribute.inspect} to be invalid when value is #{value.inspect}") elsif expected_error && !(expected_error, actual_errors) = "expected %s to be invalid with error message %s" fail( % [attribute.inspect, expected_error.inspect]) else pass("attribute #{attribute.inspect} is invalid") end end |