From ba6903e0b1afc9e6a80462c40d66c6a07012b606 Mon Sep 17 00:00:00 2001 From: "Richard E. Dodson" Date: Sun, 22 Oct 2017 15:42:44 -0500 Subject: [PATCH] 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. --- lib/pry/color_printer.rb | 4 +--- spec/color_printer_spec.rb | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/pry/color_printer.rb b/lib/pry/color_printer.rb index 51f3a2a4..150e6a1f 100644 --- a/lib/pry/color_printer.rb +++ b/lib/pry/color_printer.rb @@ -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 diff --git a/spec/color_printer_spec.rb b/spec/color_printer_spec.rb index 78fa6f2f..0b1479f8 100644 --- a/spec/color_printer_spec.rb +++ b/spec/color_printer_spec.rb @@ -80,5 +80,21 @@ describe Pry::ColorPrinter do expect(str).to match(/\A#\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