File: maybe_spec.rb

package info (click to toggle)
ruby-morpher 0.4.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 236 kB
  • sloc: ruby: 1,444; makefile: 4
file content (48 lines) | stat: -rw-r--r-- 1,056 bytes parent folder | download
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
# frozen_string_literal: true

RSpec.describe Morpher::Transform::Maybe do
  subject { described_class.new(transform) }

  let(:transform) { Morpher::Transform::STRING }

  describe '#call' do
    def apply
      subject.call(input)
    end

    context 'on nil input' do
      let(:input) { nil }

      it 'returns sucess' do
        expect(apply).to eql(right(nil))
      end
    end

    context 'on non nil input' do
      context 'on input valid for innner transform' do
        let(:input) { 'some-string' }

        it 'returns sucess' do
          expect(apply).to eql(right('some-string'))
        end
      end

      context 'on input invalud for inner transform' do
        let(:input) { 1 }

        let(:error) do
          Morpher::Transform::Error.new(
            cause:     transform.call(input).from_left,
            input:     input,
            message:   nil,
            transform: subject
          )
        end

        it 'returns failure' do
          expect(apply).to eql(left(error))
        end
      end
    end
  end
end