Skip to content

Commit

Permalink
Change to fix prompt inspect to format all public attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrmurach committed Jul 2, 2020
1 parent 80a4961 commit 542cdac
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 11 deletions.
25 changes: 14 additions & 11 deletions lib/tty/prompt.rb
Expand Up @@ -581,21 +581,24 @@ def stderr
$stderr
end

# Inspect class name and public attributes
# Inspect this instance public attributes
#
# @return [String]
#
# @api public
def inspect
attributes = {
input: input,
output: output,
prefix: prefix,
active_color: active_color,
error_color: error_color,
enabled_color: enabled_color,
help_color: help_color
}
"#<#{self.class}: #{attributes.each { |name, val| "@#{name}=#{val}" }}"
attributes = [
:prefix,
:quiet,
:enabled_color,
:active_color,
:error_color,
:help_color,
:input,
:output,
]
name = self.class.name
"#<#{name}#{attributes.map { |attr| " #{attr}=#{send(attr).inspect}" }.join}>"
end
end # Prompt
end # TTY
19 changes: 19 additions & 0 deletions spec/unit/inspect_spec.rb
@@ -0,0 +1,19 @@
# frozen_string_literal: true

RSpec.describe TTY::Prompt, "#inspect" do
it "inspects instance attributes" do
prompt = TTY::TestPrompt.new

expect(prompt.inspect).to eq([
"#<TTY::TestPrompt",
"prefix=\"\"",
"quiet=false",
"enabled_color=true",
"active_color=:green",
"error_color=:red",
"help_color=:bright_black",
"input=#{prompt.input}",
"output=#{prompt.output}>",
].join(" "))
end
end

0 comments on commit 542cdac

Please sign in to comment.