Sha256: cb2f1058f1b499b56a1a8e97487a9aa4624685eab5497334db1a2257411627c4

Contents?: true

Size: 1.23 KB

Versions: 3

Compression:

Stored size: 1.23 KB

Contents

require "spec_helper"
require "hamster/list"

describe Hamster::List do
  [
    [:sort, ->(left, right) { left.length <=> right.length }],
    [:sort_by, ->(item) { item.length }],
  ].each do |method, comparator|
    describe "##{method}" do
      it "is lazy" do
        -> { Hamster.stream { fail }.send(method, &comparator) }.should_not raise_error
      end

      [
        [[], []],
        [["A"], ["A"]],
        [%w[Ichi Ni San], %w[Ni San Ichi]],
      ].each do |values, expected|
        context "on #{values.inspect}" do
          let(:list) { L[*values] }

          context "with a block" do
            it "preserves the original" do
              list.send(method, &comparator)
              list.should == L[*values]
            end

            it "returns #{expected.inspect}" do
              list.send(method, &comparator).should == L[*expected]
            end
          end

          context "without a block" do
            it "preserves the original" do
              list.send(method)
              list.should eql(L[*values])
            end

            it "returns #{expected.sort.inspect}" do
              list.send(method).should == L[*expected.sort]
            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/sorting_spec.rb
hamster-3.0.0 spec/lib/hamster/list/sorting_spec.rb
hamster-2.0.0 spec/lib/hamster/list/sorting_spec.rb