summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyrylo Silin <silin@kyrylo.org>2019-03-30 01:55:03 +0200
committerKyrylo Silin <silin@kyrylo.org>2019-03-30 01:55:03 +0200
commit7ab0d59588c1214da70ff868d0687ec11c21cfe0 (patch)
treeda6b3cf196213d18f5cca73754cc95997dbf438f
parentd1075419519ea6cea077394c8ddd474b4f4f7c56 (diff)
downloadpry-7ab0d59588c1214da70ff868d0687ec11c21cfe0.tar.gz
color_printer_spec: add more specs
Some code paths were not covered by unit tests.
-rw-r--r--spec/color_printer_spec.rb57
1 files changed, 56 insertions, 1 deletions
diff --git a/spec/color_printer_spec.rb b/spec/color_printer_spec.rb
index 6c2e72cb..13b2acf6 100644
--- a/spec/color_printer_spec.rb
+++ b/spec/color_printer_spec.rb
@@ -11,7 +11,7 @@ RSpec.describe Pry::ColorPrinter do
end
end
- it "prints a string" do
+ it "prints a string with a newline" do
described_class.pp(healthy_class.new, output)
expect(output.string).to eq("string\n")
end
@@ -40,5 +40,60 @@ RSpec.describe Pry::ColorPrinter do
.to match(/\A\e\[32m#<BasicObject:0x.+>\e\[0m\e\[0m\n\z/)
end
end
+
+ context "when #inspect returns an object literal" do
+ let(:klass) do
+ Class.new do
+ def inspect
+ '#<Object:0x00007fe86bab53c8>'
+ end
+ end
+ end
+
+ it "prints the object inspect" do
+ described_class.pp(klass.new, output)
+ expect(output.string).to eq("\e[32m#<Object:0x00007fe86bab53c8>\e[0m\n")
+ end
+
+ context "and when SyntaxHighlighter returns a token starting with '\e'" do
+ before do
+ expect(Pry::SyntaxHighlighter).to receive(:keyword_token_color)
+ .and_return("\e[32m")
+ end
+
+ it "prints the object as is" do
+ described_class.pp(klass.new, output)
+ expect(output.string).to eq("\e[32m#<Object:0x00007fe86bab53c8>\e[0m\n")
+ end
+ end
+
+ context "and when SyntaxHighlighter returns a token that doesn't start with '\e'" do
+ before do
+ expect(Pry::SyntaxHighlighter).to receive(:keyword_token_color)
+ .and_return('token')
+ end
+
+ it "prints the object with escape characters" do
+ described_class.pp(klass.new, output)
+ expect(output.string)
+ .to eq("\e[0m\e[0;tokenm#<Object:0x00007fe86bab53c8>\e[0m\n")
+ end
+ end
+ end
+
+ context "when #inspect raises Pry::Pager::StopPaging" do
+ let(:klass) do
+ Class.new do
+ def inspect
+ raise Pry::Pager::StopPaging
+ end
+ end
+ end
+
+ it "propagates the error" do
+ expect { described_class.pp(klass.new, output) }
+ .to raise_error(Pry::Pager::StopPaging)
+ end
+ end
end
end