Fix Mutant::Loader to use correct constant scope
* Do not load the compiled code before CompiledCode#create_script was called. * Add a test case that illustrates the issue.
This commit is contained in:
parent
28bbf9af00
commit
e7ea0bbde7
3 changed files with 50 additions and 13 deletions
|
@ -25,16 +25,22 @@ module Mutant
|
|||
#
|
||||
def initialize(root)
|
||||
@root = Helper.deep_clone(root)
|
||||
Rubinius.run_script(compiled_code)
|
||||
Rubinius.run_script(script.compiled_code)
|
||||
end
|
||||
|
||||
# Return code script
|
||||
#
|
||||
# @return [Rubinisu::CompiledCode::Script]
|
||||
#
|
||||
# @api private
|
||||
#
|
||||
def script
|
||||
compiled_code.create_script
|
||||
end
|
||||
|
||||
# Return compiled code for node
|
||||
#
|
||||
# This method actually returns a Rubnius::CompiledMethod
|
||||
# instance. But it is named on the future name of CompiledMethod
|
||||
# that will be renamed to Rubinius::CompiledCode.
|
||||
#
|
||||
# @return [Rubinius::CompiledMethod]
|
||||
# @return [Rubinius::CompiledCode]
|
||||
#
|
||||
# @api private
|
||||
#
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Mutant::Loader, '.load' do
|
||||
subject { object.load(node) }
|
||||
|
||||
let(:object) { described_class }
|
||||
end
|
38
spec/unit/mutant/loader/class_methods/run_spec.rb
Normal file
38
spec/unit/mutant/loader/class_methods/run_spec.rb
Normal file
|
@ -0,0 +1,38 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Mutant::Loader, '.run' do
|
||||
subject { object.run(node) }
|
||||
|
||||
let(:object) { described_class }
|
||||
|
||||
after do
|
||||
Object.send(:remove_const, :SomeNamespace)
|
||||
end
|
||||
|
||||
let(:source) do
|
||||
# This test case will blow up when not executed
|
||||
# under toplevel binding.
|
||||
<<-RUBY
|
||||
class SomeNamespace
|
||||
class Bar
|
||||
end
|
||||
|
||||
class SomeOther
|
||||
class Foo < Bar
|
||||
end
|
||||
end
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
let(:node) do
|
||||
Rubinius::AST::Script.new(source.to_ast).tap do |source|
|
||||
source.file = "/some/source"
|
||||
end
|
||||
end
|
||||
|
||||
it 'should load nodes into vm' do
|
||||
subject
|
||||
SomeNamespace::SomeOther::Foo
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue