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 60 61
|
# frozen_string_literal: true
RSpec.describe Morpher::Transform::Boolean do
subject { described_class.new }
describe '#call' do
def apply
subject.call(input)
end
context 'on true' do
let(:input) { true }
it 'returns sucess' do
expect(apply).to eql(right(input))
end
end
context 'on false' do
let(:input) { false }
it 'returns sucess' do
expect(apply).to eql(right(input))
end
end
context 'on nil input' do
let(:input) { nil }
let(:error) do
Morpher::Transform::Error.new(
cause: nil,
input: input,
message: 'Expected: boolean but got: nil',
transform: subject
)
end
it 'returns failure' do
expect(apply).to eql(left(error))
end
end
context 'on truthy input' do
let(:input) { '' }
let(:error) do
Morpher::Transform::Error.new(
cause: nil,
input: input,
message: 'Expected: boolean but got: ""',
transform: subject
)
end
it 'returns failure' do
expect(apply).to eql(left(error))
end
end
end
end
|