diff --git a/test/test.rb b/test/test.rb index a57c1ab1..545fae4a 100644 --- a/test/test.rb +++ b/test/test.rb @@ -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 diff --git a/test/test_helper.rb b/test/test_helper.rb index 1199615b..886975d3 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -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