opal 0.3.43 → 0.3.44
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +19 -0
- data/README.md +1 -0
- data/Rakefile +29 -19
- data/examples/native/Gemfile +3 -0
- data/examples/native/README.md +17 -0
- data/examples/native/app/app.rb +38 -0
- data/examples/native/config.ru +8 -0
- data/examples/native/index.html.erb +12 -0
- data/lib/opal/lexer.rb +5 -1
- data/lib/opal/parser.rb +36 -10
- data/lib/opal/processor.rb +10 -9
- data/lib/opal/server.rb +17 -7
- data/lib/opal/target_scope.rb +2 -2
- data/lib/opal/version.rb +1 -1
- data/opal/opal-browser/script_loader.rb +8 -13
- data/opal/opal.rb +23 -5
- data/opal/opal/array.rb +128 -14
- data/opal/opal/boolean.rb +1 -1
- data/opal/opal/class.rb +92 -18
- data/opal/opal/enumerable.rb +90 -0
- data/opal/opal/error.rb +1 -1
- data/opal/opal/hash.rb +2 -2
- data/opal/opal/kernel.rb +3 -3
- data/opal/opal/numeric.rb +1 -1
- data/opal/opal/proc.rb +1 -1
- data/opal/opal/regexp.rb +31 -31
- data/opal/opal/runtime.js +181 -69
- data/opal/opal/string.rb +561 -40
- data/opal/opal/time.rb +1 -1
- data/opal/rbconfig.rb +17 -3
- data/opal/strscan.rb +41 -5
- data/spec/opal/class/new_spec.rb +27 -0
- data/spec/opal/native_spec.rb +127 -0
- data/spec/ospec/runner.rb +0 -2
- data/spec/parser/strscan/get_byte_spec.rb +29 -0
- data/spec/parser/strscan/skip_spec.rb +40 -0
- data/spec/rubyspec/core/array/each_spec.rb +1 -1
- data/spec/rubyspec/core/array/intersection_spec.rb +5 -0
- data/spec/rubyspec/core/array/max_spec.rb +32 -0
- data/spec/rubyspec/core/array/min_spec.rb +32 -0
- data/spec/rubyspec/core/array/minus_spec.rb +7 -5
- data/spec/rubyspec/core/array/multiply_spec.rb +1 -1
- data/spec/rubyspec/core/array/plus_spec.rb +1 -1
- data/spec/rubyspec/core/array/pop_spec.rb +1 -1
- data/spec/rubyspec/core/array/push_spec.rb +1 -1
- data/spec/rubyspec/core/array/rassoc_spec.rb +1 -1
- data/spec/rubyspec/core/array/reject_spec.rb +2 -2
- data/spec/rubyspec/core/array/reverse_each_spec.rb +2 -2
- data/spec/rubyspec/core/array/rindex_spec.rb +2 -2
- data/spec/rubyspec/core/array/select_spec.rb +1 -1
- data/spec/rubyspec/core/array/shift_spec.rb +1 -1
- data/spec/rubyspec/core/array/slice_spec.rb +1 -1
- data/spec/rubyspec/core/array/sort_spec.rb +15 -15
- data/spec/rubyspec/core/array/to_a_spec.rb +1 -1
- data/spec/rubyspec/core/array/to_ary_spec.rb +1 -1
- data/spec/rubyspec/core/array/uniq_spec.rb +1 -1
- data/spec/rubyspec/core/array/unshift_spec.rb +1 -1
- data/spec/rubyspec/core/array/zip_spec.rb +1 -1
- data/spec/rubyspec/core/enumerable/select_spec.rb +4 -1
- data/spec/rubyspec/core/module/const_defined_spec.rb +86 -0
- data/spec/rubyspec/core/module/const_get_spec.rb +55 -3
- data/spec/rubyspec/core/module/const_set_spec.rb +2 -2
- data/spec/rubyspec/core/module/constants_spec.rb +49 -0
- data/spec/rubyspec/core/regexp/match_spec.rb +66 -1
- data/spec/rubyspec/core/string/center_spec.rb +71 -0
- data/spec/rubyspec/core/string/chomp_spec.rb +6 -1
- data/spec/rubyspec/core/string/clone_spec.rb +8 -0
- data/spec/rubyspec/core/string/dup_spec.rb +8 -0
- data/spec/rubyspec/core/string/end_with_spec.rb +5 -1
- data/spec/rubyspec/core/string/gsub_spec.rb +15 -1
- data/spec/rubyspec/core/string/lines_spec.rb +9 -0
- data/spec/rubyspec/core/string/ljust_spec.rb +17 -0
- data/spec/rubyspec/core/string/match_spec.rb +25 -3
- data/spec/rubyspec/core/string/rindex_spec.rb +50 -0
- data/spec/rubyspec/core/string/rjust_spec.rb +17 -0
- data/spec/rubyspec/core/string/scan_spec.rb +66 -0
- data/spec/rubyspec/core/string/sub_spec.rb +17 -1
- data/spec/rubyspec/core/string/tr_s_spec.rb +31 -0
- data/spec/rubyspec/core/string/tr_spec.rb +31 -0
- data/spec/rubyspec/fixtures/constants.rb +6 -0
- data/spec/rubyspec/language/class_spec.rb +4 -8
- data/spec/rubyspec/language/numbers_spec.rb +10 -4
- data/spec/rubyspec/language/predefined_spec.rb +69 -2
- data/spec/rubyspec/library/rbconfig/config_spec.rb +47 -0
- data/spec/rubyspec/spec_helper.rb +6 -0
- metadata +46 -25
- data/opal/opal-eventable.rb +0 -26
- data/opal/opal/native.rb +0 -115
- data/spec/opal/eventable_spec.rb +0 -75
- data/spec/opal/native/element_reference_spec.rb +0 -40
- data/spec/opal/native/equal_spec.rb +0 -17
- data/spec/opal/native/fixtures/classes.rb +0 -27
- data/spec/opal/native/global_spec.rb +0 -12
- data/spec/opal/native/initialize_spec.rb +0 -8
- data/spec/opal/native/method_missing_spec.rb +0 -53
- data/spec/opal/native/to_native_spec.rb +0 -8
- data/spec/rubyspec/core/string/demodulize_spec.rb +0 -10
- data/spec/rubyspec/core/string/underscore_spec.rb +0 -17
@@ -53,7 +53,7 @@ describe "Array#* with an integer" do
|
|
53
53
|
(ary * 1).should_not equal(ary)
|
54
54
|
end
|
55
55
|
|
56
|
-
|
56
|
+
it "properly handles recursive arrays" do
|
57
57
|
empty = ArraySpecs.empty_recursive_array
|
58
58
|
(empty * 0).should == []
|
59
59
|
(empty * 1).should == empty
|
@@ -20,7 +20,7 @@ describe "Array#+" do
|
|
20
20
|
([1, 2, 3] + obj).should == [1, 2, 3, "x", "y"]
|
21
21
|
end
|
22
22
|
|
23
|
-
|
23
|
+
it "properly handles recursive arrays" do
|
24
24
|
empty = ArraySpecs.empty_recursive_array
|
25
25
|
(empty + empty).should == [empty, empty]
|
26
26
|
|
@@ -10,7 +10,7 @@ describe "Array#rassoc" do
|
|
10
10
|
ary.rassoc("z").should == nil
|
11
11
|
end
|
12
12
|
|
13
|
-
|
13
|
+
it "properly handles recursive arrays" do
|
14
14
|
empty = ArraySpecs.empty_recursive_array
|
15
15
|
empty.rassoc([]).should be_nil
|
16
16
|
[[empty, empty]].rassoc(empty).should == [empty, empty]
|
@@ -21,7 +21,7 @@ describe "Array#reject" do
|
|
21
21
|
array.reject { |x| true }.should == []
|
22
22
|
end
|
23
23
|
|
24
|
-
|
24
|
+
it "properly handles recursive arrays" do
|
25
25
|
empty = ArraySpecs.empty_recursive_array
|
26
26
|
empty.reject { false }.should == [empty]
|
27
27
|
empty.reject { true }.should == []
|
@@ -79,7 +79,7 @@ describe "Array#reject!" do
|
|
79
79
|
a.should == []
|
80
80
|
end
|
81
81
|
|
82
|
-
|
82
|
+
it "properly handles recursive arrays" do
|
83
83
|
empty = ArraySpecs.empty_recursive_array
|
84
84
|
empty_dup = empty.dup
|
85
85
|
empty.reject! { false }.should == nil
|
@@ -21,13 +21,13 @@ describe "Array#reverse_each" do
|
|
21
21
|
a.reverse_each { |x| }.should equal(a)
|
22
22
|
end
|
23
23
|
|
24
|
-
|
24
|
+
it "yields only the top level element of an empty recursive arrays" do
|
25
25
|
empty = ArraySpecs.empty_recursive_array
|
26
26
|
empty.reverse_each { |i| ScratchPad << i }
|
27
27
|
ScratchPad.recorded.should == [empty]
|
28
28
|
end
|
29
29
|
|
30
|
-
|
30
|
+
it "yields only the top level element of a recursive array" do
|
31
31
|
array = ArraySpecs.recursive_array
|
32
32
|
array.reverse_each { |i| ScratchPad << i }
|
33
33
|
ScratchPad.recorded.should == [array, array, array, array, array, 3.0, 'two', 1]
|
@@ -31,13 +31,13 @@ describe "Array#rindex" do
|
|
31
31
|
[1, 1, 3, 2, 1, 3].rindex(4).should == nil
|
32
32
|
end
|
33
33
|
|
34
|
-
|
34
|
+
it "properly handles empty recursive arrays" do
|
35
35
|
empty = ArraySpecs.empty_recursive_array
|
36
36
|
empty.rindex(empty).should == 0
|
37
37
|
empty.rindex(1).should be_nil
|
38
38
|
end
|
39
39
|
|
40
|
-
|
40
|
+
it "properly handles recursive arrays" do
|
41
41
|
array = ArraySpecs.recursive_array
|
42
42
|
array.rindex(1).should == 0
|
43
43
|
array.rindex(array).should == 7
|
@@ -16,7 +16,7 @@ describe "Array#select" do
|
|
16
16
|
ArraySpecs::MyArray[1, 2, 3].select { true }.should be_kind_of(Array)
|
17
17
|
end
|
18
18
|
|
19
|
-
|
19
|
+
it "properly handles recursive arrays" do
|
20
20
|
empty = ArraySpecs.empty_recursive_array
|
21
21
|
empty.select { true }.should == empty
|
22
22
|
empty.select { false }.should == []
|
@@ -2,23 +2,23 @@ require File.expand_path('../../../spec_helper', __FILE__)
|
|
2
2
|
require File.expand_path('../fixtures/classes', __FILE__)
|
3
3
|
|
4
4
|
describe "Array#sort" do
|
5
|
-
|
5
|
+
it "returns a new array sorted based on comparing elements with <=>" do
|
6
6
|
a = [1, -2, 3, 9, 1, 5, -5, 1000, -5, 2, -10, 14, 6, 23, 0]
|
7
7
|
a.sort.should == [-10, -5, -5, -2, 0, 1, 1, 2, 3, 5, 6, 9, 14, 23, 1000]
|
8
8
|
end
|
9
9
|
|
10
|
-
|
10
|
+
it "does not affect the original Array" do
|
11
11
|
a = [0, 15, 2, 3, 4, 6, 14, 5, 7, 12, 8, 9, 1, 10, 11, 13]
|
12
12
|
b = a.sort
|
13
13
|
a.should == [0, 15, 2, 3, 4, 6, 14, 5, 7, 12, 8, 9, 1, 10, 11, 13]
|
14
14
|
b.should == (0..15).to_a
|
15
15
|
end
|
16
16
|
|
17
|
-
|
17
|
+
it "sorts already-sorted Arrays" do
|
18
18
|
(0..15).to_a.sort.should == (0..15).to_a
|
19
19
|
end
|
20
20
|
|
21
|
-
|
21
|
+
it "sorts reverse-sorted Arrays" do
|
22
22
|
(0..15).to_a.reverse.sort.should == (0..15).to_a
|
23
23
|
end
|
24
24
|
|
@@ -41,7 +41,7 @@ describe "Array#sort" do
|
|
41
41
|
sorted.should_not equal(a)
|
42
42
|
end
|
43
43
|
|
44
|
-
|
44
|
+
it "properly handles recursive arrays" do
|
45
45
|
empty = ArraySpecs.empty_recursive_array
|
46
46
|
empty.sort.should == empty
|
47
47
|
|
@@ -49,7 +49,7 @@ describe "Array#sort" do
|
|
49
49
|
array.sort.should == [[], array]
|
50
50
|
end
|
51
51
|
|
52
|
-
|
52
|
+
it "uses #<=> of elements in order to sort" do
|
53
53
|
a = ArraySpecs::MockForCompared.new
|
54
54
|
b = ArraySpecs::MockForCompared.new
|
55
55
|
c = ArraySpecs::MockForCompared.new
|
@@ -59,7 +59,7 @@ describe "Array#sort" do
|
|
59
59
|
ArraySpecs::MockForCompared.compared?.should == true
|
60
60
|
end
|
61
61
|
|
62
|
-
|
62
|
+
it "does not deal with exceptions raised by unimplemented or incorrect #<=>" do
|
63
63
|
o = Object.new
|
64
64
|
|
65
65
|
lambda { [o, 1].sort }.should raise_error
|
@@ -71,7 +71,7 @@ describe "Array#sort" do
|
|
71
71
|
a.sort {|x, y| y <=> x}.should == [5, 4, 3, 2, 1]
|
72
72
|
end
|
73
73
|
|
74
|
-
|
74
|
+
it "raises an error when a given block returns nil" do
|
75
75
|
lambda { [1, 2].sort {} }.should raise_error(ArgumentError)
|
76
76
|
end
|
77
77
|
|
@@ -101,7 +101,7 @@ describe "Array#sort" do
|
|
101
101
|
a.sort { |x,y| a.frozen?.should == false; x <=> y }
|
102
102
|
end
|
103
103
|
|
104
|
-
|
104
|
+
it "returns the specified value when it would break in the given block" do
|
105
105
|
[1, 2, 3].sort{ break :a }.should == :a
|
106
106
|
end
|
107
107
|
|
@@ -122,7 +122,7 @@ describe "Array#sort" do
|
|
122
122
|
end
|
123
123
|
end
|
124
124
|
|
125
|
-
|
125
|
+
it "compares values returned by block with 0" do
|
126
126
|
a = [1, 2, 5, 10, 7, -4, 12]
|
127
127
|
a.sort { |n, m| n - m }.should == [-4, 1, 2, 5, 7, 10, 12]
|
128
128
|
a.sort { |n, m|
|
@@ -147,7 +147,7 @@ describe "Array#sort" do
|
|
147
147
|
a.sort {|a, b| a <=> b }.last.should == 2
|
148
148
|
end
|
149
149
|
|
150
|
-
|
150
|
+
it "raises an error if objects can't be compared" do
|
151
151
|
a=[ArraySpecs::Uncomparable.new, ArraySpecs::Uncomparable.new]
|
152
152
|
lambda {a.sort}.should raise_error(ArgumentError)
|
153
153
|
end
|
@@ -174,7 +174,7 @@ describe "Array#sort" do
|
|
174
174
|
end
|
175
175
|
|
176
176
|
describe "Array#sort!" do
|
177
|
-
|
177
|
+
it "sorts array in place using <=>" do
|
178
178
|
a = [1, -2, 3, 9, 1, 5, -5, 1000, -5, 2, -10, 14, 6, 23, 0]
|
179
179
|
a.sort!
|
180
180
|
a.should == [-10, -5, -5, -2, 0, 1, 1, 2, 3, 5, 6, 9, 14, 23, 1000]
|
@@ -197,7 +197,7 @@ describe "Array#sort!" do
|
|
197
197
|
a.should == [1, 2, 3, 4, 5]
|
198
198
|
end
|
199
199
|
|
200
|
-
|
200
|
+
it "properly handles recursive arrays" do
|
201
201
|
empty = ArraySpecs.empty_recursive_array
|
202
202
|
empty.sort!.should == empty
|
203
203
|
|
@@ -205,7 +205,7 @@ describe "Array#sort!" do
|
|
205
205
|
array.sort!.should == array
|
206
206
|
end
|
207
207
|
|
208
|
-
|
208
|
+
it "uses #<=> of elements in order to sort" do
|
209
209
|
a = ArraySpecs::MockForCompared.new
|
210
210
|
b = ArraySpecs::MockForCompared.new
|
211
211
|
c = ArraySpecs::MockForCompared.new
|
@@ -256,7 +256,7 @@ describe "Array#sort!" do
|
|
256
256
|
end
|
257
257
|
end
|
258
258
|
|
259
|
-
|
259
|
+
it "returns the specified value when it would break in the given block" do
|
260
260
|
[1, 2, 3].sort{ break :a }.should == :a
|
261
261
|
end
|
262
262
|
|
@@ -1,3 +1,6 @@
|
|
1
|
+
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
+
require File.expand_path('../fixtures/classes', __FILE__)
|
3
|
+
|
1
4
|
describe "Enumerable#select" do
|
2
5
|
before :each do
|
3
6
|
ScratchPad.record []
|
@@ -10,4 +13,4 @@ describe "Enumerable#select" do
|
|
10
13
|
@numerous.select {|i| true }.should == @elements
|
11
14
|
@numerous.select {|i| false }.should == []
|
12
15
|
end
|
13
|
-
end
|
16
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
+
require File.expand_path('../../../fixtures/constants', __FILE__)
|
3
|
+
|
4
|
+
CD_CONST1 = :const1
|
5
|
+
|
6
|
+
module ConstDefinedSpecs
|
7
|
+
FOO = 100
|
8
|
+
|
9
|
+
module Bar
|
10
|
+
BAR = 200
|
11
|
+
|
12
|
+
module Baz
|
13
|
+
BAZ = 300
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class Dog
|
18
|
+
LEGS = 4
|
19
|
+
end
|
20
|
+
|
21
|
+
class Bloudhound < Dog
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "Module#const_defined?" do
|
26
|
+
it "should consider constants with values that evaluate to false in a JavaScript conditional as defined" do
|
27
|
+
Object.const_defined?("CS_NIL").should be_true
|
28
|
+
Object.const_defined?("CS_ZERO").should be_true
|
29
|
+
Object.const_defined?("CS_BLANK").should be_true
|
30
|
+
Object.const_defined?("CS_FALSE").should be_true
|
31
|
+
end
|
32
|
+
|
33
|
+
it "accepts a String or Symbol name" do
|
34
|
+
Object.const_defined?(:CD_CONST1).should be_true
|
35
|
+
Object.const_defined?("CD_CONST1").should be_true
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should return false if no constant is defined in the search path" do
|
39
|
+
Object.const_defined?(:CS_CONSTX_BAD).should be_false
|
40
|
+
end
|
41
|
+
|
42
|
+
it "raises a NameError if the name does not start with a capital letter" do
|
43
|
+
lambda { ConstantSpecs.const_defined? "name" }.should raise_error(NameError)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "raises a NameError if the name starts with a non-alphabetic character" do
|
47
|
+
lambda { ConstantSpecs.const_defined? "__CONSTX__" }.should raise_error(NameError)
|
48
|
+
lambda { ConstantSpecs.const_defined? "@Name" }.should raise_error(NameError)
|
49
|
+
lambda { ConstantSpecs.const_defined? "!Name" }.should raise_error(NameError)
|
50
|
+
lambda { ConstantSpecs.const_defined? "::Name" }.should raise_error(NameError)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "raises a NameError if the name contains non-word characters" do
|
54
|
+
# underscore (i.e., _) is a valid word character
|
55
|
+
ConstantSpecs.const_defined?("CD_CONST1").should be_true
|
56
|
+
lambda { ConstantSpecs.const_defined? "Name=" }.should raise_error(NameError)
|
57
|
+
lambda { ConstantSpecs.const_defined? "Name?" }.should raise_error(NameError)
|
58
|
+
end
|
59
|
+
|
60
|
+
it "searches parent scopes of classes and modules" do
|
61
|
+
Module.const_defined?(:ConstDefinedSpecs).should be_true
|
62
|
+
ConstDefinedSpecs.const_defined?(:ConstDefinedSpecs).should be_true
|
63
|
+
ConstDefinedSpecs::Bar::Baz.const_defined?(:BAZ).should be_true
|
64
|
+
ConstDefinedSpecs::Bar::Baz.const_defined?(:CD_CONST1).should be_true
|
65
|
+
ConstDefinedSpecs::Bar::Baz.const_defined?(:BAR).should be_false
|
66
|
+
ConstDefinedSpecs::Bar::Baz.const_defined?(:FOO).should be_false
|
67
|
+
ConstDefinedSpecs::Bar::Baz.const_defined?(:Bar).should be_false
|
68
|
+
ConstDefinedSpecs::Bar::Baz.const_defined?(:ConstDefinedSpecs).should be_true
|
69
|
+
ConstDefinedSpecs::Dog.const_defined?(:LEGS).should be_true
|
70
|
+
ConstDefinedSpecs::Dog.const_defined?(:Dog).should be_false
|
71
|
+
ConstDefinedSpecs::Bloudhound.const_defined?(:LEGS).should be_true
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should not search parent scopes of classes and modules if inherit is false" do
|
75
|
+
Module.const_defined?(:ConstDefinedSpecs, false).should be_false
|
76
|
+
ConstDefinedSpecs.const_defined?(:ConstDefinedSpecs, false).should be_false
|
77
|
+
ConstDefinedSpecs::Dog.const_defined?(:LEGS, false).should be_true
|
78
|
+
ConstDefinedSpecs::Dog.const_defined?(:Dog, false).should be_false
|
79
|
+
ConstDefinedSpecs::Bloudhound.const_defined?(:LEGS, false).should be_false
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should search parent scopes of classes and modules for Object regardless of inherit value" do
|
83
|
+
Object.const_defined?(:ConstDefinedSpecs).should be_true
|
84
|
+
Object.const_defined?(:ConstDefinedSpecs, false).should be_true
|
85
|
+
end
|
86
|
+
end
|
@@ -13,9 +13,23 @@ module ConstGetSpecs
|
|
13
13
|
BAZ = 300
|
14
14
|
end
|
15
15
|
end
|
16
|
+
|
17
|
+
class Dog
|
18
|
+
LEGS = 4
|
19
|
+
end
|
20
|
+
|
21
|
+
class Bloudhound < Dog
|
22
|
+
end
|
16
23
|
end
|
17
24
|
|
18
25
|
describe "Module#const_get" do
|
26
|
+
it "should get constants with values that evaluate to false in a JavaScript conditional" do
|
27
|
+
Object.const_get("CS_NIL").should be_nil
|
28
|
+
Object.const_get("CS_ZERO").should == 0
|
29
|
+
Object.const_get("CS_BLANK").should == ""
|
30
|
+
Object.const_get("CS_FALSE").should == false
|
31
|
+
end
|
32
|
+
|
19
33
|
it "accepts a String or Symbol name" do
|
20
34
|
Object.const_get(:CS_CONST1).should == :const1
|
21
35
|
Object.const_get("CS_CONST1").should == :const1
|
@@ -25,10 +39,48 @@ describe "Module#const_get" do
|
|
25
39
|
lambda { Object.const_get :CS_CONSTX_BAD }.should raise_error(NameError)
|
26
40
|
end
|
27
41
|
|
42
|
+
it "raises a NameError if the name does not start with a capital letter" do
|
43
|
+
lambda { ConstantSpecs.const_get "name" }.should raise_error(NameError)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "raises a NameError if the name starts with a non-alphabetic character" do
|
47
|
+
lambda { ConstantSpecs.const_get "__CONSTX__" }.should raise_error(NameError)
|
48
|
+
lambda { ConstantSpecs.const_get "@Name" }.should raise_error(NameError)
|
49
|
+
lambda { ConstantSpecs.const_get "!Name" }.should raise_error(NameError)
|
50
|
+
lambda { ConstantSpecs.const_get "::Name" }.should raise_error(NameError)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "raises a NameError if the name contains non-word characters" do
|
54
|
+
# underscore (i.e., _) is a valid word character
|
55
|
+
ConstantSpecs.const_get("CS_CONST1").should == :const1
|
56
|
+
lambda { ConstantSpecs.const_get "Name=" }.should raise_error(NameError)
|
57
|
+
lambda { ConstantSpecs.const_get "Name?" }.should raise_error(NameError)
|
58
|
+
end
|
59
|
+
|
28
60
|
it "searches parent scopes of classes and modules" do
|
61
|
+
Module.const_get(:ConstGetSpecs).should == ConstGetSpecs
|
62
|
+
ConstGetSpecs.const_get(:ConstGetSpecs).should == ConstGetSpecs
|
29
63
|
ConstGetSpecs::Bar::Baz.const_get(:BAZ).should == 300
|
30
|
-
ConstGetSpecs::Bar::Baz.const_get(:
|
31
|
-
ConstGetSpecs::Bar::Baz.const_get(:
|
32
|
-
ConstGetSpecs::Bar::Baz.const_get(:
|
64
|
+
ConstGetSpecs::Bar::Baz.const_get(:CS_CONST1).should == :const1
|
65
|
+
lambda { ConstGetSpecs::Bar::Baz.const_get(:BAR) }.should raise_error(NameError)
|
66
|
+
lambda { ConstGetSpecs::Bar::Baz.const_get(:FOO) }.should raise_error(NameError)
|
67
|
+
lambda { ConstGetSpecs::Bar::Baz.const_get(:Bar) }.should raise_error(NameError)
|
68
|
+
ConstGetSpecs::Bar::Baz.const_get(:ConstGetSpecs).should == ConstGetSpecs
|
69
|
+
ConstGetSpecs::Dog.const_get(:LEGS).should == 4
|
70
|
+
lambda { ConstGetSpecs::Dog.const_get(:Dog) }.should raise_error(NameError)
|
71
|
+
ConstGetSpecs::Bloudhound.const_get(:LEGS).should == 4
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should not search parent scopes of classes and modules if inherit is false" do
|
75
|
+
lambda { Module.const_get(:ConstGetSpecs, false) }.should raise_error(NameError)
|
76
|
+
lambda { ConstGetSpecs.const_get(:ConstGetSpecs, false) }.should raise_error(NameError)
|
77
|
+
ConstGetSpecs::Dog.const_get(:LEGS, false).should == 4
|
78
|
+
lambda { ConstGetSpecs::Dog.const_get(:Dog, false) }.should raise_error(NameError)
|
79
|
+
lambda { ConstGetSpecs::Bloudhound.const_get(:LEGS, false) }.should raise_error(NameError)
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should search parent scopes of classes and modules for Object regardless of inherit value" do
|
83
|
+
Object.const_get(:ConstGetSpecs).should == ConstGetSpecs
|
84
|
+
Object.const_get(:ConstGetSpecs, false).should == ConstGetSpecs
|
33
85
|
end
|
34
86
|
end
|