Skip to content
This repository has been archived by the owner on Mar 16, 2023. It is now read-only.

Commit

Permalink
Use a private registry so that Foo::Bar is independent across tests.
Browse files Browse the repository at this point in the history
otherwise there would be a conflict between
  spec/ruby-lint/constant_loader_spec.rb
  spec/ruby-lint/virtual_machine/classes/extending_spec.rb
  • Loading branch information
mvidner committed Jun 25, 2016
1 parent a3aa837 commit 473b43c
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions spec/ruby-lint/constant_loader_spec.rb
Expand Up @@ -2,8 +2,15 @@

describe RubyLint::ConstantLoader do
before do
@registry = RubyLint::Definition::Registry.new
@definitions = ruby_object.new
@loader = RubyLint::ConstantLoader.new(:definitions => @definitions)

# Having our own registry is one thing, but the definitions
# in ruby-lint/definitions/core insist on applying themselves to the
# global one (before we can stub it) so we borrow the result now
@registry.stub(:registered).and_return(RubyLint.registry.registered.dup)
@loader.stub(:registry).and_return(@registry)
end

context 'bootstrapping definitions' do
Expand Down Expand Up @@ -78,23 +85,21 @@
end

context 'loading scoped constants' do
before(:all) do
# cannot be undone, hope it is OK
RubyLint.registry.register('Foo') do |defs|
it 'loads a constant from a scope' do
@registry.register('Foo') do |defs|
defs.define_constant('Foo') do |klass|
klass.inherits(defs.constant_proxy('Object', RubyLint.registry))
klass.inherits(defs.constant_proxy('Object', @registry))
klass.define_method('hello_foo')
end
end
RubyLint.registry.register('Foo::Bar') do |defs|

@registry.register('Foo::Bar') do |defs|
defs.define_constant('Foo::Bar') do |klass|
klass.inherits(defs.constant_proxy('Object', RubyLint.registry))
klass.inherits(defs.constant_proxy('Object', @registry))
klass.define_method('hello_bar')
end
end
end

it 'loads a constant from a scope' do
code = <<-CODE
module Foo
class Qux
Expand Down

0 comments on commit 473b43c

Please sign in to comment.