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

other tests passing: commands

This commit is contained in:
John Mair 2011-01-06 11:07:06 +13:00
parent 329f49afa1
commit 12758922e8
2 changed files with 37 additions and 11 deletions

View file

@ -88,7 +88,7 @@ describe Pry do
describe "nesting" do
it 'should nest properly' do
Pry.input = InputTester.new("pry", "pry", "pry", "\"nest:\#\{Pry.nesting.level\}\"", "exit", "exit", "exit", "exit")
Pry.input = InputTester.new("pry", "pry", "pry", "\"nest:\#\{Pry.nesting.level\}\"", "exit_all")
str_output = StringIO.new
Pry.output = Pry::Output.new(str_output)
@ -104,16 +104,40 @@ describe Pry do
end
end
# describe "commands" do
# before do
# Pry.input = InputTester.new("exit")
describe "commands" do
after do
Pry.reset_defaults
end
# Pry.output = OutputTester.new
# end
it 'should run command1' do
pry_tester = Pry.new
pry_tester.commands = CommandTester.new
pry_tester.input = InputTester.new("command1", "exit_all")
pry_tester.commands = CommandTester.new
str_output = StringIO.new
pry_tester.output = Pry::Output.new(str_output)
pry_tester.rep
str_output.string.should =~ /command1/
end
it 'should run command2' do
pry_tester = Pry.new
pry_tester.commands = CommandTester.new
pry_tester.repl
pry_tester.input = InputTester.new("command2 horsey", "exit_all")
pry_tester.commands = CommandTester.new
str_output = StringIO.new
pry_tester.output = Pry::Output.new(str_output)
pry_tester.rep
str_output.string.should =~ /horsey/
end
# after do
# Pry.reset_defaults
# end
# commands = {
# "!" => "refresh",
@ -184,3 +208,4 @@ describe Pry do
end
end
end
end

View file

@ -21,10 +21,11 @@ end
class CommandTester
def commands
@commands ||= {
"command1" => proc { |opts| opts[:output].puts "command1" },
/command2\s*(.+)/ => proc do |opts|
"command1" => proc { |opts| opts[:output].puts "command1"; opts[:val].clear },
/command2\s*(.*)/ => proc do |opts|
arg = opts[:captures].first
opts[:output].puts arg
opts[:val].clear
end
}
end