Class: PencilPusher::HaveErrors
- Inherits:
-
Object
- Object
- PencilPusher::HaveErrors
- Defined in:
- lib/pencil_pusher/have_errors.rb
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message_for_should ⇒ Object (also: #failure_message)
- #failure_message_for_should_not ⇒ Object (also: #failure_message_when_negated)
-
#initialize(field_name, expected_errors = []) ⇒ HaveErrors
constructor
A new instance of HaveErrors.
- #matches?(form) ⇒ Boolean
Constructor Details
#initialize(field_name, expected_errors = []) ⇒ HaveErrors
Returns a new instance of HaveErrors.
3 4 5 6 |
# File 'lib/pencil_pusher/have_errors.rb', line 3 def initialize(field_name, expected_errors=[]) @field_name = field_name @expected_errors = expected_errors end |
Instance Method Details
#description ⇒ Object
33 34 35 |
# File 'lib/pencil_pusher/have_errors.rb', line 33 def description "have errors for #{field_name}" end |
#failure_message_for_should ⇒ Object Also known as: failure_message
18 19 20 21 22 23 24 |
# File 'lib/pencil_pusher/have_errors.rb', line 18 def if errors = actual.[field_name].presence "expected field #{field_name} to have errors #{expected_errors} but had errors #{errors}" else "expected field #{field_name} to have errors #{expected_errors} but had no errors" end end |
#failure_message_for_should_not ⇒ Object Also known as: failure_message_when_negated
26 27 28 |
# File 'lib/pencil_pusher/have_errors.rb', line 26 def "expected no errors for field #{field_name} but found #{actual.error_messages[field_name]}" end |
#matches?(form) ⇒ Boolean
8 9 10 11 12 13 14 15 16 |
# File 'lib/pencil_pusher/have_errors.rb', line 8 def matches?(form) @actual = form valid = form.valid? if expected_errors.present? form.[field_name] == expected_errors else form.[field_name].present? end end |