Sha256: e65f0143595478b702aeb5fba76a337a8e10759b72a4e7db479868cf8e285e9d

Contents?: true

Size: 1.48 KB

Versions: 3

Compression:

Stored size: 1.48 KB

Contents

require "spec_helper"
require "hamster/list"

describe Hamster::List do
  describe "#join" do
    context "on a really big list" do
      it "doesn't run out of stack" do
        -> { Hamster.interval(0, STACK_OVERFLOW_DEPTH).join }.should_not raise_error
      end
    end

    context "with a separator" do
      [
        [[], ""],
        [["A"], "A"],
        [%w[A B C], "A|B|C"]
      ].each do |values, expected|
        context "on #{values.inspect}" do
          let(:list) { L[*values] }

          it "preserves the original" do
            list.join("|")
            list.should eql(L[*values])
          end

          it "returns #{expected.inspect}" do
            list.join("|").should == expected
          end
        end
      end
    end

    context "without a separator" do
      [
        [[], ""],
        [["A"], "A"],
        [%w[A B C], "ABC"]
      ].each do |values, expected|
        context "on #{values.inspect}" do
          let(:list) { L[*values] }

          it "preserves the original" do
            list.join
            list.should eql(L[*values])
          end

          it "returns #{expected.inspect}" do
            list.join.should == expected
          end
        end
      end
    end

    context "without a separator (with global default separator set)" do
      before { $, = '**' }
      let(:list) { L["A", "B", "C"] }
      after  { $, = nil }

      it "uses the default global separator" do
        list.join.should == "A**B**C"
      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/join_spec.rb
hamster-3.0.0 spec/lib/hamster/list/join_spec.rb
hamster-2.0.0 spec/lib/hamster/list/join_spec.rb