Sha256: 094aebf9e697b13ca7f14d28866d445ce0731a6c38fabe134651993fcf74c6bb

Contents?: true

Size: 1.05 KB

Versions: 1

Compression:

Stored size: 1.05 KB

Contents

RSpec.describe Fear::Some do
  include Fear::Option::Mixin

  it_behaves_like Fear::RightBiased::Right do
    let(:right) { described_class.new('value') }
  end

  subject(:some) { Some(value) }
  let(:value) { 42 }

  describe '#detect' do
    subject { some.detect(&predicate) }

    context 'predicate evaluates to true' do
      let(:predicate) { ->(v) { v > 40 } }
      it { is_expected.to eq(some) }
    end

    context 'predicate evaluates to false' do
      let(:predicate) { ->(v) { v < 40 } }
      it { is_expected.to eq(None()) }
    end
  end

  describe '#reject' do
    subject { some.reject(&predicate) }

    context 'predicate evaluates to true' do
      let(:predicate) { ->(v) { v > 40 } }
      it { is_expected.to eq(None()) }
    end

    context 'predicate evaluates to false' do
      let(:predicate) { ->(v) { v < 40 } }
      it { is_expected.to eq(some) }
    end
  end

  specify '#get returns value' do
    expect(some.get).to eq value
  end

  specify '#or_nil returns value' do
    result = some.or_nil

    expect(result).to eq value
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fear-0.0.1 spec/fear/some_spec.rb