summaryrefslogtreecommitdiffstats
path: root/spec/unit/interface
diff options
context:
space:
mode:
authorDaniel Pittman <daniel@puppetlabs.com>2011-04-20 13:49:05 -0700
committerDaniel Pittman <daniel@puppetlabs.com>2011-04-20 13:49:05 -0700
commit8172060684e532eaba234eb992ed739511abbe59 (patch)
treeb5695e6f8988022d1352d644c255e9b7e4fa9455 /spec/unit/interface
parent8a3071caf4e470ca9dcb9d3a0f80218ee9a8ebb7 (diff)
parent5d7ef5caf30a0c5b3253340c5f2722e51c56c75e (diff)
Merge branch 'bug/2.7.x/7062-improve-cloudpack-option-parsing-errors' into 2.7.x
Diffstat (limited to 'spec/unit/interface')
-rwxr-xr-xspec/unit/interface/action_spec.rb56
1 files changed, 56 insertions, 0 deletions
diff --git a/spec/unit/interface/action_spec.rb b/spec/unit/interface/action_spec.rb
index 0eb450ee2..24826a6ef 100755
--- a/spec/unit/interface/action_spec.rb
+++ b/spec/unit/interface/action_spec.rb
@@ -12,6 +12,62 @@ describe Puppet::Interface::Action do
end
end
+ describe "#when_invoked=" do
+ it "should fail if the block has arity 0" do
+ pending "Ruby 1.8 (painfully) treats argument-free blocks as arity -1" if
+ RUBY_VERSION =~ /^1\.8/
+
+ expect {
+ Puppet::Interface.new(:action_when_invoked, '1.0.0') do
+ action :foo do
+ when_invoked do
+ end
+ end
+ end
+ }.to raise_error ArgumentError, /foobra/
+ end
+
+ it "should work with arity 1 blocks" do
+ face = Puppet::Interface.new(:action_when_invoked, '1.0.0') do
+ action :foo do
+ when_invoked {|one| }
+ end
+ end
+ # -1, because we use option defaulting. :(
+ face.method(:foo).arity.should == -1
+ end
+
+ it "should work with arity 2 blocks" do
+ face = Puppet::Interface.new(:action_when_invoked, '1.0.0') do
+ action :foo do
+ when_invoked {|one, two| }
+ end
+ end
+ # -2, because we use option defaulting. :(
+ face.method(:foo).arity.should == -2
+ end
+
+ it "should work with arity 1 blocks that collect arguments" do
+ face = Puppet::Interface.new(:action_when_invoked, '1.0.0') do
+ action :foo do
+ when_invoked {|*one| }
+ end
+ end
+ # -1, because we use only varargs
+ face.method(:foo).arity.should == -1
+ end
+
+ it "should work with arity 2 blocks that collect arguments" do
+ face = Puppet::Interface.new(:action_when_invoked, '1.0.0') do
+ action :foo do
+ when_invoked {|one, *two| }
+ end
+ end
+ # -2, because we take one mandatory argument, and one varargs
+ face.method(:foo).arity.should == -2
+ end
+ end
+
describe "when invoking" do
it "should be able to call other actions on the same object" do
face = Puppet::Interface.new(:my_face, '0.0.1') do