Class: RSpec::BeValidWhenMatcher::BeValidWhen Private
- Inherits:
-
Object
- Object
- RSpec::BeValidWhenMatcher::BeValidWhen
- Defined in:
- lib/rspec/be_valid_when_matcher.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Provides the implementation for ‘be_valid_when` matcher. Not intended to be instantiated directly.
Instance Method Summary collapse
-
#description ⇒ String
private
Used to generate the example’s doc string in one-liner syntax.
-
#diffable? ⇒ FalseClass
private
Indicates that this matcher doesn’t provide actual and expected attributes.
-
#does_not_match?(model) ⇒ Boolean
private
Passes if given ‘model` instance is invalid.
-
#failure_message ⇒ String
private
Called when #matches? returns false.
-
#failure_message_when_negated ⇒ String
private
Called when #does_not_match? returns false.
-
#initialize(field) ⇒ BeValidWhen
constructor
private
Returns a new instance of matcher.
- #is(*args) ⇒ Object private
- #is_false ⇒ Object private
-
#is_not_present ⇒ Object
private
rubocop:disable Style/PredicateName.
- #is_true ⇒ Object private
-
#matches?(model) ⇒ Boolean
private
Passes if given ‘model` instance is valid.
-
#supports_block_expectations? ⇒ FalseClass
private
Indicates that this matcher cannot be used in a block expectation expression.
Constructor Details
#initialize(field) ⇒ BeValidWhen
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of matcher.
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/rspec/be_valid_when_matcher.rb', line 16 def initialize(field) unless field.instance_of? Symbol fail ArgumentError, "field name should be symbol (#{field.inspect})" end @field = field @value_set = false @value = nil @model = nil end |
Instance Method Details
#description ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Used to generate the example’s doc string in one-liner syntax.
73 74 75 76 77 |
# File 'lib/rspec/be_valid_when_matcher.rb', line 73 def description assert_value_existence "be valid when #{}" end |
#diffable? ⇒ FalseClass
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Indicates that this matcher doesn’t provide actual and expected attributes.
81 82 83 |
# File 'lib/rspec/be_valid_when_matcher.rb', line 81 def diffable? false end |
#does_not_match?(model) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Passes if given ‘model` instance is invalid.
More specifically if it does have ‘errors` on specified `field` after setting it’s ‘value` and validating it. Does not take into account other fields.
48 49 50 51 |
# File 'lib/rspec/be_valid_when_matcher.rb', line 48 def does_not_match?(model) setup_model model !@model.errors[@field].empty? end |
#failure_message ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Called when #matches? returns false.
55 56 57 58 59 60 |
# File 'lib/rspec/be_valid_when_matcher.rb', line 55 def assert_value_existence assert_model_existance "expected #{@model.inspect} to be valid when #{}" end |
#failure_message_when_negated ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Called when #does_not_match? returns false.
64 65 66 67 68 69 |
# File 'lib/rspec/be_valid_when_matcher.rb', line 64 def assert_value_existence assert_model_existance "expected #{@model.inspect} not to be valid when #{}" end |
#is(*args) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/rspec/be_valid_when_matcher.rb', line 92 def is(*args) number_of_arguments = args.size if number_of_arguments > 2 || number_of_arguments == 0 fail ArgumentError, "wrong number of arguments (#{number_of_arguments} insted of 1 or 2)" else self.value = args.shift @message = args.first end self end |
#is_false ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
138 139 140 |
# File 'lib/rspec/be_valid_when_matcher.rb', line 138 def is_false is(false, 'false') end |
#is_not_present ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
rubocop:disable Style/PredicateName
107 108 109 |
# File 'lib/rspec/be_valid_when_matcher.rb', line 107 def is_not_present is(nil, 'not present') end |
#is_true ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
133 134 135 |
# File 'lib/rspec/be_valid_when_matcher.rb', line 133 def is_true is(true, 'true') end |
#matches?(model) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Passes if given ‘model` instance is valid.
More specifically if it doesn’t have any ‘errors` on specified `field` after setting it’s ‘value` and validating it. Does not take into account other fields and the validity of the whole object.
35 36 37 38 |
# File 'lib/rspec/be_valid_when_matcher.rb', line 35 def matches?(model) setup_model model @model.errors[@field].empty? end |
#supports_block_expectations? ⇒ FalseClass
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Indicates that this matcher cannot be used in a block expectation expression.
87 88 89 |
# File 'lib/rspec/be_valid_when_matcher.rb', line 87 def supports_block_expectations? false end |