Skip to content
Browse files

Don't use Enumerators in unit tests

In previous commit (5d983f4) I added
Enumerators to unit tests. It appears that Enumerator is not available
for Ruby 1.8.7 and friends. So, let's rewrite the related to Enumerator
code and hard-code everything again.

Signed-off-by: Kyrylo Silin <kyrylosilin@gmail.com>
  • Loading branch information...
1 parent 5d983f4 commit b3f71bc3b6ca0d352513f921a784a3bd38734b69 @kyrylo kyrylo committed Jul 12, 2012
Showing with 44 additions and 52 deletions.
  1. +10 −12 test/test_command_integration.rb
  2. +34 −40 test/test_default_commands/test_cd.rb
View
22 test/test_command_integration.rb
@@ -5,12 +5,10 @@
@str_output = StringIO.new
@o = Object.new
- # The `@bs` Enumerator yields strings for tests that require binding stack
- # checkings (for example,Pad.bs1, Pad.bs2 and so on).
- @bs = Enumerator.new do |y|
- n = 0
- loop { y << "Pad.bs#{n+=1} = _pry_.binding_stack.dup" }
- end
+ # Shortcuts. They save a lot of typing.
+ @bs1 = "Pad.bs1 = _pry_.binding_stack.dup"
+ @bs2 = "Pad.bs2 = _pry_.binding_stack.dup"
+ @bs3 = "Pad.bs3 = _pry_.binding_stack.dup"
@self = "Pad.self = self"
@@ -140,8 +138,8 @@
run "cd / "
end
end
- redirect_pry_io(InputTester.new("cd 1/2/3/4/5/6", @bs.next, "test-run",
- @self, @bs.next, "exit-all")) do
+ redirect_pry_io(InputTester.new("cd 1/2/3/4/5/6", @bs1, "test-run",
+ @self, @bs2, "exit-all")) do
Pry.start(@o, :commands => set)
end
@@ -157,8 +155,8 @@
run "cd /"
end
end
- redirect_pry_io(InputTester.new("cd 1/2/3/4/5/6", @bs.next, "test-run",
- @self, @bs.next, "exit-all")) do
+ redirect_pry_io(InputTester.new("cd 1/2/3/4/5/6", @bs1, "test-run",
+ @self, @bs2, "exit-all")) do
Pry.start(@o, :commands => set)
end
@@ -174,8 +172,8 @@
run "cd", "/"
end
end
- redirect_pry_io(InputTester.new("cd 1/2/3/4/5/6", @bs.next, "test-run",
- @self, @bs.next, "exit-all")) do
+ redirect_pry_io(InputTester.new("cd 1/2/3/4/5/6", @bs1, "test-run",
+ @self, @bs2, "exit-all")) do
Pry.start(@o, :commands => set)
end
View
74 test/test_default_commands/test_cd.rb
@@ -7,18 +7,13 @@
@obj.instance_variable_set(:@y, 79)
@o.instance_variable_set(:@obj, @obj)
- # The `@bs` Enumerator yields strings for tests that require binding stack
- # checkings (for example,Pad.bs1, Pad.bs2 and so on).
- @bs = Enumerator.new do |y|
- n = 0
- loop { y << "Pad.bs#{n+=1} = _pry_.binding_stack.dup" }
- end
+ # Shortcuts. They save a lot of typing.
+ @bs1 = "Pad.bs1 = _pry_.binding_stack.dup"
+ @bs2 = "Pad.bs2 = _pry_.binding_stack.dup"
+ @bs3 = "Pad.bs3 = _pry_.binding_stack.dup"
- # Same as `@bs`, but for command state's old stack.
- @os = Enumerator.new do |y|
- n = 0
- loop { y << "Pad.os#{n+=1} = _pry_.command_state['cd'].old_stack.dup" }
- end
+ @os1 = "Pad.os1 = _pry_.command_state['cd'].old_stack.dup"
+ @os2 = "Pad.os2 = _pry_.command_state['cd'].old_stack.dup"
@self = "Pad.self = self"
@inner = "Pad.inner = self"
@@ -31,7 +26,7 @@
describe 'state' do
it 'should not to be set up in fresh instance' do
- redirect_pry_io(InputTester.new(@os.next, "exit-all")) do
+ redirect_pry_io(InputTester.new(@os1, "exit-all")) do
Pry.start(@o)
end
@@ -42,8 +37,8 @@
describe 'old stack toggling with `cd -`' do
describe 'in fresh pry instance' do
it 'should not toggle when there is no old stack' do
- redirect_pry_io(InputTester.new("cd -", @bs.next, "cd -",
- @bs.next, "exit-all")) do
+ redirect_pry_io(InputTester.new("cd -", @bs1, "cd -",
+ @bs2, "exit-all")) do
Pry.start(@o)
end
@@ -58,7 +53,7 @@
end
it 'should not toggle and should keep correct old stack' do
- redirect_pry_io(InputTester.new("cd @", @os.next, "cd -", @os.next, "exit-all")) do
+ redirect_pry_io(InputTester.new("cd @", @os1, "cd -", @os2, "exit-all")) do
Pry.start(@o)
end
@@ -67,8 +62,7 @@
end
it 'should not toggle and should keep correct current binding stack' do
- redirect_pry_io(InputTester.new("cd @", @bs.next, "cd -",
- @bs.next, "exit-all")) do
+ redirect_pry_io(InputTester.new("cd @", @bs1, "cd -", @bs2, "exit-all")) do
Pry.start(@o)
end
@@ -79,8 +73,8 @@
describe 'when using simple cd syntax' do
it 'should toggle' do
- redirect_pry_io(InputTester.new("cd :mon_dogg", "cd -", @bs.next,
- "cd -", @bs.next, "exit-all")) do
+ redirect_pry_io(InputTester.new("cd :mon_dogg", "cd -", @bs1,
+ "cd -", @bs2, "exit-all")) do
Pry.start(@o)
end
@@ -91,8 +85,8 @@
describe "when using complex cd syntax" do
it 'should toggle with a complex path (simple case)' do
- redirect_pry_io(InputTester.new("cd 1/2/3", "cd -", @bs.next,
- "cd -", @bs.next, "exit-all")) do
+ redirect_pry_io(InputTester.new("cd 1/2/3", "cd -", @bs1,
+ "cd -", @bs2, "exit-all")) do
Pry.start(@o)
end
@@ -102,7 +96,7 @@
it 'should toggle with a complex path (more complex case)' do
redirect_pry_io(InputTester.new("cd 1/2/3", "cd ../4", "cd -",
- @bs.next, "cd -", @bs.next, "exit-all")) do
+ @bs1, "cd -", @bs2, "exit-all")) do
Pry.start(@o)
end
@@ -114,7 +108,7 @@
describe 'series of cd calls' do
it 'should toggle with fuzzy `cd -` calls' do
redirect_pry_io(InputTester.new("cd :mon_dogg", "cd -", "cd 42", "cd -",
- @bs.next, "cd -", @bs.next, "exit-all")) do
+ @bs1, "cd -", @bs2, "exit-all")) do
Pry.start(@o)
end
@@ -125,8 +119,8 @@
describe 'when using cd ..' do
it 'should toggle with a simple path' do
- redirect_pry_io(InputTester.new("cd :john_dogg", "cd ..", @bs.next,
- "cd -", @bs.next, "exit-all")) do
+ redirect_pry_io(InputTester.new("cd :john_dogg", "cd ..", @bs1,
+ "cd -", @bs2, "exit-all")) do
Pry.start(@o)
end
@@ -135,8 +129,8 @@
end
it 'should toggle with a complex path' do
- redirect_pry_io(InputTester.new("cd 1/2/3/../4", "cd -", @bs.next,
- "cd -", @bs.next, "exit-all")) do
+ redirect_pry_io(InputTester.new("cd 1/2/3/../4", "cd -", @bs1,
+ "cd -", @bs2, "exit-all")) do
Pry.start(@o)
end
@@ -147,8 +141,8 @@
describe 'when using cd ::' do
it 'should toggle' do
- redirect_pry_io(InputTester.new("cd ::", "cd -", @bs.next,
- "cd -", @bs.next, "exit-all")) do
+ redirect_pry_io(InputTester.new("cd ::", "cd -", @bs1,
+ "cd -", @bs2, "exit-all")) do
Pry.start(@o)
end
@@ -159,8 +153,8 @@
describe 'when using cd /' do
it 'should toggle' do
- redirect_pry_io(InputTester.new("cd /", "cd -", @bs.next, "cd :john_dogg",
- "cd /", "cd -", @bs.next, "exit-all")) do
+ redirect_pry_io(InputTester.new("cd /", "cd -", @bs1, "cd :john_dogg",
+ "cd /", "cd -", @bs2, "exit-all")) do
Pry.start(@o)
end
@@ -176,8 +170,8 @@
it 'should keep correct old binding' do
redirect_pry_io(InputTester.new("cd :john_dogg", "cd :mon_dogg",
- "cd :kyr_dogg", @control_d, @bs.next,
- "cd -", @bs.next, "cd -", @bs.next, "exit-all")) do
+ "cd :kyr_dogg", @control_d, @bs1,
+ "cd -", @bs2, "cd -", @bs3, "exit-all")) do
Pry.start(@o)
end
@@ -236,15 +230,15 @@
end
it 'should cd into an object and its ivar using cd obj/@ivar syntax' do
- redirect_pry_io(InputTester.new("cd @obj/@x", @bs.next, "exit-all")) do
+ redirect_pry_io(InputTester.new("cd @obj/@x", @bs1, "exit-all")) do
Pry.start(@o)
end
Pad.bs1.map { |v| v.eval("self") }.should == [@o, @obj, 66]
end
it 'should cd into an object and its ivar using cd obj/@ivar/ syntax (note following /)' do
- redirect_pry_io(InputTester.new("cd @obj/@x/", @bs.next, "exit-all")) do
+ redirect_pry_io(InputTester.new("cd @obj/@x/", @bs1, "exit-all")) do
Pry.start(@o)
end
@@ -253,23 +247,23 @@
it 'should cd into previous object and its local using cd ../local syntax' do
redirect_pry_io(InputTester.new("cd @obj", "local = :local", "cd @x",
- "cd ../local", @bs.next, "exit-all")) do
+ "cd ../local", @bs1, "exit-all")) do
Pry.start(@o)
end
Pad.bs1.map { |v| v.eval("self") }.should == [@o, @obj, :local]
end
it 'should cd into an object and its ivar and back again using cd obj/@ivar/.. syntax' do
- redirect_pry_io(InputTester.new("cd @obj/@x/..", @bs.next, "exit-all")) do
+ redirect_pry_io(InputTester.new("cd @obj/@x/..", @bs1, "exit-all")) do
Pry.start(@o)
end
Pad.bs1.map { |v| v.eval("self") }.should == [@o, @obj]
end
it 'should cd into an object and its ivar and back and then into another ivar using cd obj/@ivar/../@y syntax' do
- redirect_pry_io(InputTester.new("cd @obj/@x/../@y", @bs.next, "exit-all")) do
+ redirect_pry_io(InputTester.new("cd @obj/@x/../@y", @bs1, "exit-all")) do
Pry.start(@o)
end
@@ -278,7 +272,7 @@
it 'should cd back to top-level and then into another ivar using cd /@ivar/ syntax' do
redirect_pry_io(InputTester.new("@z = 20", "cd @obj/@x/", "cd /@z",
- @bs.next, "exit-all")) do
+ @bs1, "exit-all")) do
Pry.start(@o)
end
@@ -307,7 +301,7 @@ def @o.hello(x, y, z)
it 'should not cd into complex input when it encounters an exception' do
redirect_pry_io(InputTester.new("cd 1/2/swoop_a_doop/3",
- @bs.next, "exit-all")) do
+ @bs1, "exit-all")) do
Pry.start(@o)
end

0 comments on commit b3f71bc

Please sign in to comment.
Something went wrong with that request. Please try again.