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

Commit

Permalink
Test loading scoped constants (Foo::Bar)
Browse files Browse the repository at this point in the history
If we have a definition with

    RubyLint.registry.register('Foo::Bar')

and code like

    module Foo
      Bar.baz
    end

then ruby-lint should load "Foo::Bar" first, only then try "Bar".
  • Loading branch information
mvidner committed Jun 25, 2016
1 parent 3d83ae7 commit a3aa837
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions spec/ruby-lint/constant_loader_spec.rb
Expand Up @@ -76,4 +76,38 @@
@loader.run([@ast])
end
end

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

it 'loads a constant from a scope' do
code = <<-CODE
module Foo
class Qux
def hello_qux
Bar.hello_bar
end
end
end
CODE
@ast = parse(code)

@loader.run([@ast])
@loader.loaded?('Foo::Bar').should == true
end
end
end

0 comments on commit a3aa837

Please sign in to comment.