spec/unit/yes_no_spec.rb in tty-prompt-0.11.0 vs spec/unit/yes_no_spec.rb in tty-prompt-0.12.0
- old
+ new
@@ -9,10 +9,13 @@
prompt.input << 'yes'
prompt.input.rewind
expect(prompt.yes?("Are you a human?")).to eq(true)
expect(prompt.output.string).to eq([
"Are you a human? \e[90m(Y/n)\e[0m ",
+ "\e[2K\e[1GAre you a human? \e[90m(Y/n)\e[0m y",
+ "\e[2K\e[1GAre you a human? \e[90m(Y/n)\e[0m ye",
+ "\e[2K\e[1GAre you a human? \e[90m(Y/n)\e[0m yes",
"\e[1A\e[2K\e[1G",
"Are you a human? \e[32mYes\e[0m\n"
].join)
end
@@ -20,10 +23,12 @@
prompt.input << 'no'
prompt.input.rewind
expect(prompt.yes?("Are you a human?")).to eq(false)
expect(prompt.output.string).to eq([
"Are you a human? \e[90m(Y/n)\e[0m ",
+ "\e[2K\e[1GAre you a human? \e[90m(Y/n)\e[0m n",
+ "\e[2K\e[1GAre you a human? \e[90m(Y/n)\e[0m no",
"\e[1A\e[2K\e[1G",
"Are you a human? \e[32mno\e[0m\n"
].join)
end
@@ -31,23 +36,25 @@
prompt.input << "\r"
prompt.input.rewind
expect(prompt.yes?("Are you a human?")).to eq(true)
expect(prompt.output.string).to eq([
"Are you a human? \e[90m(Y/n)\e[0m ",
+ "\e[2K\e[1GAre you a human? \e[90m(Y/n)\e[0m \n",
"\e[1A\e[2K\e[1G",
"Are you a human? \e[32mYes\e[0m\n"
].join)
end
it 'changes default' do
prompt.input << "\n"
prompt.input.rewind
expect(prompt.yes?("Are you a human?", default: false)).to eq(false)
expect(prompt.output.string).to eq([
- "Are you a human? \e[90m(Y/n)\e[0m ",
+ "Are you a human? \e[90m(y/N)\e[0m ",
+ "\e[2K\e[1GAre you a human? \e[90m(y/N)\e[0m \n",
"\e[1A\e[2K\e[1G",
- "Are you a human? \e[32mno\e[0m\n"
+ "Are you a human? \e[32mNo\e[0m\n"
].join)
end
it "defaults suffix and converter" do
prompt.input << "Nope\n"
@@ -57,10 +64,15 @@
q.negative 'nope'
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"
].join)
end
@@ -71,10 +83,15 @@
q.suffix 'Yup/nope'
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"
].join)
end
@@ -84,10 +101,11 @@
result = prompt.yes?("Are you a human?", suffix: 'Agree/Disagree',
positive: 'Agree', negative: 'Disagree')
expect(result).to eq(true)
expect(prompt.output.string).to eq([
"Are you a human? \e[90m(Agree/Disagree)\e[0m ",
+ "\e[2K\e[1GAre you a human? \e[90m(Agree/Disagree)\e[0m \n",
"\e[1A\e[2K\e[1G",
"Are you a human? \e[32mAgree\e[0m\n"
].join)
end
@@ -102,10 +120,19 @@
q.convert conversion
end
expect(result).to eq(false)
expect(prompt.output.string).to eq([
"Are you a human? \e[90m(Agree/Disagree)\e[0m ",
+ "\e[2K\e[1GAre you a human? \e[90m(Agree/Disagree)\e[0m d",
+ "\e[2K\e[1GAre you a human? \e[90m(Agree/Disagree)\e[0m di",
+ "\e[2K\e[1GAre you a human? \e[90m(Agree/Disagree)\e[0m dis",
+ "\e[2K\e[1GAre you a human? \e[90m(Agree/Disagree)\e[0m disa",
+ "\e[2K\e[1GAre you a human? \e[90m(Agree/Disagree)\e[0m disag",
+ "\e[2K\e[1GAre you a human? \e[90m(Agree/Disagree)\e[0m disagr",
+ "\e[2K\e[1GAre you a human? \e[90m(Agree/Disagree)\e[0m disagre",
+ "\e[2K\e[1GAre you a human? \e[90m(Agree/Disagree)\e[0m disagree",
+ "\e[2K\e[1GAre you a human? \e[90m(Agree/Disagree)\e[0m disagree\n",
"\e[1A\e[2K\e[1G",
"Are you a human? \e[32mDisagree\e[0m\n"
].join)
end
end
@@ -115,10 +142,12 @@
prompt.input << 'no'
prompt.input.rewind
expect(prompt.no?("Are you a human?")).to eq(true)
expect(prompt.output.string).to eq([
"Are you a human? \e[90m(y/N)\e[0m ",
+ "\e[2K\e[1GAre you a human? \e[90m(y/N)\e[0m n",
+ "\e[2K\e[1GAre you a human? \e[90m(y/N)\e[0m no",
"\e[1A\e[2K\e[1G",
"Are you a human? \e[32mNo\e[0m\n"
].join)
end
@@ -126,32 +155,37 @@
prompt.input << 'yes'
prompt.input.rewind
expect(prompt.no?("Are you a human?")).to eq(false)
expect(prompt.output.string).to eq([
"Are you a human? \e[90m(y/N)\e[0m ",
+ "\e[2K\e[1GAre you a human? \e[90m(y/N)\e[0m y",
+ "\e[2K\e[1GAre you a human? \e[90m(y/N)\e[0m ye",
+ "\e[2K\e[1GAre you a human? \e[90m(y/N)\e[0m yes",
"\e[1A\e[2K\e[1G",
- "Are you a human? \e[32mYes\e[0m\n"
+ "Are you a human? \e[32myes\e[0m\n"
].join)
end
it 'assumes default false' do
prompt.input << "\r"
prompt.input.rewind
expect(prompt.no?("Are you a human?")).to eq(true)
expect(prompt.output.string).to eq([
"Are you a human? \e[90m(y/N)\e[0m ",
+ "\e[2K\e[1GAre you a human? \e[90m(y/N)\e[0m \n",
"\e[1A\e[2K\e[1G",
"Are you a human? \e[32mNo\e[0m\n"
].join)
end
it 'changes default' do
prompt.input << "\r"
prompt.input.rewind
expect(prompt.no?("Are you a human?", default: true)).to eq(false)
expect(prompt.output.string).to eq([
- "Are you a human? \e[90m(y/N)\e[0m ",
+ "Are you a human? \e[90m(Y/n)\e[0m ",
+ "\e[2K\e[1GAre you a human? \e[90m(Y/n)\e[0m \n",
"\e[1A\e[2K\e[1G",
"Are you a human? \e[32mYes\e[0m\n"
].join)
end
@@ -163,10 +197,14 @@
q.negative 'Nope'
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 Y",
+ "\e[2K\e[1GAre you a human? \e[90m(yup/Nope)\e[0m Yu",
+ "\e[2K\e[1GAre you a human? \e[90m(yup/Nope)\e[0m Yup",
+ "\e[2K\e[1GAre you a human? \e[90m(yup/Nope)\e[0m Yup\n",
"\e[1A\e[2K\e[1G",
"Are you a human? \e[32myup\e[0m\n"
].join)
end
@@ -181,9 +219,15 @@
q.convert conversion
end
expect(result).to eq(false)
expect(prompt.output.string).to eq([
"Are you a human? \e[90m(Agree/Disagree)\e[0m ",
+ "\e[2K\e[1GAre you a human? \e[90m(Agree/Disagree)\e[0m a",
+ "\e[2K\e[1GAre you a human? \e[90m(Agree/Disagree)\e[0m ag",
+ "\e[2K\e[1GAre you a human? \e[90m(Agree/Disagree)\e[0m agr",
+ "\e[2K\e[1GAre you a human? \e[90m(Agree/Disagree)\e[0m agre",
+ "\e[2K\e[1GAre you a human? \e[90m(Agree/Disagree)\e[0m agree",
+ "\e[2K\e[1GAre you a human? \e[90m(Agree/Disagree)\e[0m agree\n",
"\e[1A\e[2K\e[1G",
"Are you a human? \e[32mAgree\e[0m\n"
].join)
end
end