Class: ElabsMatchers::Matchers::BeValidWith::BeValidWithMatcher
- Inherits:
-
Object
- Object
- ElabsMatchers::Matchers::BeValidWith::BeValidWithMatcher
- Defined in:
- lib/elabs_matchers/matchers/be_valid_with.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#record ⇒ Object
readonly
Returns the value of attribute record.
Instance Method Summary collapse
-
#as(*attributes) ⇒ Object
Tell the matcher which attributes to check.
- #description ⇒ Object
- #does_not_match?(record) ⇒ Boolean
- #failure_message ⇒ Object (also: #failure_message_for_should)
- #failure_message_when_negated ⇒ Object (also: #failure_message_for_should_not)
-
#initialize(values) ⇒ BeValidWithMatcher
constructor
A new instance of BeValidWithMatcher.
- #matches?(record) ⇒ Boolean
Constructor Details
#initialize(values) ⇒ BeValidWithMatcher
Returns a new instance of BeValidWithMatcher
10 11 12 |
# File 'lib/elabs_matchers/matchers/be_valid_with.rb', line 10 def initialize(values) @values = values end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes
8 9 10 |
# File 'lib/elabs_matchers/matchers/be_valid_with.rb', line 8 def attributes @attributes end |
#record ⇒ Object (readonly)
Returns the value of attribute record
8 9 10 |
# File 'lib/elabs_matchers/matchers/be_valid_with.rb', line 8 def record @record end |
Instance Method Details
#as(*attributes) ⇒ Object
Tell the matcher which attributes to check
Example: post.should be_valid_with(“Elabs”).as(:title)
33 34 35 36 |
# File 'lib/elabs_matchers/matchers/be_valid_with.rb', line 33 def as(*attributes) @attributes = [*attributes] self end |
#description ⇒ Object
48 49 50 |
# File 'lib/elabs_matchers/matchers/be_valid_with.rb', line 48 def description "be valid with #{@values.inspect} as #{@attributes.inspect}" end |
#does_not_match?(record) ⇒ Boolean
19 20 21 22 |
# File 'lib/elabs_matchers/matchers/be_valid_with.rb', line 19 def does_not_match?(record) @record = record errors.all? and correct_number_of_errors? end |
#failure_message ⇒ Object Also known as: failure_message_for_should
38 39 40 |
# File 'lib/elabs_matchers/matchers/be_valid_with.rb', line 38 def (:valid) end |
#failure_message_when_negated ⇒ Object Also known as: failure_message_for_should_not
43 44 45 |
# File 'lib/elabs_matchers/matchers/be_valid_with.rb', line 43 def (:invalid) end |
#matches?(record) ⇒ Boolean
14 15 16 17 |
# File 'lib/elabs_matchers/matchers/be_valid_with.rb', line 14 def matches?(record) @record = record errors.none? end |