Skip to content

Commit

Permalink
Fixed break specs unnecessarily relying on and guarding against block…
Browse files Browse the repository at this point in the history
… argument shadowing behaviour.

Rather than guard the spec and duplicate it incorrectly (the previous version had, for 1.9, specs that would succeed regardless of the behaviour of break), it should simply not depend on whether or not the blockarg shadows the outer variable. As such, specs that need this behaviour update an at variable instead of directly assigning to it through their block args.
  • Loading branch information
stormbrew committed Jan 26, 2011
1 parent fd53047 commit a0f52fc
Showing 1 changed file with 20 additions and 48 deletions.
68 changes: 20 additions & 48 deletions language/break_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -335,54 +335,26 @@ def three
end
end

ruby_version_is "" ... "1.9" do
it "stops any loop type at the correct spot" do
i = 0; loop do break i if i == 2; i+=1; end.should == 2
i = 0; loop do break if i == 3; i+=1; end; i.should == 3
i = 0; 0.upto(5) {|i| break i if i == 2 }.should == 2
i = 0; 0.upto(5) {|i| break if i == 3 }; i.should == 3
i = 0; while (i < 5) do break i if i == 2 ; i+=1; end.should == 2
i = 0; while (i < 5) do break if i == 3 ; i+=1; end; i.should == 3
end
end

ruby_version_is "1.9" do
it "stops any loop type at the correct spot" do
i = 0; loop do break i if i == 2; i+=1; end.should == 2
i = 0; loop do break if i == 3; i+=1; end; i.should == 3
i = 0; 0.upto(5) {|i| break i if i == 2 }.should == 2
i = 0; 0.upto(5) {|i| break if i == 3 }; i.should == 0
i = 0; while (i < 5) do break i if i == 2 ; i+=1; end.should == 2
i = 0; while (i < 5) do break if i == 3 ; i+=1; end; i.should == 3
end
end

ruby_version_is "" ... "1.9" do
it "stops a yielded method at the correct spot" do
def break_test()
yield 1
yield 2
yield 3
end
break_test {|i| break i if i == 2 }.should == 2
i = 0
break_test {|i| break i if i == 1 }
i.should == 1
end
end

ruby_version_is "1.9" do
it "stops a yielded method at the correct spot" do
def break_test()
yield 1
yield 2
yield 3
end
break_test {|i| break i if i == 2 }.should == 2
i = 0
break_test {|i| break i if i == 1 }
i.should == 0
end
it "stops any loop type at the correct spot" do
i = 0; loop do break i if i == 2; i+=1; end.should == 2
i = 0; loop do break if i == 3; i+=1; end; i.should == 3
i = 0; while (i < 5) do break i if i == 2 ; i+=1; end.should == 2
i = 0; while (i < 5) do break if i == 3 ; i+=1; end; i.should == 3

at = 0; 0.upto(5) {|i| at = i; break i if i == 2 }.should == 2
at = 0; 0.upto(5) {|i| at = i; break if i == 3 }; at.should == 3
end

it "stops a yielded method at the correct spot" do
def break_test()
yield 1
yield 2
yield 3
end
break_test {|i| break i if i == 2 }.should == 2
at = 0
break_test {|i| at = i; break i if i == 1 }
at.should == 1
end
end

Expand Down

0 comments on commit a0f52fc

Please sign in to comment.