2018-11-18 01:04:44 -05:00
|
|
|
describe Pry::ColorPrinter do
|
2015-01-13 07:33:07 -05:00
|
|
|
include Pry::Helpers::Text
|
|
|
|
let(:io) { StringIO.new }
|
|
|
|
let(:str) { strip_color(io.string.chomp) }
|
2018-11-18 01:04:44 -05:00
|
|
|
|
2015-01-13 07:33:07 -05:00
|
|
|
describe '.pp' do
|
|
|
|
describe 'Object' do
|
|
|
|
it 'prints a string' do
|
|
|
|
Pry::ColorPrinter.pp(Object.new, io)
|
|
|
|
expect(str).to match(/\A#<Object:0x\w+>\z/)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-11-18 01:04:44 -05:00
|
|
|
describe 'Object subclass' do
|
2015-01-14 06:39:10 -05:00
|
|
|
before do
|
2018-11-18 01:04:44 -05:00
|
|
|
class ObjectF < Object
|
2015-01-14 06:39:10 -05:00
|
|
|
def inspect
|
|
|
|
'foo'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class ObjectG < Object
|
2018-11-18 01:04:44 -05:00
|
|
|
def inspect
|
|
|
|
raise
|
2015-01-14 06:39:10 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-11-18 01:04:44 -05:00
|
|
|
after do
|
2015-01-14 06:39:10 -05:00
|
|
|
Object.send :remove_const, :ObjectF
|
|
|
|
Object.send :remove_const, :ObjectG
|
2018-11-18 01:04:44 -05:00
|
|
|
end
|
2015-01-14 06:39:10 -05:00
|
|
|
|
|
|
|
it 'prints a string' do
|
|
|
|
Pry::ColorPrinter.pp(ObjectF.new, io)
|
|
|
|
expect(str).to eq('foo')
|
2018-11-18 01:04:44 -05:00
|
|
|
end
|
2015-01-14 06:39:10 -05:00
|
|
|
|
2018-11-18 01:04:44 -05:00
|
|
|
it 'prints a string, even when an exception is raised' do
|
2015-01-14 06:39:10 -05:00
|
|
|
Pry::ColorPrinter.pp(ObjectG.new, io)
|
|
|
|
expect(str).to match(/\A#<ObjectG:0x\w+>\z/)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-01-13 07:33:07 -05:00
|
|
|
describe 'BasicObject' do
|
|
|
|
it 'prints a string' do
|
|
|
|
Pry::ColorPrinter.pp(BasicObject.new, io)
|
|
|
|
expect(str).to match(/\A#<BasicObject:0x\w+>\z/)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'BasicObject subclass' do
|
2015-01-13 15:02:08 -05:00
|
|
|
before do
|
|
|
|
class BasicF < BasicObject
|
|
|
|
def inspect
|
|
|
|
'foo'
|
|
|
|
end
|
2015-01-13 07:33:07 -05:00
|
|
|
end
|
2015-01-13 15:02:08 -05:00
|
|
|
|
|
|
|
class BasicG < BasicObject
|
|
|
|
def inspect
|
|
|
|
raise
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
|
|
|
Object.__send__ :remove_const, :BasicF
|
|
|
|
Object.__send__ :remove_const, :BasicG
|
2015-01-13 07:33:07 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'prints a string' do
|
2015-01-13 15:02:08 -05:00
|
|
|
Pry::ColorPrinter.pp(BasicF.new, io)
|
2015-01-13 07:33:07 -05:00
|
|
|
expect(str).to eq("foo")
|
|
|
|
end
|
2015-01-13 15:02:08 -05:00
|
|
|
|
|
|
|
it 'prints a string, even when an exception is raised' do
|
|
|
|
Pry::ColorPrinter.pp(BasicG.new, io)
|
|
|
|
expect(str).to match(/\A#<BasicG:0x\w+>\z/)
|
|
|
|
end
|
2015-01-13 07:33:07 -05:00
|
|
|
end
|
2017-10-22 16:42:44 -04:00
|
|
|
|
|
|
|
describe 'String' do
|
|
|
|
context 'with a single-line string' do
|
|
|
|
it 'pretty prints the string' do
|
|
|
|
Pry::ColorPrinter.pp('hello world', io)
|
|
|
|
expect(str).to eq('"hello world"')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a multi-line string' do
|
|
|
|
it 'pretty prints the string' do
|
|
|
|
Pry::ColorPrinter.pp("hello\nworld", io)
|
|
|
|
expect(str).to eq('"hello\nworld"')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-01-13 07:33:07 -05:00
|
|
|
end
|
|
|
|
end
|