File: spec_helper.rb

package info (click to toggle)
ruby-mprelude 0.1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 112 kB
  • sloc: ruby: 452; makefile: 4
file content (47 lines) | stat: -rw-r--r-- 1,012 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
# frozen_string_literal: true

require 'mprelude'

RSpec.shared_examples 'no block evaluation' do
  context 'with block' do
    let(:block) { -> { fail } }

    it 'does not evaluate block' do
      apply
    end
  end
end

RSpec.shared_examples 'requires block' do
  context 'without block' do
    let(:block) { nil }

    specify do
      expect { apply }.to raise_error(LocalJumpError)
    end
  end
end

RSpec.shared_examples 'returns self' do
  it 'returns self' do
    expect(apply).to be(subject)
  end
end

RSpec.shared_examples '#bind block evaluation' do
  it 'evaluates block and returns its wrapped result' do
    expect { expect(apply).to eql(block_result) }
      .to change(yields, :to_a)
      .from([])
      .to([value])
  end
end

RSpec.shared_examples 'Functor#fmap block evaluation' do
  it 'evaluates block and returns its wrapped result' do
    expect { expect(apply).to eql(described_class.new(block_result)) }
      .to change(yields, :to_a)
      .from([])
      .to([value])
  end
end