spec/unit/yes_no_spec.rb in tty-prompt-0.10.1 vs spec/unit/yes_no_spec.rb in tty-prompt-0.11.0
- old
+ new
@@ -9,48 +9,44 @@
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[1000D\e[K\e[1A",
- "\e[1000D\e[K",
+ "\e[1A\e[2K\e[1G",
"Are you a human? \e[32mYes\e[0m\n"
].join)
end
it 'disagrees with question' do
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[1000D\e[K\e[1A",
- "\e[1000D\e[K",
+ "\e[1A\e[2K\e[1G",
"Are you a human? \e[32mno\e[0m\n"
].join)
end
it 'assumes default true' do
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[1000D\e[K\e[1A",
- "\e[1000D\e[K",
+ "\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 ",
- "\e[1000D\e[K\e[1A",
- "\e[1000D\e[K",
+ "\e[1A\e[2K\e[1G",
"Are you a human? \e[32mno\e[0m\n"
].join)
end
it "defaults suffix and converter" do
@@ -61,12 +57,11 @@
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[1000D\e[K\e[1A",
- "\e[1000D\e[K",
+ "\e[1A\e[2K\e[1G",
"Are you a human? \e[32mnope\e[0m\n"
].join)
end
it "defaults positive and negative" do
@@ -76,12 +71,11 @@
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[1000D\e[K\e[1A",
- "\e[1000D\e[K",
+ "\e[1A\e[2K\e[1G",
"Are you a human? \e[32mnope\e[0m\n"
].join)
end
it "customizes question through options" do
@@ -90,12 +84,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[1000D\e[K\e[1A",
- "\e[1000D\e[K",
+ "\e[1A\e[2K\e[1G",
"Are you a human? \e[32mAgree\e[0m\n"
].join)
end
it "customizes question through DSL" do
@@ -109,12 +102,11 @@
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[1000D\e[K\e[1A",
- "\e[1000D\e[K",
+ "\e[1A\e[2K\e[1G",
"Are you a human? \e[32mDisagree\e[0m\n"
].join)
end
end
@@ -123,48 +115,44 @@
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[1000D\e[K\e[1A",
- "\e[1000D\e[K",
+ "\e[1A\e[2K\e[1G",
"Are you a human? \e[32mNo\e[0m\n"
].join)
end
it 'disagrees with question' do
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[1000D\e[K\e[1A",
- "\e[1000D\e[K",
+ "\e[1A\e[2K\e[1G",
"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[1000D\e[K\e[1A",
- "\e[1000D\e[K",
+ "\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 ",
- "\e[1000D\e[K\e[1A",
- "\e[1000D\e[K",
+ "\e[1A\e[2K\e[1G",
"Are you a human? \e[32mYes\e[0m\n"
].join)
end
it "defaults suffix and converter" do
@@ -175,12 +163,11 @@
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[1000D\e[K\e[1A",
- "\e[1000D\e[K",
+ "\e[1A\e[2K\e[1G",
"Are you a human? \e[32myup\e[0m\n"
].join)
end
it "customizes question through DSL" do
@@ -194,11 +181,10 @@
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[1000D\e[K\e[1A",
- "\e[1000D\e[K",
+ "\e[1A\e[2K\e[1G",
"Are you a human? \e[32mAgree\e[0m\n"
].join)
end
end
end