diff options
Diffstat (limited to 'spec/unit')
-rwxr-xr-x | spec/unit/application/face_base_spec.rb | 37 | ||||
-rwxr-xr-x | spec/unit/interface/action_builder_spec.rb | 11 | ||||
-rwxr-xr-x | spec/unit/interface/action_manager_spec.rb | 18 |
3 files changed, 63 insertions, 3 deletions
diff --git a/spec/unit/application/face_base_spec.rb b/spec/unit/application/face_base_spec.rb index 939712ef8..eaf60b434 100755 --- a/spec/unit/application/face_base_spec.rb +++ b/spec/unit/application/face_base_spec.rb @@ -70,9 +70,33 @@ describe Puppet::Application::FaceBase do end end - it "should fail if no action is given" do - expect { app.preinit; app.parse_options }. - to raise_error OptionParser::MissingArgument, /No action given/ + it "should use the default action if not given any arguments" do + app.command_line.stubs(:args).returns [] + action = stub(:options => []) + Puppet::Face[:basetest, '0.0.1'].expects(:get_default_action).returns(action) + app.stubs(:main) + app.run + app.action.should == action + app.arguments.should == [ { } ] + end + + it "should use the default action if not given a valid one" do + app.command_line.stubs(:args).returns %w{bar} + action = stub(:options => []) + Puppet::Face[:basetest, '0.0.1'].expects(:get_default_action).returns(action) + app.stubs(:main) + app.run + app.action.should == action + app.arguments.should == [ 'bar', { } ] + end + + it "should have no action if not given a valid one and there is no default action" do + app.command_line.stubs(:args).returns %w{bar} + Puppet::Face[:basetest, '0.0.1'].expects(:get_default_action).returns(nil) + app.stubs(:main) + app.run + app.action.should be_nil + app.arguments.should == [ 'bar', { } ] end it "should report a sensible error when options with = fail" do @@ -178,6 +202,13 @@ describe Puppet::Application::FaceBase do app.main end + it "should lookup help when it cannot do anything else" do + app.action = nil + Puppet::Face[:help, :current].expects(:help).with(:basetest, *app.arguments) + app.stubs(:puts) # meh. Don't print nil, thanks. --daniel 2011-04-12 + app.main + end + it "should use its render method to render any result" do app.expects(:render).with(app.arguments.length + 1) app.stubs(:puts) # meh. Don't print nil, thanks. --daniel 2011-04-12 diff --git a/spec/unit/interface/action_builder_spec.rb b/spec/unit/interface/action_builder_spec.rb index 5b04df900..8f29c8a7b 100755 --- a/spec/unit/interface/action_builder_spec.rb +++ b/spec/unit/interface/action_builder_spec.rb @@ -65,5 +65,16 @@ describe Puppet::Interface::ActionBuilder do action.summary.should == "this is some text" end end + + context "action defaulting" do + let :face do Puppet::Interface.new(:default_action, '0.0.1') end + + it "should set the default to true" do + action = Puppet::Interface::ActionBuilder.build(face, :foo) do + default + end + action.default.should == true + end + end end end diff --git a/spec/unit/interface/action_manager_spec.rb b/spec/unit/interface/action_manager_spec.rb index c4b21eaac..387faa043 100755 --- a/spec/unit/interface/action_manager_spec.rb +++ b/spec/unit/interface/action_manager_spec.rb @@ -3,6 +3,7 @@ require 'spec_helper' # This is entirely an internal class for Interface, so we have to load it instead of our class. require 'puppet/interface' +require 'puppet/face' class ActionManagerTester include Puppet::Interface::ActionManager @@ -213,6 +214,23 @@ describe Puppet::Interface::ActionManager do end end + describe "#action" do + it 'should add an action' do + subject.action(:foo) { } + subject.get_action(:foo).should be_a Puppet::Interface::Action + end + + it 'should support default actions' do + subject.action(:foo) { default } + subject.get_default_action.should == subject.get_action(:foo) + end + + it 'should not support more than one default action' do + subject.action(:foo) { default } + expect { subject.action(:bar) { default } }.should raise_error + end + end + describe "#get_action" do let :parent_class do parent_class = Class.new(Puppet::Interface) |