diff options
author | Benoit Daloze <[email protected]> | 2022-06-26 14:50:14 +0200 |
---|---|---|
committer | Benoit Daloze <[email protected]> | 2022-06-26 14:50:14 +0200 |
commit | d3d5ef0cca160fca538c7f556c5a6e08df5847e6 (patch) | |
tree | 57358b4b9cdd6f429d0383005ac393cb74dd3bff /spec/ruby/core/kernel | |
parent | f616e816372d14e605879d2e43c7fbdda29ef837 (diff) |
Update to ruby/spec@ab32a1a
Diffstat (limited to 'spec/ruby/core/kernel')
-rw-r--r-- | spec/ruby/core/kernel/instance_variable_get_spec.rb | 6 | ||||
-rw-r--r-- | spec/ruby/core/kernel/instance_variable_set_spec.rb | 6 | ||||
-rw-r--r-- | spec/ruby/core/kernel/remove_instance_variable_spec.rb | 13 | ||||
-rw-r--r-- | spec/ruby/core/kernel/shared/require.rb | 19 |
4 files changed, 44 insertions, 0 deletions
diff --git a/spec/ruby/core/kernel/instance_variable_get_spec.rb b/spec/ruby/core/kernel/instance_variable_get_spec.rb index bb6f03d3bf..f1d2a45df8 100644 --- a/spec/ruby/core/kernel/instance_variable_get_spec.rb +++ b/spec/ruby/core/kernel/instance_variable_get_spec.rb @@ -67,6 +67,12 @@ describe "Kernel#instance_variable_get when passed Symbol" do it "raises a NameError when the passed Symbol is an invalid instance variable name" do -> { @obj.instance_variable_get(:"@0") }.should raise_error(NameError) end + + it "returns nil or raises for frozen objects" do + nil.instance_variable_get(:@foo).should == nil + -> { nil.instance_variable_get(:foo) }.should raise_error(NameError) + :foo.instance_variable_get(:@foo).should == nil + end end describe "Kernel#instance_variable_get when passed String" do diff --git a/spec/ruby/core/kernel/instance_variable_set_spec.rb b/spec/ruby/core/kernel/instance_variable_set_spec.rb index dbd257f7b9..2c25f4366f 100644 --- a/spec/ruby/core/kernel/instance_variable_set_spec.rb +++ b/spec/ruby/core/kernel/instance_variable_set_spec.rb @@ -95,5 +95,11 @@ describe "Kernel#instance_variable_set" do o.instance_variable_set(:@💙, 42) o.instance_variable_get(:@💙).should == 42 end + + it "raises for frozen objects" do + -> { nil.instance_variable_set(:@foo, 42) }.should raise_error(FrozenError) + -> { nil.instance_variable_set(:foo, 42) }.should raise_error(NameError) + -> { :foo.instance_variable_set(:@foo, 42) }.should raise_error(FrozenError) + end end end diff --git a/spec/ruby/core/kernel/remove_instance_variable_spec.rb b/spec/ruby/core/kernel/remove_instance_variable_spec.rb index e90efc8aed..4e5ba5e018 100644 --- a/spec/ruby/core/kernel/remove_instance_variable_spec.rb +++ b/spec/ruby/core/kernel/remove_instance_variable_spec.rb @@ -41,6 +41,19 @@ describe "Kernel#remove_instance_variable" do end.should raise_error(TypeError) end + it "raises a FrozenError if self is frozen" do + o = Object.new + o.freeze + -> { o.remove_instance_variable(:@foo) }.should raise_error(FrozenError) + -> { o.remove_instance_variable(:foo) }.should raise_error(NameError) + end + + it "raises for frozen objects" do + -> { nil.remove_instance_variable(:@foo) }.should raise_error(FrozenError) + -> { nil.remove_instance_variable(:foo) }.should raise_error(NameError) + -> { :foo.remove_instance_variable(:@foo) }.should raise_error(FrozenError) + end + describe "when passed a String" do it_behaves_like :kernel_remove_instance_variable, nil, "@greeting" end diff --git a/spec/ruby/core/kernel/shared/require.rb b/spec/ruby/core/kernel/shared/require.rb index cf01b9dc52..666ca15e11 100644 --- a/spec/ruby/core/kernel/shared/require.rb +++ b/spec/ruby/core/kernel/shared/require.rb @@ -568,6 +568,25 @@ describe :kernel_require, shared: true do -> { @object.require("unicode_normalize") }.should raise_error(LoadError) end + + ruby_version_is "3.0" do + it "does not load a file earlier on the $LOAD_PATH when other similar features were already loaded" do + Dir.chdir CODE_LOADING_DIR do + @object.send(@method, "../code/load_fixture").should be_true + end + ScratchPad.recorded.should == [:loaded] + + $LOAD_PATH.unshift "#{CODE_LOADING_DIR}/b" + # This loads because the above load was not on the $LOAD_PATH + @object.send(@method, "load_fixture").should be_true + ScratchPad.recorded.should == [:loaded, :loaded] + + $LOAD_PATH.unshift "#{CODE_LOADING_DIR}/c" + # This does not load because the above load was on the $LOAD_PATH + @object.send(@method, "load_fixture").should be_false + ScratchPad.recorded.should == [:loaded, :loaded] + end + end end describe "(shell expansion)" do |