1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
# frozen_string_literal: true
RSpec.describe Morpher::Transform::Exception do
subject { described_class.new(error_class, block) }
let(:error_class) do
Class.new(RuntimeError)
end
describe '#call' do
def apply
subject.call(input)
end
let(:input) { 2 }
context 'block that does not raise' do
let(:block) { ->(input) { input * input } }
it 'returns expected success value' do
expect(apply).to eql(right(4))
end
end
context 'on block that raises' do
context 'a covered exception' do
let(:block) { ->(_input) { fail(error_class, 'some message') } }
let(:error) do
Morpher::Transform::Error.new(
cause: nil,
input: input,
message: 'some message',
transform: subject
)
end
it 'returns expected error' do
expect(apply).to eql(left(error))
end
end
end
end
end
|