Skip to content

Commit 977c82b

Browse files
committed
Improve Kernel#load(path, true) specs about the wrap module
1 parent 2035a09 commit 977c82b

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,21 +97,25 @@
9797
@object.load(path, true)
9898

9999
Object.const_defined?(:LoadSpecWrap).should be_false
100+
101+
wrap_module = ScratchPad.recorded[1]
102+
wrap_module.should be_an_instance_of(Module)
100103
end
101104

102105
it "allows referencing outside namespaces" do
103106
path = File.expand_path "wrap_fixture.rb", CODE_LOADING_DIR
104107
@object.load(path, true)
105108

106-
ScratchPad.recorded.first.should equal(String)
109+
ScratchPad.recorded[0].should equal(String)
107110
end
108111

109112
it "sets self as a copy of the top-level main" do
110113
path = File.expand_path "wrap_fixture.rb", CODE_LOADING_DIR
111114
@object.load(path, true)
112115

113-
top_level = ScratchPad.recorded.last
116+
top_level = ScratchPad.recorded[2]
114117
top_level.to_s.should == "main"
118+
top_level.method(:to_s).owner.should == top_level.singleton_class
115119
top_level.should_not equal(main)
116120
top_level.should be_an_instance_of(Object)
117121
end
@@ -126,9 +130,12 @@
126130
path = File.expand_path "wrap_fixture.rb", CODE_LOADING_DIR
127131
@object.load(path, true)
128132

129-
top_level = ScratchPad.recorded.last
133+
top_level = ScratchPad.recorded[2]
130134
top_level_ancestors = top_level.singleton_class.ancestors[-main_ancestors.size..-1]
131135
top_level_ancestors.should == main_ancestors
136+
137+
wrap_module = ScratchPad.recorded[1]
138+
top_level.singleton_class.ancestors.should == [top_level.singleton_class, wrap_module, *main_ancestors]
132139
end
133140

134141
describe "with top-level methods" do

spec/ruby/fixtures/code/wrap_fixture.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,8 @@ class LoadSpecWrap
22
ScratchPad << String
33
end
44

5+
def load_wrap_specs_top_level_method
6+
end
7+
ScratchPad << method(:load_wrap_specs_top_level_method).owner
8+
59
ScratchPad << self

0 commit comments

Comments
 (0)