1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00

Issue #1647: Fix String#pp output color

This commit fixes #1647 and pretty prints strings in red instead of
green. This bug was introduced in https://github.com/pry/pry/pull/1586.
It will also continue to pretty print multi-line strings without a '+'
delimiter, per the same pull request.
This commit is contained in:
Richard E. Dodson 2017-10-22 15:42:44 -05:00
parent 1f32f89ae6
commit ba6903e0b1
No known key found for this signature in database
GPG key ID: C59F7099F016BFF8
2 changed files with 17 additions and 3 deletions

View file

@ -32,9 +32,7 @@ class Pry
def pp(obj)
if String === obj
# Avoid calling Ruby 2.4+ String#pretty_print that prints multiline
# Strings prettier
Object.instance_method(:pretty_print).bind(obj).call
text(obj.inspect)
else
super
end

View file

@ -80,5 +80,21 @@ describe Pry::ColorPrinter do
expect(str).to match(/\A#<BasicG:0x\w+>\z/)
end
end
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
end
end