Sha256: 307960b04a5c099e14d52302630cd5905d9131040dfbabc73e928c4ff539ae08

Contents?: true

Size: 1.37 KB

Versions: 3

Compression:

Stored size: 1.37 KB

Contents

require "spec_helper"
require "hamster/list"

describe Hamster::List do
  describe "#all?" do
    context "on a really big list" do
      let(:list) { Hamster.interval(0, STACK_OVERFLOW_DEPTH) }

      it "doesn't run out of stack" do
        -> { list.all? }.should_not raise_error
      end
    end

    context "when empty" do
      it "with a block returns true" do
        L.empty.all? {}.should == true
      end

      it "with no block returns true" do
        L.empty.all?.should == true
      end
    end

    context "when not empty" do
      context "with a block" do
        let(:list) { L["A", "B", "C"] }

        context "if the block always returns true" do
          it "returns true" do
            list.all? { |item| true }.should == true
          end
        end

        context "if the block ever returns false" do
          it "returns false" do
            list.all? { |item| item == "D" }.should == false
          end
        end
      end

      context "with no block" do
        context "if all values are truthy" do
          it "returns true" do
            L[true, "A"].all?.should == true
          end
        end

        [nil, false].each do |value|
          context "if any value is #{value.inspect}" do
            it "returns false" do
              L[value, true, "A"].all?.should == false
            end
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
files.com-1.0.55 docs/vendor/bundle/ruby/2.5.0/gems/hamster-3.0.0/spec/lib/hamster/list/all_spec.rb
hamster-3.0.0 spec/lib/hamster/list/all_spec.rb
hamster-2.0.0 spec/lib/hamster/list/all_spec.rb