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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
# frozen_string_literal: true
RSpec.describe Morpher::Transform::Block do
subject { described_class.new(name: name, block: block) }
let(:block) { ->(value) { right(value * 2) } }
let(:name) { :external }
describe '#call' do
def apply
subject.call(input)
end
let(:input) { 3 }
context 'when block suceeds' do
it 'returns success' do
expect(apply).to eql(right(6))
end
end
context 'when block fails' do
let(:block) { ->(_value) { left('some error') } }
it 'returns expected error' do
expect(apply).to eql(
left(
Morpher::Transform::Error.new(
cause: nil,
input: input,
message: 'some error',
transform: subject
)
)
)
end
end
end
describe '#slug' do
def apply
subject.slug
end
it 'returns name' do
expect(apply).to be(name)
end
end
describe '.capture' do
def apply
described_class.capture(name, &block)
end
it 'returns expected transform' do
expect(apply).to eql(described_class.new(name: name, block: block))
end
end
end
|