Sha256: c2c65bf27235d4677a75a7a4e6256d4406262aacb8bcb8b1750f4b206e481c60

Contents?: true

Size: 1.23 KB

Versions: 3

Compression:

Stored size: 1.23 KB

Contents

require "spec_helper"
require "hamster/set"

describe Hamster::Set do
  describe "#none?" do
    context "when empty" do
      it "with a block returns true" do
        S.empty.none? {}.should == true
      end

      it "with no block returns true" do
        S.empty.none?.should == true
      end
    end

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

        ["A", "B", "C", nil].each do |value|
          it "returns false if the block ever returns true (#{value.inspect})" do
            set.none? { |item| item == value }.should == false
          end
        end

        it "returns true if the block always returns false" do
          set.none? { |item| item == "D" }.should == true
        end

        it "stops iterating as soon as the block returns true" do
          yielded = []
          set.none? { |item| yielded << item; true }
          yielded.size.should == 1
        end
      end

      context "with no block" do
        it "returns false if any value is truthy" do
          S[nil, false, true, "A"].none?.should == false
        end

        it "returns true if all values are falsey" do
          S[nil, false].none?.should == true
        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/set/none_spec.rb
hamster-3.0.0 spec/lib/hamster/set/none_spec.rb
hamster-2.0.0 spec/lib/hamster/set/none_spec.rb