2011-09-21 10:15:53 -04:00
|
|
|
require 'helper'
|
2011-08-23 03:54:58 -04:00
|
|
|
|
|
|
|
describe Pry do
|
|
|
|
describe "output failsafe" do
|
|
|
|
after do
|
|
|
|
Pry.config.print = Pry::DEFAULT_PRINT
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should catch serialization exceptions" do
|
|
|
|
Pry.config.print = lambda { |*a| raise "catch-22" }
|
|
|
|
|
|
|
|
lambda {
|
|
|
|
mock_pry("1")
|
|
|
|
}.should.not.raise
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should display serialization exceptions" do
|
|
|
|
Pry.config.print = lambda { |*a| raise "catch-22" }
|
|
|
|
|
2011-09-14 18:48:20 -04:00
|
|
|
mock_pry("1").should =~ /\(pry\) output error: #<RuntimeError: catch-22>/
|
2011-08-23 03:54:58 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should catch errors serializing exceptions" do
|
|
|
|
Pry.config.print = lambda do |*a|
|
|
|
|
raise Exception.new("catch-22").tap{ |e| class << e; def inspect; raise e; end; end }
|
|
|
|
end
|
|
|
|
|
2011-09-14 18:48:20 -04:00
|
|
|
mock_pry("1").should =~ /\(pry\) output error: failed to show result/
|
2011-08-23 03:54:58 -04:00
|
|
|
end
|
|
|
|
end
|
2011-08-24 04:07:52 -04:00
|
|
|
|
|
|
|
describe "DEFAULT_PRINT" do
|
|
|
|
it "should output the right thing" do
|
2012-11-18 04:42:22 -05:00
|
|
|
mock_pry("[1]").should =~ /^=> \[1\]/
|
2012-10-15 04:20:18 -04:00
|
|
|
end
|
|
|
|
|
2012-11-08 02:58:18 -05:00
|
|
|
it "should not include the =>" do
|
|
|
|
accumulator = StringIO.new
|
2012-11-18 04:42:22 -05:00
|
|
|
Pry.config.print.call(accumulator, [1])
|
|
|
|
accumulator.string.should == "\[1\]\n"
|
2011-08-24 04:07:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should not be phased by un-inspectable things" do
|
2011-09-21 10:51:14 -04:00
|
|
|
mock_pry("class NastyClass; undef pretty_inspect; end", "NastyClass.new").should =~ /#<NastyClass:0x.*?>/
|
2011-08-24 04:07:52 -04:00
|
|
|
end
|
|
|
|
end
|
2012-10-21 01:54:58 -04:00
|
|
|
|
2012-11-28 18:21:14 -05:00
|
|
|
describe "color" do
|
|
|
|
before do
|
|
|
|
Pry.color = true
|
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
|
|
|
Pry.color = false
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should colorize strings as though they were ruby" do
|
|
|
|
accumulator = StringIO.new
|
|
|
|
Pry.config.print.call(accumulator, [1])
|
|
|
|
accumulator.string.should == "[\e[1;34m1\e[0m]\e[0m\n"
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should not colorize strings that already include color" do
|
|
|
|
f = Object.new
|
|
|
|
def f.inspect
|
|
|
|
"\e[1;31mFoo\e[0m"
|
|
|
|
end
|
|
|
|
accumulator = StringIO.new
|
|
|
|
Pry.config.print.call(accumulator, f)
|
|
|
|
# We add an extra \e[0m to prevent color leak
|
|
|
|
accumulator.string.should == "\e[1;31mFoo\e[0m\e[0m\n"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-10-21 01:54:58 -04:00
|
|
|
describe "output suppression" do
|
|
|
|
before do
|
|
|
|
@t = pry_tester
|
|
|
|
end
|
|
|
|
it "should normally output the result" do
|
|
|
|
mock_pry("1 + 2").should == "=> 3\n\n"
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should not output anything if the input ends with a semicolon" do
|
|
|
|
mock_pry("1 + 2;").should == "\n"
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should output something if the input ends with a comment" do
|
|
|
|
mock_pry("1 + 2 # basic addition").should == "=> 3\n\n"
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should not output something if the input is only a comment" do
|
|
|
|
mock_pry("# basic addition").should == "\n"
|
|
|
|
end
|
|
|
|
end
|
2011-08-23 03:54:58 -04:00
|
|
|
end
|