Class: Cuprum::RSpec::BeAResultMatcher
- Inherits:
-
Object
- Object
- Cuprum::RSpec::BeAResultMatcher
- Defined in:
- lib/cuprum/rspec/be_a_result_matcher.rb
Overview
Custom matcher that asserts the actual object is a Cuprum result object with the specified properties.
Instance Method Summary collapse
-
#description ⇒ String
A short description of the matcher and expected properties.
-
#does_not_match?(actual) ⇒ Boolean
Checks that the given actual object is not a Cuprum result.
-
#failure_message ⇒ String
A summary message describing a failed expectation.
-
#failure_message_when_negated ⇒ String
A summary message describing a failed negated expectation.
-
#initialize ⇒ BeAResultMatcher
constructor
A new instance of BeAResultMatcher.
-
#matches?(actual) ⇒ Boolean
Checks that the given actual object is a Cuprum result or compatible object and has the specified properties.
-
#with_error(error) ⇒ BeAResultMatcher
(also: #and_error)
Sets an error expectation on the matcher.
-
#with_status(status) ⇒ BeAResultMatcher
(also: #and_status)
Sets a status expectation on the matcher.
-
#with_value(value) ⇒ BeAResultMatcher
(also: #and_value)
Sets a value expectation on the matcher.
Constructor Details
#initialize ⇒ BeAResultMatcher
Returns a new instance of BeAResultMatcher.
16 17 18 19 |
# File 'lib/cuprum/rspec/be_a_result_matcher.rb', line 16 def initialize @expected_error = DEFAULT_VALUE @expected_value = DEFAULT_VALUE end |
Instance Method Details
#description ⇒ String
Returns a short description of the matcher and expected properties.
23 24 25 26 27 28 29 |
# File 'lib/cuprum/rspec/be_a_result_matcher.rb', line 23 def description = 'be a Cuprum result' return unless expected_properties? "#{} #{properties_description}" end |
#does_not_match?(actual) ⇒ Boolean
Checks that the given actual object is not a Cuprum result.
36 37 38 39 40 41 42 |
# File 'lib/cuprum/rspec/be_a_result_matcher.rb', line 36 def does_not_match?(actual) @actual = actual raise ArgumentError, negated_matcher_warning if expected_properties? !actual_is_result? end |
#failure_message ⇒ String
Returns a summary message describing a failed expectation.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/cuprum/rspec/be_a_result_matcher.rb', line 45 def = "expected #{actual.inspect} to #{description}" if !actual_is_result? + ', but the object is not a result' elsif actual_is_uncalled_operation? + ', but the object is an uncalled operation' elsif !properties_match? + else # :nocov: # :nocov: end end |
#failure_message_when_negated ⇒ String
Returns a summary message describing a failed negated expectation.
63 64 65 |
# File 'lib/cuprum/rspec/be_a_result_matcher.rb', line 63 def "expected #{actual.inspect} not to #{description}" end |
#matches?(actual) ⇒ Boolean
Checks that the given actual object is a Cuprum result or compatible object and has the specified properties.
74 75 76 77 78 |
# File 'lib/cuprum/rspec/be_a_result_matcher.rb', line 74 def matches?(actual) @actual = actual actual_is_result? && !actual_is_uncalled_operation? && properties_match? end |
#with_error(error) ⇒ BeAResultMatcher Also known as: and_error
Sets an error expectation on the matcher. Calls to #matches? will fail unless the actual object has the specified error.
86 87 88 89 90 |
# File 'lib/cuprum/rspec/be_a_result_matcher.rb', line 86 def with_error(error) @expected_error = error self end |
#with_status(status) ⇒ BeAResultMatcher Also known as: and_status
Sets a status expectation on the matcher. Calls to #matches? will fail unless the actual object has the specified status.
99 100 101 102 103 |
# File 'lib/cuprum/rspec/be_a_result_matcher.rb', line 99 def with_status(status) @expected_status = status self end |
#with_value(value) ⇒ BeAResultMatcher Also known as: and_value
Sets a value expectation on the matcher. Calls to #matches? will fail unless the actual object has the specified value.
112 113 114 115 116 |
# File 'lib/cuprum/rspec/be_a_result_matcher.rb', line 112 def with_value(value) @expected_value = value self end |