Skip to content

Commit 2035a09

Browse files
committed
Add specs for self under Kernel#load(path, true)
1 parent 442e851 commit 2035a09

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

spec/ruby/core/kernel/shared/load.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
main = self
2+
13
describe :kernel_load, shared: true do
24
before :each do
35
CodeLoadingSpecs.spec_setup
@@ -104,6 +106,31 @@
104106
ScratchPad.recorded.first.should equal(String)
105107
end
106108

109+
it "sets self as a copy of the top-level main" do
110+
path = File.expand_path "wrap_fixture.rb", CODE_LOADING_DIR
111+
@object.load(path, true)
112+
113+
top_level = ScratchPad.recorded.last
114+
top_level.to_s.should == "main"
115+
top_level.should_not equal(main)
116+
top_level.should be_an_instance_of(Object)
117+
end
118+
119+
it "includes modules included in main's singleton class in self's class" do
120+
mod = Module.new
121+
main.extend(mod)
122+
123+
main_ancestors = main.singleton_class.ancestors[1..-1]
124+
main_ancestors.first.should == mod
125+
126+
path = File.expand_path "wrap_fixture.rb", CODE_LOADING_DIR
127+
@object.load(path, true)
128+
129+
top_level = ScratchPad.recorded.last
130+
top_level_ancestors = top_level.singleton_class.ancestors[-main_ancestors.size..-1]
131+
top_level_ancestors.should == main_ancestors
132+
end
133+
107134
describe "with top-level methods" do
108135
before :each do
109136
path = File.expand_path "load_wrap_method_fixture.rb", CODE_LOADING_DIR
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
class LoadSpecWrap
22
ScratchPad << String
33
end
4+
5+
ScratchPad << self

0 commit comments

Comments
 (0)