-
Notifications
You must be signed in to change notification settings - Fork 608
/
const_lookup_spec.rb
47 lines (37 loc) · 1.09 KB
/
const_lookup_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
require File.expand_path('../../../spec_helper', __FILE__)
CONST = 2
module ConstLookupSpecs
class A
class B
CONST = 1
end
class C; end
class D
def self.const_missing(const)
A::B::CONST
end
end
end
end
describe Kernel, "#const_lookup" do
it "returns the constant specified by 'A::B'" do
const_lookup("ConstLookupSpecs::A::B").should == ConstLookupSpecs::A::B
end
it "returns a regular constant specified without scoping" do
const_lookup("ConstLookupSpecs").should == ConstLookupSpecs
end
it "returns an explicit toplevel constant" do
const_lookup("::ConstLookupSpecs").should == ConstLookupSpecs
end
it "returns the constant from the proper scope" do
const_lookup("ConstLookupSpecs::A::B::CONST").should == 1
end
it "raises NameError if the constant is not contained within the module's scope" do
lambda {
const_lookup("ConstLookupSpecs::A::C::CONST")
}.should raise_error(NameError)
end
it "returns the value of #const_missing" do
const_lookup("ConstLookupSpecs::A::D::CONST").should == 1
end
end