mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
color_printer_spec: add more specs
Some code paths were not covered by unit tests.
This commit is contained in:
parent
d107541951
commit
7ab0d59588
1 changed files with 56 additions and 1 deletions
|
@ -11,7 +11,7 @@ RSpec.describe Pry::ColorPrinter do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it "prints a string" do
|
it "prints a string with a newline" do
|
||||||
described_class.pp(healthy_class.new, output)
|
described_class.pp(healthy_class.new, output)
|
||||||
expect(output.string).to eq("string\n")
|
expect(output.string).to eq("string\n")
|
||||||
end
|
end
|
||||||
|
@ -40,5 +40,60 @@ RSpec.describe Pry::ColorPrinter do
|
||||||
.to match(/\A\e\[32m#<BasicObject:0x.+>\e\[0m\e\[0m\n\z/)
|
.to match(/\A\e\[32m#<BasicObject:0x.+>\e\[0m\e\[0m\n\z/)
|
||||||
end
|
end
|
||||||
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
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue