Skip to content

Commit

Permalink
WIP - fixed the problem. trying to decipher why spec is failing
Browse files Browse the repository at this point in the history
  • Loading branch information
rpbaltazar committed Oct 31, 2018
1 parent 6fd9bf4 commit 68c7538
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
5 changes: 4 additions & 1 deletion lib/tty/prompt/confirm_question.rb
Expand Up @@ -121,7 +121,10 @@ def create_suffix
#
# @api private
def conversion
proc { |input| !input.match(/^#{positive}|#{positive[0]}$/i).nil? }
proc { |input|
regex = Regexp.new(Regexp.escape("^#{positive}|#{positive[0]}$/i"))
!input.match(regex).nil?
}
end
end # ConfirmQuestion
end # Prompt
Expand Down
18 changes: 7 additions & 11 deletions spec/unit/yes_no_spec.rb
Expand Up @@ -136,22 +136,18 @@
].join)
end

it "accepts any character as suffix" do
prompt.input << "[\n"
it "accepts regex conflicting characters as suffix" do
prompt.input << "]\n"
prompt.input.rewind
result = prompt.yes?("Are you human? Use [ for yes and ] for no") do |q|
result = prompt.yes?("Are you a human? Use [ for yes and ] for no") do |q|
q.suffix '[/]'
end
expect(result).to eq(false)
expect(prompt.output.string).to eq([
"Are you a human? \e[90m(Yup/nope)\e[0m ",
"\e[2K\e[1GAre you a human? \e[90m(Yup/nope)\e[0m N",
"\e[2K\e[1GAre you a human? \e[90m(Yup/nope)\e[0m No",
"\e[2K\e[1GAre you a human? \e[90m(Yup/nope)\e[0m Nop",
"\e[2K\e[1GAre you a human? \e[90m(Yup/nope)\e[0m Nope",
"\e[2K\e[1GAre you a human? \e[90m(Yup/nope)\e[0m Nope\n",
"\e[1A\e[2K\e[1G",
"Are you a human? \e[32mnope\e[0m\n"
"Are you a human? Use [ for yes and ] for no \e[90m([/])\e[0m ",
"\e[2K\e[1GAre you a human? Use [ for yes and ] for no \e[90m([/])\e[0m [",
"\e[2K\e[1GAre you a human? Use [ for yes and ] for no \e[90m([/])\e[0m [\n",
"Are you a human? Use [ for yes and ] for no \e[32m[\e[0m\n"
].join)
end
end
Expand Down

0 comments on commit 68c7538

Please sign in to comment.