Skip to content

Instantly share code, notes, and snippets.

@mrbongiolo
Created August 24, 2020 21:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrbongiolo/44a5dc798e55503c5791c563b7490b4e to your computer and use it in GitHub Desktop.
Save mrbongiolo/44a5dc798e55503c5791c563b7490b4e to your computer and use it in GitHub Desktop.
Micro::Case::Result rspec matchers

Usage

https://github.com/serradura/u-case

it 'is a proper result' do
  result = MyCase.(input)
  expect(result).to be_a_result
end

it 'something is wrong' do
  result = MyCase.(bad_input)
  expect(result).to be_a_failed_result
end

it 'something is right' do
  result = MyCase.(input)
  expect(result.to be_a_successful_result
end
# frozen_string_literal: true
RSpec::Matchers.define :be_a_result do
match do |actual|
actual.is_a?(Micro::Case::Result)
end
failure_message do |actual|
"expected that #{actual} would be a Micro::Case::Result"
end
failure_message_when_negated do |actual|
"expected that #{actual} would not be a Micro::Case::Result"
end
description do
'be a Micro::Case::Result'
end
end
RSpec::Matchers.define :be_a_successful_result do
match do |actual|
actual.is_a?(Micro::Case::Result) && actual.success?
end
failure_message do |actual|
"expected that #{actual} would be a successful Micro::Case::Result"
end
failure_message_when_negated do |actual|
"expected that #{actual} would not be a successful Micro::Case::Result"
end
description do
'be a successful Micro::Case::Result'
end
end
RSpec::Matchers.define :be_a_failed_result do
match do |actual|
actual.is_a?(Micro::Case::Result) && actual.failure?
end
failure_message do |actual|
"expected that #{actual} would be a failed Micro::Case::Result"
end
failure_message_when_negated do |actual|
"expected that #{actual} would not be a failed Micro::Case::Result"
end
description do
'be a failed Micro::Case::Result'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment