Sha256: a57f71b1c95c7462077a8003a14e7458ccf42222aa8552ee7b05f291df66f008
Contents?: true
Size: 1.88 KB
Versions: 1
Compression:
Stored size: 1.88 KB
Contents
require 'spec_helper' module OrElse describe Just do subject(:just) { Just.new(val) } context 'when wrapping 1' do specify { expect(Just(1)).to be_a Just } end describe '#value' do context 'when initialized with 1' do let(:val) { 1 } specify { expect(just.value).to eq 1 } end context 'when initialized with "foo"' do let(:val) { 'foo' } specify { expect(just.value).to eq 'foo' } end end describe '#map' do context 'when initialized with 1' do let(:val) { 1 } specify { expect { |b| just.map(&b) }.to yield_with_args(val) } it 'yields the value 1 and wraps the block in a Maybe' do expect(just.map { |j| j }.value).to eq val end it 'yields the value 1 and is Nothing when the block evaluates to nil' do expect(just.map { |j| nil }).to eq Nothing end end context 'when initialized with "foo"' do let(:val) { 'foo' } specify { expect { |b| just.map(&b) }.to yield_with_args(val) } it 'yields the value "foo" and wraps the block in a Maybe' do expect(just.map { |j| j }.value).to eq val end end end describe '#flat_map' do context 'when initialized with 1' do let(:val) { 1 } specify { expect { |b| just.flat_map(&b) }.to yield_with_args(val) } end context 'when initialized with "foo"' do let(:val) { 'foo' } specify { expect { |b| just.flat_map(&b) }.to yield_with_args(val) } end end describe '#empty?' do let(:val) { 1 } specify { expect(just.empty?).to be_false } end describe '#exists?' do let(:val) { 1 } specify { expect(just.exists?).to be_true } end describe '#or_else' do let(:val) { 1 } specify { expect(just.or_else).to eq 1 } end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
or_else-0.0.3 | spec/or_else/just_spec.rb |