diff options
author | Daniel Pittman <daniel@puppetlabs.com> | 2011-05-12 14:31:01 -0700 |
---|---|---|
committer | Daniel Pittman <daniel@puppetlabs.com> | 2011-05-12 14:31:01 -0700 |
commit | 82fb02ce27c95d8326335a8d52a9ab7e676fe8d3 (patch) | |
tree | 6706dc7afa05bf4bbffb2ab7e616717fb6af0c86 /spec/unit/interface/action_builder_spec.rb | |
parent | 7f9c9e1089c4bc36d52fcdd9751de559c658bf8d (diff) | |
parent | 704623cb95aacb0544609620994dc36f61a4b463 (diff) | |
download | puppet-82fb02ce27c95d8326335a8d52a9ab7e676fe8d3.tar.gz puppet-82fb02ce27c95d8326335a8d52a9ab7e676fe8d3.tar.xz puppet-82fb02ce27c95d8326335a8d52a9ab7e676fe8d3.zip |
Merge branch 'next'
Diffstat (limited to 'spec/unit/interface/action_builder_spec.rb')
-rwxr-xr-x | spec/unit/interface/action_builder_spec.rb | 52 |
1 files changed, 40 insertions, 12 deletions
diff --git a/spec/unit/interface/action_builder_spec.rb b/spec/unit/interface/action_builder_spec.rb index 6f36d2b44..e9f10a1a6 100755 --- a/spec/unit/interface/action_builder_spec.rb +++ b/spec/unit/interface/action_builder_spec.rb @@ -7,7 +7,8 @@ describe Puppet::Interface::ActionBuilder do let :face do Puppet::Interface.new(:puppet_interface_actionbuilder, '0.0.1') end it "should build an action" do - action = Puppet::Interface::ActionBuilder.build(nil, :foo) do + action = Puppet::Interface::ActionBuilder.build(face, :foo) do + when_invoked do true end end action.should be_a(Puppet::Interface::Action) action.name.should == :foo @@ -26,17 +27,25 @@ describe Puppet::Interface::ActionBuilder do should raise_error("Action :foo must specify a block") end + it "should require an invocation block" do + expect { + Puppet::Interface::ActionBuilder.build(face, :foo) {} + }.to raise_error(/actions need to know what to do when_invoked; please add the block/) + end + describe "when handling options" do it "should have a #option DSL function" do method = nil Puppet::Interface::ActionBuilder.build(face, :foo) do + when_invoked do true end method = self.method(:option) end - method.should be + method.should be_an_instance_of Method end it "should define an option without a block" do action = Puppet::Interface::ActionBuilder.build(face, :foo) do + when_invoked do true end option "--bar" end action.should be_option :bar @@ -44,6 +53,7 @@ describe Puppet::Interface::ActionBuilder do it "should accept an empty block" do action = Puppet::Interface::ActionBuilder.build(face, :foo) do + when_invoked do true end option "--bar" do # This space left deliberately blank. end @@ -58,15 +68,18 @@ describe Puppet::Interface::ActionBuilder do option '-w' action(:foo) do + when_invoked do true end option '-x', '--ex' option '-y', '--why' end action(:bar) do + when_invoked do true end option '-z', '--zee' end action(:baz) do + when_invoked do true end option '-z', '--zed' end end @@ -75,6 +88,7 @@ describe Puppet::Interface::ActionBuilder do it 'should add the options from the specified action' do foo = face.get_action(:foo) action = Puppet::Interface::ActionBuilder.build(face, :inherit_options) do + when_invoked do true end inherit_options_from foo end action.options.should == foo.options @@ -84,15 +98,17 @@ describe Puppet::Interface::ActionBuilder do foo = face.get_action(:foo) bar = face.get_action(:bar) action = Puppet::Interface::ActionBuilder.build(face, :inherit_options) do + when_invoked do true end inherit_options_from foo inherit_options_from bar end - action.options.should == (foo.options + bar.options).uniq.sort + action.options.should == (foo.options + bar.options).uniq end it 'should permit symbolic names for actions in the same face' do foo = face.get_action(:foo) action = Puppet::Interface::ActionBuilder.build(face, :inherit_options) do + when_invoked do true end inherit_options_from :foo end action.options.should == foo.options @@ -101,6 +117,7 @@ describe Puppet::Interface::ActionBuilder do it 'should raise a useful error if you supply a bad action name' do expect do Puppet::Interface::ActionBuilder.build(face, :inherit_options) do + when_invoked do true end inherit_options_from :nowhere end end.to raise_error /nowhere/ @@ -110,6 +127,7 @@ describe Puppet::Interface::ActionBuilder do context "inline documentation" do it "should set the summary" do action = Puppet::Interface::ActionBuilder.build(face, :foo) do + when_invoked do true end summary "this is some text" end action.summary.should == "this is some text" @@ -119,13 +137,16 @@ describe Puppet::Interface::ActionBuilder do context "action defaulting" do it "should set the default to true" do action = Puppet::Interface::ActionBuilder.build(face, :foo) do + when_invoked do true end default end action.default.should be_true end it "should not be default by, er, default. *cough*" do - action = Puppet::Interface::ActionBuilder.build(face, :foo) do end + action = Puppet::Interface::ActionBuilder.build(face, :foo) do + when_invoked do true end + end action.default.should be_false end end @@ -134,6 +155,7 @@ describe Puppet::Interface::ActionBuilder do it "should fail if no rendering format is given" do expect { Puppet::Interface::ActionBuilder.build(face, :foo) do + when_invoked do true end when_rendering do true end end }.to raise_error ArgumentError, /must give a rendering format to when_rendering/ @@ -142,6 +164,7 @@ describe Puppet::Interface::ActionBuilder do it "should fail if no block is given" do expect { Puppet::Interface::ActionBuilder.build(face, :foo) do + when_invoked do true end when_rendering :json end }.to raise_error ArgumentError, /must give a block to when_rendering/ @@ -150,6 +173,7 @@ describe Puppet::Interface::ActionBuilder do it "should fail if the block takes no arguments" do expect { Puppet::Interface::ActionBuilder.build(face, :foo) do + when_invoked do true end when_rendering :json do true end end }.to raise_error ArgumentError, /when_rendering methods take one argument, the result, not/ @@ -158,6 +182,7 @@ describe Puppet::Interface::ActionBuilder do it "should fail if the block takes more than one argument" do expect { Puppet::Interface::ActionBuilder.build(face, :foo) do + when_invoked do true end when_rendering :json do |a, b, c| true end end }.to raise_error ArgumentError, /when_rendering methods take one argument, the result, not/ @@ -166,6 +191,7 @@ describe Puppet::Interface::ActionBuilder do it "should fail if the block takes a variable number of arguments" do expect { Puppet::Interface::ActionBuilder.build(face, :foo) do + when_invoked do true end when_rendering :json do |*args| true end end }.to raise_error(ArgumentError, @@ -174,6 +200,7 @@ describe Puppet::Interface::ActionBuilder do it "should stash a rendering block" do action = Puppet::Interface::ActionBuilder.build(face, :foo) do + when_invoked do true end when_rendering :json do |a| true end end action.when_rendering(:json).should be_an_instance_of Method @@ -182,6 +209,7 @@ describe Puppet::Interface::ActionBuilder do it "should fail if you try to set the same rendering twice" do expect { Puppet::Interface::ActionBuilder.build(face, :foo) do + when_invoked do true end when_rendering :json do |a| true end when_rendering :json do |a| true end end @@ -190,6 +218,7 @@ describe Puppet::Interface::ActionBuilder do it "should work if you set two different renderings" do action = Puppet::Interface::ActionBuilder.build(face, :foo) do + when_invoked do true end when_rendering :json do |a| true end when_rendering :yaml do |a| true end end @@ -199,6 +228,7 @@ describe Puppet::Interface::ActionBuilder do it "should be bound to the face when called" do action = Puppet::Interface::ActionBuilder.build(face, :foo) do + when_invoked do true end when_rendering :json do |a| self end end action.when_rendering(:json).call(true).should == face @@ -207,13 +237,16 @@ describe Puppet::Interface::ActionBuilder do context "#render_as" do it "should default to nil (eg: based on context)" do - action = Puppet::Interface::ActionBuilder.build(face, :foo) do end + action = Puppet::Interface::ActionBuilder.build(face, :foo) do + when_invoked do true end + end action.render_as.should be_nil end it "should fail if not rendering format is given" do expect { Puppet::Interface::ActionBuilder.build(face, :foo) do + when_invoked do true end render_as end }.to raise_error ArgumentError, /must give a rendering format to render_as/ @@ -222,23 +255,18 @@ describe Puppet::Interface::ActionBuilder do Puppet::Network::FormatHandler.formats.each do |name| it "should accept #{name.inspect} format" do action = Puppet::Interface::ActionBuilder.build(face, :foo) do + when_invoked do true end render_as name end action.render_as.should == name end end - it "should accept :for_humans format" do - action = Puppet::Interface::ActionBuilder.build(face, :foo) do - render_as :for_humans - end - action.render_as.should == :for_humans - end - [:if_you_define_this_format_you_frighten_me, "json", 12].each do |input| it "should fail if given #{input.inspect}" do expect { Puppet::Interface::ActionBuilder.build(face, :foo) do + when_invoked do true end render_as input end }.to raise_error ArgumentError, /#{input.inspect} is not a valid rendering format/ |