Sha256: bd2aff81dc6520a3be42f336c3f0125f93caf641055b995e1c09cfa2fff8331a

Contents?: true

Size: 1.49 KB

Versions: 6

Compression:

Stored size: 1.49 KB

Contents

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')

require 'hamster/list'

describe Hamster::List do

  [
    [:sort, lambda { |left, right| left.length <=> right.length }],
    [:sort_by, lambda { |item| item.length }],
  ].each do |method, comparator|

    describe "##{method}" do

      it "is lazy" do
        lambda { Hamster.stream { fail }.send(method, &comparator) }.should_not raise_error
      end

      [
        [[], []],
        [["A"], ["A"]],
        [["Ichi", "Ni", "San"], ["Ni", "San", "Ichi"]],
      ].each do |values, expected|

        describe "on #{values.inspect}" do

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

          describe "with a block" do

            before do
              @result = @original.send(method, &comparator)
            end

            it "preserves the original" do
              @original.should == Hamster.list(*values)
            end

            it "returns #{expected.inspect}" do
              @result.should == Hamster.list(*expected)
            end

          end

          describe "without a block" do

            before do
              @result = @original.send(method)
            end

            it "preserves the original" do
              @original.should == Hamster.list(*values)
            end

            it "returns #{expected.sort.inspect}" do
              @result.should == Hamster.list(*expected.sort)
            end

          end

        end

      end

    end

  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
hamster-0.2.5 spec/hamster/list/sorting_spec.rb
hamster-0.2.4 spec/hamster/list/sorting_spec.rb
hamster-0.2.3 spec/hamster/list/sorting_spec.rb
hamster-0.2.2 spec/hamster/list/sorting_spec.rb
hamster-0.2.1 spec/hamster/list/sorting_spec.rb
hamster-0.2.0 spec/hamster/list/sorting_spec.rb