Sha256: 1553125969c902f3b0143fc6b5a0a56696b30275f699bc356840df9fc3ddf7a3

Contents?: true

Size: 1.12 KB

Versions: 4

Compression:

Stored size: 1.12 KB

Contents

require 'spec_helper'

describe None do

  let (:cat) { Cat.new("MOGGIE!") }

  subject { None }

  it { should be_none }
  it { should_not be_some }
  it { should_not be_some Cat }

  it { should eq None }
  it { should_not eq Some[cat] }

  it "does not have a value" do
    expect { subject.value }.to raise_error Option::ValueOfNoneError
  end

  it "does, however, allow you to supply a default in place of a value" do
    subject.value_or { cat }.should eq cat
    subject.value_or(cat).should eq cat
  end

  it "can be anded with another none, yielding none" do
    (None & None).should be_none
  end

  it "can be anded with a some, yielding none" do
    (None & Some[cat]).should be_none
  end

  it "can be ored with another none, yielding none" do
    (None | None).should be_none
  end

  it "can be ored with a some, yielding the some" do
    (None | Some[cat]).should eq Some[cat]
  end

  it "prints as None" do
    None.to_s.should eq "None"
  end

  it "can be merged with another none" do
    None.merge(None).should be_none
  end

  it "can be merged with a some" do
    None.merge(Some[cat]).should eq Some[cat]
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
optional-0.0.7 spec/lib/optional/none_spec.rb
optional-0.0.6 spec/lib/optional/none_spec.rb
optional-0.0.5 spec/lib/optional/none_spec.rb
optional-0.0.4 spec/lib/optional/none_spec.rb