1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00

Don't use Enumerators in unit tests

In previous commit (5d983f49a2) 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>
This commit is contained in:
Kyrylo Silin 2012-07-12 00:32:35 +03:00
parent 5d983f49a2
commit b3f71bc3b6
2 changed files with 44 additions and 52 deletions

View file

@ -5,12 +5,10 @@ describe "commands" do
@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 @@ describe "commands" do
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 @@ describe "commands" do
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 @@ describe "commands" do
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 file

@ -7,18 +7,13 @@ describe 'Pry::DefaultCommands::Cd' do
@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 'Pry::DefaultCommands::Cd' do
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 'Pry::DefaultCommands::Cd' do
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 @@ describe 'Pry::DefaultCommands::Cd' do
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 @@ describe 'Pry::DefaultCommands::Cd' do
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 'Pry::DefaultCommands::Cd' do
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 'Pry::DefaultCommands::Cd' do
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 @@ describe 'Pry::DefaultCommands::Cd' do
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 'Pry::DefaultCommands::Cd' do
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 'Pry::DefaultCommands::Cd' do
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 @@ describe 'Pry::DefaultCommands::Cd' do
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 'Pry::DefaultCommands::Cd' do
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 'Pry::DefaultCommands::Cd' do
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 @@ describe 'Pry::DefaultCommands::Cd' do
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,7 +230,7 @@ describe 'Pry::DefaultCommands::Cd' do
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
@ -244,7 +238,7 @@ describe 'Pry::DefaultCommands::Cd' do
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,7 +247,7 @@ describe 'Pry::DefaultCommands::Cd' do
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
@ -261,7 +255,7 @@ describe 'Pry::DefaultCommands::Cd' do
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
@ -269,7 +263,7 @@ describe 'Pry::DefaultCommands::Cd' do
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 @@ describe 'Pry::DefaultCommands::Cd' do
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 @@ describe 'Pry::DefaultCommands::Cd' do
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