File: index_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 (92 lines) | stat: -rw-r--r-- 1,916 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# frozen_string_literal: true

RSpec.describe Morpher::Transform::Index do
  subject { described_class.new(index: index, transform: transform) }

  let(:index)     { 1                              }
  let(:transform) { Morpher::Transform::Boolean.new }

  describe '#slug' do
    def apply
      subject.slug
    end

    it 'retursn expected value' do
      expect(apply).to eql('1')
    end

    it 'returns frozen value' do
      expect(apply.frozen?).to be(true)
    end

    it 'returns idempotent value' do
      expect(apply).to be(apply)
    end
  end

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

    context 'on valid input' do
      let(:input) { true }

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

    context 'on nvalid input' do
      let(:input) { 1 }

      let(:boolean_error) do
        Morpher::Transform::Error.new(
          cause:     nil,
          input:     input,
          message:   'Expected: boolean but got: 1',
          transform: transform
        )
      end

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

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

  describe '.wrap' do
    def apply
      described_class.wrap(error, index)
    end

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

    it 'returns wrapped error' do
      expect(apply).to eql(
        Morpher::Transform::Error.new(
          cause:     error,
          input:     1,
          message:   nil,
          transform: described_class.new(index: index, transform: transform)
        )
      )
    end
  end
end