spec/unit/select_spec.rb in tty-prompt-0.18.0 vs spec/unit/select_spec.rb in tty-prompt-0.18.1

- old
+ new

@@ -41,23 +41,26 @@ # Ensure a wide prompt on CI before { allow(TTY::Screen).to receive(:width).and_return(200) } it "selects by default first option" do - choices = %w(Large Medium Small) + choices = %i(Large Medium Small) prompt.input << "\r" prompt.input.rewind - expect(prompt.select('What size?', choices)).to eq('Large') - expect(prompt.output.string).to eq([ + + expect(prompt.select('What size?', choices)).to eq(:Large) + expected_output = [ "\e[?25lWhat size? \e[90m(Use arrow keys, press Enter to select)\e[0m\n", "\e[32m#{symbols[:pointer]} Large\e[0m\n", " Medium\n", " Small", "\e[2K\e[1G\e[1A" * 3, "\e[2K\e[1G", "What size? \e[32mLarge\e[0m\n\e[?25h" - ].join) + ].join + + expect(prompt.output.string).to eq(expected_output) end it "allows navigation using events without errors" do choices = %w(Large Medium Small) prompt.input << "j" << "\r" @@ -627,17 +630,31 @@ "What size? \e[32mSmall\e[0m\n\e[?25h" expect(prompt.output.string).to eq(expected_output) end - it "sets default correct when disabled choice" do - choices = [ {name: 'Small', disabled: '(out of stock)'}, 'Medium', 'Large', 'Huge' ] + it "sets active to be first non-disabled choice" do + choices = [ + {name: 'Small', disabled: '(out of stock)'}, 'Medium', 'Large', 'Huge' + ] prompt = TTY::TestPrompt.new prompt.input << "\r" prompt.input.rewind + answer = prompt.select("What size?", choices) + expect(answer).to eq('Medium') + end + + it "prevents setting default to disabled choice" do + choices = [ + {name: 'Small', disabled: '(out of stock)'}, 'Medium', 'Large', 'Huge' + ] + prompt = TTY::TestPrompt.new + prompt.input << "\r" + prompt.input.rewind + expect { - prompt.select("What size?", choices) + prompt.select("What size?", choices, default: 1) }.to raise_error(TTY::Prompt::ConfigurationError, /default index `1` matches disabled choice item/) end end end