Sha256: 897ce321b0ef9957b647ee3b7cc6c4c400dfa24b5d120aa50c64c71a208d946a

Contents?: true

Size: 1.25 KB

Versions: 12

Compression:

Stored size: 1.25 KB

Contents

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

require 'hamster/list'

describe Hamster::List do

  [:find, :detect].each do |method|

    describe "##{method}" do

      describe "on a really big list" do

        before do
          @list = Hamster.interval(0, STACK_OVERFLOW_DEPTH)
        end

        it "doesn't run out of stack" do
          lambda { @list.send(method) { false } }.should_not raise_error
        end

      end

      [
        [[], "A", nil],
        [[], nil, nil],
        [["A"], "A", "A"],
        [["A"], "B", nil],
        [["A"], nil, nil],
        [["A", "B", nil], "A", "A"],
        [["A", "B", nil], "B", "B"],
        [["A", "B", nil], nil, nil],
        [["A", "B", nil], "C", nil],
      ].each do |values, item, expected|

        describe "on #{values.inspect}" do

          before do
            @list = Hamster.list(*values)
          end

          describe "with a block" do

            it "returns #{expected.inspect}" do
              @list.send(method) { |x| x == item }.should == expected
            end

          end

          describe "without a block" do

            it "returns nil" do
              @list.send(method).should be_nil
            end

          end

        end

      end

    end

  end

end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
hamster-0.3.6 spec/hamster/list/find_spec.rb
hamster-0.3.5 spec/hamster/list/find_spec.rb
hamster-0.3.4 spec/hamster/list/find_spec.rb
hamster-0.3.3 spec/hamster/list/find_spec.rb
hamster-0.3.2 spec/hamster/list/find_spec.rb
hamster-0.3.1 spec/hamster/list/find_spec.rb
hamster-0.3.0 spec/hamster/list/find_spec.rb
hamster-0.2.13 spec/hamster/list/find_spec.rb
hamster-0.2.12 spec/hamster/list/find_spec.rb
hamster-0.2.11 spec/hamster/list/find_spec.rb
hamster-0.2.9 spec/hamster/list/find_spec.rb
hamster-0.2.8 spec/hamster/list/find_spec.rb