2010-12-21 09:03:52 -05:00
|
|
|
direc = File.dirname(__FILE__)
|
|
|
|
|
|
|
|
require 'bacon'
|
|
|
|
require "#{direc}/../lib/pry"
|
|
|
|
require "#{direc}/test_helper"
|
|
|
|
|
|
|
|
describe Pry do
|
|
|
|
describe "open a Pry session on an object" do
|
|
|
|
describe "rep" do
|
|
|
|
it 'should set an ivar on an object' do
|
|
|
|
input_string = "@x = 10"
|
|
|
|
input = InputTester.new(input_string)
|
|
|
|
output = OutputTester.new
|
|
|
|
o = Object.new
|
|
|
|
|
|
|
|
pry_tester = Pry.new(input, output)
|
|
|
|
pry_tester.rep(o)
|
|
|
|
o.instance_variable_get(:@x).should == 10
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should make self evaluate to the receiver of the rep session' do
|
|
|
|
output = OutputTester.new
|
|
|
|
o = Object.new
|
|
|
|
|
|
|
|
pry_tester = Pry.new(InputTester.new("self"), output)
|
|
|
|
pry_tester.rep(o)
|
|
|
|
output.output_buffer.should == o
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "repl" do
|
2010-12-24 03:30:51 -05:00
|
|
|
describe "basic functionality" do
|
|
|
|
it 'should set an ivar on an object and exit the repl' do
|
|
|
|
input_strings = ["@x = 10", "exit"]
|
|
|
|
input = InputTester.new(*input_strings)
|
|
|
|
output = OutputTester.new
|
|
|
|
|
|
|
|
o = Object.new
|
|
|
|
|
|
|
|
pry_tester = Pry.new(input, output)
|
|
|
|
pry_tester.repl(o)
|
|
|
|
|
|
|
|
o.instance_variable_get(:@x).should == 10
|
|
|
|
output.session_end_invoked.should == true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "nesting" do
|
|
|
|
it 'should nest properly' do
|
|
|
|
Pry.input = InputTester.new("pry", "pry", "pry", "nesting", "exit", "exit", "exit", "exit")
|
|
|
|
Pry.output = OutputTester.new
|
2010-12-21 09:03:52 -05:00
|
|
|
|
2010-12-24 03:30:51 -05:00
|
|
|
def (Pry.output).show_nesting(level)
|
|
|
|
class << self; attr_reader :nest_output; end
|
|
|
|
@nest_output = level.last.first
|
|
|
|
end
|
|
|
|
|
|
|
|
o = Object.new
|
|
|
|
|
|
|
|
pry_tester = Pry.new
|
|
|
|
pry_tester.repl(o)
|
|
|
|
|
|
|
|
Pry.output.nest_output.should == 3
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "commands" do
|
2010-12-21 09:03:52 -05:00
|
|
|
before do
|
|
|
|
Pry.input = InputTester.new("exit")
|
2010-12-24 03:30:51 -05:00
|
|
|
|
2010-12-21 09:03:52 -05:00
|
|
|
Pry.output = OutputTester.new
|
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
|
|
|
Pry.reset_defaults
|
|
|
|
end
|
2010-12-24 03:30:51 -05:00
|
|
|
|
|
|
|
commands = {
|
|
|
|
"!" => "refresh",
|
2010-12-21 09:03:52 -05:00
|
|
|
"help" => "show_help",
|
|
|
|
"nesting" => "show_nesting",
|
|
|
|
"status" => "show_status",
|
|
|
|
"cat dummy" => "cat",
|
|
|
|
"cd 3" => "cd",
|
|
|
|
"ls" => "ls",
|
|
|
|
"show_method test_method" => "show_method",
|
|
|
|
"show_imethod test_method" => "show_method",
|
|
|
|
"show_doc test_method" => "show_doc",
|
|
|
|
"show_idoc test_method" => "show_doc",
|
|
|
|
"jump_to 0" => "jump_to"
|
2010-12-24 03:30:51 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
commands.each do |command, meth|
|
2010-12-21 09:03:52 -05:00
|
|
|
|
|
|
|
eval %{
|
|
|
|
it "should invoke output##{meth} when #{command} command entered" do
|
|
|
|
input_strings = ["#{command}", "exit"]
|
2010-12-24 03:30:51 -05:00
|
|
|
input = InputTester.new(*input_strings)
|
2010-12-21 09:03:52 -05:00
|
|
|
output = OutputTester.new
|
|
|
|
o = Class.new
|
|
|
|
|
|
|
|
pry_tester = Pry.new(input, output)
|
|
|
|
pry_tester.repl(o)
|
|
|
|
|
|
|
|
output.#{meth}_invoked.should == true
|
|
|
|
output.session_end_invoked.should == true
|
|
|
|
end
|
|
|
|
}
|
2010-12-24 03:30:51 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
commands.each do |command, meth|
|
2010-12-21 09:03:52 -05:00
|
|
|
|
2010-12-24 03:30:51 -05:00
|
|
|
eval %{
|
|
|
|
it "should raise when trying to invoke #{command} command with preceding whitespace" do
|
|
|
|
input_strings = [" #{command}", "exit"]
|
|
|
|
input = InputTester.new(*input_strings)
|
|
|
|
output = OutputTester.new
|
|
|
|
o = Class.new
|
2010-12-21 09:03:52 -05:00
|
|
|
|
2010-12-24 03:30:51 -05:00
|
|
|
pry_tester = Pry.new(input, output)
|
|
|
|
pry_tester.repl(o)
|
2010-12-21 09:03:52 -05:00
|
|
|
|
2010-12-24 03:30:51 -05:00
|
|
|
if "#{command}" != "!"
|
|
|
|
output.output_buffer.is_a?(NameError).should == true
|
|
|
|
else
|
2010-12-21 09:03:52 -05:00
|
|
|
|
2010-12-24 03:30:51 -05:00
|
|
|
# because entering " !" in pry doesnt cause error, it
|
|
|
|
# just creates a wait prompt which the subsquent
|
|
|
|
# "exit" escapes from
|
|
|
|
output.output_buffer.should == ""
|
|
|
|
end
|
|
|
|
end
|
|
|
|
}
|
2010-12-21 09:03:52 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|