diff options
Diffstat (limited to 'spec/ruby/core/kernel/freeze_spec.rb')
| -rw-r--r-- | spec/ruby/core/kernel/freeze_spec.rb | 56 |
1 files changed, 31 insertions, 25 deletions
diff --git a/spec/ruby/core/kernel/freeze_spec.rb b/spec/ruby/core/kernel/freeze_spec.rb index 018784a4f5..079617dce4 100644 --- a/spec/ruby/core/kernel/freeze_spec.rb +++ b/spec/ruby/core/kernel/freeze_spec.rb @@ -4,46 +4,46 @@ require_relative 'fixtures/classes' describe "Kernel#freeze" do it "prevents self from being further modified" do o = mock('o') - o.frozen?.should be_false + o.frozen?.should == false o.freeze - o.frozen?.should be_true + o.frozen?.should == true end it "returns self" do o = Object.new - o.freeze.should equal(o) + o.freeze.should.equal?(o) end describe "on integers" do it "has no effect since they are already frozen" do - 1.frozen?.should be_true + 1.frozen?.should == true 1.freeze bignum = bignum_value - bignum.frozen?.should be_true + bignum.frozen?.should == true bignum.freeze end end describe "on a Float" do it "has no effect since it is already frozen" do - 1.2.frozen?.should be_true + 1.2.frozen?.should == true 1.2.freeze end end describe "on a Symbol" do it "has no effect since it is already frozen" do - :sym.frozen?.should be_true + :sym.frozen?.should == true :sym.freeze end end describe "on true, false and nil" do it "has no effect since they are already frozen" do - nil.frozen?.should be_true - true.frozen?.should be_true - false.frozen?.should be_true + nil.frozen?.should == true + true.frozen?.should == true + false.frozen?.should == true nil.freeze true.freeze @@ -51,21 +51,19 @@ describe "Kernel#freeze" do end end - ruby_version_is "2.5" do - describe "on a Complex" do - it "has no effect since it is already frozen" do - c = Complex(1.3, 3.1) - c.frozen?.should be_true - c.freeze - end + describe "on a Complex" do + it "has no effect since it is already frozen" do + c = Complex(1.3, 3.1) + c.frozen?.should == true + c.freeze end + end - describe "on a Rational" do - it "has no effect since it is already frozen" do - r = Rational(1, 3) - r.frozen?.should be_true - r.freeze - end + describe "on a Rational" do + it "has no effect since it is already frozen" do + r = Rational(1, 3) + r.frozen?.should == true + r.freeze end end @@ -74,12 +72,20 @@ describe "Kernel#freeze" do def mutate; @foo = 1; end end.new o.freeze - lambda {o.mutate}.should raise_error(RuntimeError) + -> {o.mutate}.should.raise(RuntimeError) end it "causes instance_variable_set to raise RuntimeError" do o = Object.new o.freeze - lambda {o.instance_variable_set(:@foo, 1)}.should raise_error(RuntimeError) + -> {o.instance_variable_set(:@foo, 1)}.should.raise(RuntimeError) + end + + it "freezes an object's singleton class" do + o = Object.new + c = o.singleton_class + c.frozen?.should == false + o.freeze + c.frozen?.should == true end end |
