2011-09-02 06:25:18 -04:00
|
|
|
require 'helper'
|
|
|
|
|
|
|
|
describe "Pry::DefaultCommands::Shell" do
|
|
|
|
describe "cat" do
|
|
|
|
|
2011-09-14 07:35:08 -04:00
|
|
|
describe "on receiving a file that does not exist" do
|
|
|
|
it 'should display an error message' do
|
|
|
|
mock_pry("cat supercalifragilicious66").should =~ /Could not find file/
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-09-02 06:25:18 -04:00
|
|
|
# this doesnt work so well on rbx due to differences in backtrace
|
|
|
|
# so we currently skip rbx until we figure out a workaround
|
2011-09-13 13:40:30 -04:00
|
|
|
describe "with --ex" do
|
|
|
|
if !rbx?
|
|
|
|
it 'cat --ex should correctly display code that generated exception even if raised in repl' do
|
|
|
|
mock_pry("this raises error", "cat --ex").should =~ /\d+:(\s*) this raises error/
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'cat --ex should correctly display code that generated exception' do
|
|
|
|
mock_pry("broken_method", "cat --ex").should =~ /this method is broken/
|
|
|
|
end
|
2011-09-02 06:25:18 -04:00
|
|
|
end
|
2011-09-13 13:40:30 -04:00
|
|
|
end
|
2011-09-02 06:25:18 -04:00
|
|
|
|
2011-09-13 13:40:30 -04:00
|
|
|
describe "with --ex N" do
|
|
|
|
it 'should cat first level of backtrace when --ex used with no argument ' do
|
|
|
|
pry_instance = Pry.new(:input => StringIO.new("cat --ex"), :output => str_output = StringIO.new)
|
2011-09-13 23:03:24 -04:00
|
|
|
|
|
|
|
temp_file do |f|
|
2011-09-13 13:40:30 -04:00
|
|
|
f << "bt number 1"
|
2011-09-13 23:03:24 -04:00
|
|
|
f.flush
|
|
|
|
pry_instance.last_exception = MockPryException.new("#{f.path}:1", "x", "x")
|
|
|
|
pry_instance.rep(self)
|
2011-09-13 13:40:30 -04:00
|
|
|
end
|
2011-09-13 23:03:24 -04:00
|
|
|
|
2011-09-13 13:40:30 -04:00
|
|
|
str_output.string.should =~ /bt number 1/
|
2011-09-02 06:25:18 -04:00
|
|
|
end
|
2011-09-13 13:40:30 -04:00
|
|
|
|
|
|
|
it 'should cat first level of backtrace when --ex 0 used ' do
|
|
|
|
pry_instance = Pry.new(:input => StringIO.new("cat --ex 0"), :output => str_output = StringIO.new)
|
2011-09-13 23:03:24 -04:00
|
|
|
|
|
|
|
temp_file do |f|
|
2011-09-13 13:40:30 -04:00
|
|
|
f << "bt number 1"
|
2011-09-13 23:03:24 -04:00
|
|
|
f.flush
|
|
|
|
pry_instance.last_exception = MockPryException.new("#{f.path}:1", "x", "x")
|
|
|
|
pry_instance.rep(self)
|
2011-09-13 13:40:30 -04:00
|
|
|
end
|
2011-09-13 23:03:24 -04:00
|
|
|
|
2011-09-13 13:40:30 -04:00
|
|
|
str_output.string.should =~ /bt number 1/
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should cat second level of backtrace when --ex 1 used ' do
|
|
|
|
pry_instance = Pry.new(:input => StringIO.new("cat --ex 1"), :output => str_output = StringIO.new)
|
2011-09-13 23:03:24 -04:00
|
|
|
|
|
|
|
temp_file do |f|
|
2011-09-13 13:40:30 -04:00
|
|
|
f << "bt number 2"
|
2011-09-13 23:03:24 -04:00
|
|
|
f.flush
|
|
|
|
pry_instance.last_exception = MockPryException.new("x", "#{f.path}:1", "x")
|
|
|
|
pry_instance.rep(self)
|
2011-09-13 13:40:30 -04:00
|
|
|
end
|
2011-09-13 23:03:24 -04:00
|
|
|
|
2011-09-13 13:40:30 -04:00
|
|
|
str_output.string.should =~ /bt number 2/
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should cat third level of backtrace when --ex 2 used ' do
|
|
|
|
pry_instance = Pry.new(:input => StringIO.new("cat --ex 2"), :output => str_output = StringIO.new)
|
2011-09-13 23:03:24 -04:00
|
|
|
|
|
|
|
temp_file do |f|
|
2011-09-13 13:40:30 -04:00
|
|
|
f << "bt number 3"
|
2011-09-13 23:03:24 -04:00
|
|
|
f.flush
|
|
|
|
pry_instance.last_exception = MockPryException.new("x", "x", "#{f.path}:1")
|
|
|
|
pry_instance.rep(self)
|
2011-09-13 13:40:30 -04:00
|
|
|
end
|
2011-09-13 23:03:24 -04:00
|
|
|
|
2011-09-13 13:40:30 -04:00
|
|
|
str_output.string.should =~ /bt number 3/
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should show error when backtrace level out of bounds ' do
|
|
|
|
pry_instance = Pry.new(:input => StringIO.new("cat --ex 3"), :output => str_output = StringIO.new)
|
|
|
|
pry_instance.last_exception = MockPryException.new("x", "x", "x")
|
|
|
|
pry_instance.rep(self)
|
|
|
|
str_output.string.should =~ /No Exception or Exception has no associated file/
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'each successive cat --ex should show the next level of backtrace, and going past the final level should return to the first' do
|
2011-09-13 23:03:24 -04:00
|
|
|
temp_files = []
|
|
|
|
3.times do |i|
|
|
|
|
temp_files << Tempfile.new(['tmp', '*.rb'])
|
|
|
|
temp_files.last << "bt number #{i}"
|
|
|
|
temp_files.last.flush
|
|
|
|
end
|
2011-09-13 13:40:30 -04:00
|
|
|
|
2011-09-13 23:03:24 -04:00
|
|
|
pry_instance = Pry.new(:input => StringIO.new("cat --ex\n" * 4),
|
|
|
|
:output => (str_output = StringIO.new))
|
2011-09-13 13:40:30 -04:00
|
|
|
|
2011-09-13 23:03:24 -04:00
|
|
|
pry_instance.last_exception = MockPryException.new(*temp_files.map { |f| "#{f.path}:1" })
|
2011-09-13 13:40:30 -04:00
|
|
|
|
2011-09-13 23:03:24 -04:00
|
|
|
3.times do |i|
|
2011-09-13 13:40:30 -04:00
|
|
|
pry_instance.rep(self)
|
2011-09-13 23:03:24 -04:00
|
|
|
str_output.string.should =~ /bt number #{i}/
|
2011-09-13 13:40:30 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
str_output.reopen
|
|
|
|
pry_instance.rep(self)
|
|
|
|
str_output.string.should =~ /bt number 0/
|
2011-09-13 23:03:24 -04:00
|
|
|
|
|
|
|
temp_files.each(&:close)
|
2011-09-13 13:40:30 -04:00
|
|
|
end
|
|
|
|
|
2011-09-02 06:25:18 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|