Skip to content

Commit 52f095a

Browse files
committed
Add spec for 'for' and local variables defined outside the method
1 parent 258e170 commit 52f095a

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module ForSpecs
2+
class ForInClassMethod
3+
m = :same_variable_set_outside
4+
5+
def self.foo
6+
all = []
7+
for m in [:bar, :baz]
8+
all << m
9+
end
10+
all
11+
end
12+
13+
READER = -> { m }
14+
end
15+
end

spec/ruby/language/for_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require_relative '../spec_helper'
2+
require_relative 'fixtures/for_scope'
23

34
# for name[, name]... in expr [do]
45
# body
@@ -130,6 +131,11 @@ def each
130131
a.should == 123
131132
end
132133

134+
it "does not try to access variables outside the method" do
135+
ForSpecs::ForInClassMethod.foo.should == [:bar, :baz]
136+
ForSpecs::ForInClassMethod::READER.call.should == :same_variable_set_outside
137+
end
138+
133139
it "returns expr" do
134140
for i in 1..3; end.should == (1..3)
135141
for i,j in { 1 => 10, 2 => 20 }; end.should == { 1 => 10, 2 => 20 }

spec/tags/language/for_tags.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fails:The for expression does not try to access variables outside the method

0 commit comments

Comments
 (0)