Sha256: c700d38ca3b3a234b2c1137d8c70a40be752cb128ecbcc5128d3441506f71cc6

Contents?: true

Size: 1.16 KB

Versions: 7

Compression:

Stored size: 1.16 KB

Contents

require File.expand_path('../../../spec_helper', __FILE__)

require 'hamster/immutable'

describe Hamster::Immutable do

  describe "#transform_unless" do

    class Person < Struct.new(:first, :last)
      include Hamster::Immutable
      public :transform_unless
    end

    before do
      @original = Person.new("Simon", "Harris")
    end

    describe "when the condition is false" do

      before do
        @result = @original.transform_unless(false) { self.first = "Sampy" }
      end

      it "preserves the original" do
        @original.first.should == "Simon"
        @original.last.should == "Harris"
      end

      it "returns a new instance with the updated values" do
        @result.first.should == "Sampy"
        @result.last.should == "Harris"
      end

    end

    describe "when the condition is true" do

      before do
        @result = @original.transform_unless(true) { fail("Should never be called") }
      end

      it "preserves the original" do
        @original.first.should == "Simon"
        @original.last.should == "Harris"
      end

      it "returns the original" do
        @result.should equal(@original)
      end

    end

  end

end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
hamster-0.3.6 spec/hamster/immutable/transform_unless_spec.rb
hamster-0.3.5 spec/hamster/immutable/transform_unless_spec.rb
hamster-0.3.4 spec/hamster/immutable/transform_unless_spec.rb
hamster-0.3.3 spec/hamster/immutable/transform_unless_spec.rb
hamster-0.3.2 spec/hamster/immutable/transform_unless_spec.rb
hamster-0.3.1 spec/hamster/immutable/transform_unless_spec.rb
hamster-0.3.0 spec/hamster/immutable/transform_unless_spec.rb