Sha256: f255099ad3af88df811f682dcc9a9bf3ca1ac0f0199e9b30173525bba74f2865

Contents?: true

Size: 1.12 KB

Versions: 7

Compression:

Stored size: 1.12 KB

Contents

require "spec_helper"
require "hamster/immutable"

describe Hamster::Immutable do
  class TransformUnlessPerson < Struct.new(:first, :last)
    include Hamster::Immutable

    public :transform_unless
  end

  let(:immutable) { TransformUnlessPerson.new("Simon", "Harris") }

  describe "#transform_unless" do
    let(:transform_unless) { immutable.transform_unless(condition, &block) }
    let(:original) { immutable.first }
    let(:modified) { transform_unless.first }

    context "when the condition is false" do
      let(:condition) { false }
      let(:block) { ->(thing) { self.first = "Sampy" } }

      it "preserves the original" do
        expect(original).to eq("Simon")
      end

      it "returns a new instance with the updated values" do
        expect(modified).to eq("Sampy")
      end
    end

    context "when the condition is true" do
      let(:condition) { true }
      let(:block) { -> { fail("Should never be called") } }

      it "preserves the original" do
        expect(original).to eq("Simon")
      end

      it "returns the original" do
        expect(original).to eq(modified)
      end
    end
  end
end

Version data entries

7 entries across 7 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/immutable/transform_unless_spec.rb
hamster-3.0.0 spec/lib/hamster/immutable/transform_unless_spec.rb
hamster-2.0.0 spec/lib/hamster/immutable/transform_unless_spec.rb
hamster-1.0.0 spec/lib/hamster/immutable/transform_unless_spec.rb
hamster-1.0.1.pre.rc3 spec/lib/hamster/immutable/transform_unless_spec.rb
hamster-1.0.1.pre.rc2 spec/hamster/immutable/transform_unless_spec.rb
hamster-1.0.1.pre.rc.1 spec/hamster/immutable/transform_unless_spec.rb