File: immutable_spec.rb

package info (click to toggle)
ruby-hamster 3.0.0-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,932 kB
  • sloc: ruby: 16,915; makefile: 4
file content (45 lines) | stat: -rw-r--r-- 945 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
require "spec_helper"
require "hamster/immutable"

describe Hamster::Immutable do
  describe "#immutable?" do
    describe "object constructed after its class becomes Immutable" do
      class Fixture
        include Hamster::Immutable
      end

      before do
        @fixture = Fixture.new
      end

      it "returns true" do
        @fixture.should be_immutable
      end
    end

    describe "object constructed before its class becomes Immutable" do
      before do
        @fixture = Class.new.new
        @fixture.class.instance_eval do
          include Hamster::Immutable
        end
      end

      describe "that are not frozen" do
        it "returns false" do
          @fixture.should_not be_immutable
        end
      end

      describe "that are frozen" do
        before do
          @fixture.freeze
        end

        it "returns true" do
          @fixture.should be_immutable
        end
      end
    end
  end
end