summaryrefslogtreecommitdiff
path: root/spec/unit/knife
diff options
context:
space:
mode:
authorEric Sigler <me@esigler.com>2014-02-19 22:47:35 -0800
committersersut <serdar@opscode.com>2014-03-19 17:41:55 -0700
commit3328f4749faea190b4d5c17302aa83a6591f6305 (patch)
tree8d2208dbc911a5261361d2de7af2b67e3827438e /spec/unit/knife
parentdcfc7270c1960541ffd11eb81eb2d81d5d1f3eab (diff)
downloadchef-3328f4749faea190b4d5c17302aa83a6591f6305.tar.gz
[CHEF-5057] Add default choice option to confirm prompt
This commit allows a default choice to be provided for a ui.confirm prompt. "-y" flag still takes precedence, and the "default" for the default is the previous behavior ("Y/N", no default choice). Testing done: bundle exec rake spec - passes bundle exec rspec spec/unit/knife/core - passes
Diffstat (limited to 'spec/unit/knife')
-rw-r--r--spec/unit/knife/core/ui_spec.rb39
1 files changed, 32 insertions, 7 deletions
diff --git a/spec/unit/knife/core/ui_spec.rb b/spec/unit/knife/core/ui_spec.rb
index f9c1ac9fd0..74b3906067 100644
--- a/spec/unit/knife/core/ui_spec.rb
+++ b/spec/unit/knife/core/ui_spec.rb
@@ -437,13 +437,38 @@ EOM
}.should raise_error(SystemExit) { |e| e.status.should == 3 }
end
- it "should not exit 3 if you answer n and return false if asked for it" do
- @ui.stdin.stub(:readline).and_return("n")
- value = nil
- lambda {
- value = @ui.confirm(@question,true,false)
- }.should_not raise_error(SystemExit)
- value.should be(false)
+ describe "with 'Y' as a default choice" do
+ it 'should return true if you answer default' do
+ @ui.stdin.stub(:readline).and_return("\n")
+ @ui.confirm(@question, false, 'Y').should == true
+ end
+
+ it "should show 'Y' as the default in the instructions" do
+ out = StringIO.new
+ @ui.stdin.stub(:readline).and_return("\n")
+ @ui.stub(:stdout).and_return(out)
+ @ui.confirm(@question, true, 'Y').should == true
+ out.string.should == "#{@question}? (Y/n)"
+ end
+ end
+
+ describe "with 'N' as a default choice" do
+ it 'should exit 3 if you answer default' do
+ @ui.stdin.stub(:readline).and_return("\n")
+ lambda {
+ @ui.confirm(@question, false, 'N')
+ }.should raise_error(SystemExit) { |e| e.status.should == 3 }
+ end
+
+ it "should show 'N' as the default in the instructions" do
+ out = StringIO.new
+ @ui.stdin.stub(:readline).and_return("\n")
+ @ui.stub(:stdout).and_return(out)
+ lambda {
+ @ui.confirm(@question, true, 'N')
+ }.should raise_error(SystemExit) { |e| e.status.should == 3 }
+ out.string.should == "#{@question}? (y/N)You said no, so I'm done here.\n"
+ end
end
describe "with --y or --yes passed" do