Sha256: e3835d40a396e79b8967d886d64a2e5eea015794c39a389ad30b0b49a5a35bfa

Contents?: true

Size: 1.26 KB

Versions: 10

Compression:

Stored size: 1.26 KB

Contents

require File.expand_path('../../../spec_helper', __FILE__)

require 'hamster/set'

describe Hamster::Set do

  describe "#one?" do

    describe "when empty" do

      before do
        @set = Hamster.set
      end

      it "with a block returns false" do
        @set.one? {}.should == false
      end

      it "with no block returns false" do
        @set.one?.should == false
      end

    end

    describe "when not empty" do

      describe "with a block" do

        before do
          @set = Hamster.set("A", "B", "C")
        end

        it "returns false if the block returns true more than once" do
          @set.one? { |item| true }.should == false
        end

        it "returns false if the block never returns true" do
          @set.one? { |item| false }.should == false
        end

        it "returns true if the block only returns true once" do
          @set.one? { |item| item == "A" }.should == true
        end

      end

      describe "with no block" do

        it "returns false if more than one value is truthy" do
          Hamster.set(nil, true, "A").one?.should == false
        end

        it "returns true if only one value is truthy" do
          Hamster.set(nil, true, false).one?.should == true
        end

      end

    end

  end

end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
hamster-0.3.6 spec/hamster/set/one_spec.rb
hamster-0.3.5 spec/hamster/set/one_spec.rb
hamster-0.3.4 spec/hamster/set/one_spec.rb
hamster-0.3.3 spec/hamster/set/one_spec.rb
hamster-0.3.2 spec/hamster/set/one_spec.rb
hamster-0.3.1 spec/hamster/set/one_spec.rb
hamster-0.3.0 spec/hamster/set/one_spec.rb
hamster-0.2.13 spec/hamster/set/one_spec.rb
hamster-0.2.12 spec/hamster/set/one_spec.rb
hamster-0.2.11 spec/hamster/set/one_spec.rb