Sha256: 58eaa815469e7c6bec97e62dd9ec76cf82fc6204975bd4b1b99be210add7d9ab

Contents?: true

Size: 1.21 KB

Versions: 4

Compression:

Stored size: 1.21 KB

Contents

# frozen_string_literal: true

RSpec.describe Mutant::Maybe::Nothing do
  subject { described_class.new }

  let(:block) { -> {} }

  describe '#fmap' do
    def apply
      subject.fmap(&block)
    end

    include_examples 'no block evaluation'
    include_examples 'requires block'
    include_examples 'returns self'
  end

  describe '#apply' do
    def apply
      subject.apply(&block)
    end

    include_examples 'no block evaluation'
    include_examples 'requires block'
    include_examples 'returns self'
  end
end

RSpec.describe Mutant::Maybe::Just do
  subject { described_class.new(value) }

  let(:block_result) { instance_double(Object, 'block result') }
  let(:value)        { instance_double(Object, 'value')        }
  let(:yields)       { []                                      }

  let(:block) do
    lambda do |value|
      yields << value
      block_result
    end
  end

  describe '#fmap' do
    def apply
      subject.fmap(&block)
    end

    include_examples 'requires block'
    include_examples 'Functor#fmap block evaluation'
  end

  describe '#apply' do
    def apply
      subject.apply(&block)
    end

    include_examples 'requires block'
    include_examples '#apply block evaluation'
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
mutant-0.9.3 spec/unit/mutant/maybe_spec.rb
mutant-0.9.2 spec/unit/mutant/maybe_spec.rb
mutant-0.9.1 spec/unit/mutant/maybe_spec.rb
mutant-0.9.0 spec/unit/mutant/maybe_spec.rb