Sha256: 3101260995dfdef57b0e2e959b0fabc9bd34ec89573b784c26cf568069e003da

Contents?: true

Size: 1.02 KB

Versions: 1

Compression:

Stored size: 1.02 KB

Contents

describe ObjectThru do
  it "adds #thru to Object" do
    expect(Object.new).to respond_to(:thru)
  end

  describe "#thru" do
    context "if a block is given" do
      it "yields the object to the block" do
        array = [1,2,3]

        array.thru do |_array|
          expect(array.object_id).to eq(_array.object_id)
        end
      end

      it "returns the result of the block" do
        array = [1,2,3]

        result = array.thru do |_array|
          array.first
        end

        expect(result).to eq(array.first)
      end
    end

    context "if a callable is given" do
      it "calls the callable with the object" do
        callable = -> (object) { object }

        some_object = Object.new
        expect(some_object.thru(callable).object_id).to eq(some_object.object_id)
      end

      it "it returns the result of the callable" do
        callable = -> (integer) { integer + 1 }

        some_number = 1
        expect(some_number.thru(callable)).to eq(callable.call(some_number))
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
object_thru-0.0.1 spec/object_thru_spec.rb