Skip to content

Instantly share code, notes, and snippets.

@ngollan

ngollan/load.rb Secret

Last active August 29, 2015 14:13
Show Gist options
  • Save ngollan/f90825123c529d02001a to your computer and use it in GitHub Desktop.
Save ngollan/f90825123c529d02001a to your computer and use it in GitHub Desktop.
# goes into spec/ruby/core/kernel/shared/load.rb
describe :kernel_load, :shared => true do
# ...
describe "when passed true for 'wrap'" do
it "loads from an existing path" do
path = File.expand_path "wrap_fixture.rb", CODE_LOADING_DIR
@object.load(path, true).should be_true
end
it "sets the enclosing scope to an anonymous module" do
path = File.expand_path "wrap_fixture.rb", CODE_LOADING_DIR
@object.load(path, true)
Object.const_defined?(:LoadSpecWrap).should be_false
end
it "allows referencing outside namespaces" do
path = File.expand_path "wrap_fixture.rb", CODE_LOADING_DIR
@object.load(path, true)
ScratchPad.recorded.first.should be_an_instance_of(Class)
end
describe "with top-level methods" do
before :each do
path = File.expand_path "load_wrap_method_fixture.rb", CODE_LOADING_DIR
@object.load(path, true)
end
it "allows calling top-level methods" do
ScratchPad.recorded.last.should == :load_wrap_loaded
end
it "does not pollute the receiver" do
lambda { @object.send(:top_level_method) }.should raise_error(NameError)
end
end
end
# ...
end
# spec/ruby/fixtures/code/load_wrap_method_fixture.rb
def top_level_method
::ScratchPad << :load_wrap_loaded
end
begin
top_level_method
rescue NameError
::ScratchPad << :load_wrap_error
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment