An opinionated implementation of the Command pattern for Ruby applications. Cuprum wraps your business logic in a consistent, object-oriented interface and features status and error management, composability and control flow management.
Asserts the actual object is a result object with the specified properties.
If initialized with a class, the matcher will assert that the actual object is an instance of that class. This can be useful for asserting that the result is an instance of a result subclass. If no class is given, the matcher asserts that the result is an object responding to #to_cuprum_result.
The matcher also defines fluent methods for asserting on the result’s properties:
Generally speaking, you should use the #be_a_result, #be_a_passing_result, and #be_a_failing_result macros, rather than instantiating a BeAResultMatcher directly.
Matching Any Result
# Or use expect().to be_a_result
matcher = Cuprum::RSpec::BeAResultMatcher.new
matcher.matches?(nil) #=> false
matcher.matches?(Cuprum::Result.new) #=> trueMatching A Result Status
# Or use expect().to be_a_passing_result
matcher = Cuprum::RSpec::BeAResultMatcher.new.with_status(:success)
matcher.matches?(Cuprum::Result.new(status: :failure)) #=> false
matcher.matches?(Cuprum::Result.new(status: :success)) #=> falseMatching A Result Value
matcher = Cuprum::RSpec::BeAResultMatcher.new.with_value({ ok: true })
matcher.matches?(Cuprum::Result.new(value: { ok: false })) #=> false
matcher.matches?(Cuprum::Result.new(value: { ok: true })) #=> trueMatching A Result Error
error = Cuprum::Error.new(message: 'Something went wrong')
matcher = Cuprum::RSpec::BeAResultMatcher.new.with_error(error)
other_error = Cuprum::Error.new(message: 'Oh no')
matcher.matches?(Cuprum::Result.new(error: other_error) #=> false
matcher.matches?(Cuprum::Result.new(error: error) #=> trueMatching A Result Class
matcher = Cuprum::RSpec::BeAResultMatcher.new(CustomResult)
matcher.matches?(Cuprum::Result.new) #=> false
matcher.matches?(CustomResult.new) #=> trueMatching Multiple Properties
matcher =
Cuprum::RSpec::BeAResultMatcher
.with_status(:failure)
.and_value({ ok: false })
.and_error(Cuprum::Error.new(message: 'Something went wrong'))#initialize(expected_class = nil) => BeAResultMatcher
#expected_class => Class (readonly)
#description => String
#does_not_match?(actual) => Boolean
Checks that the given actual object is not a Cuprum result.
#failure_message => String
#failure_message_when_negated => String
#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 known as:
and_error
Sets an error expectation on the matcher. Calls to #matches? will fail unless the actual object has the specified error.
#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.
#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.
Back to Documentation | Reference | Cuprum | Cuprum::RSpec