summaryrefslogtreecommitdiffstats
path: root/spec/unit/interface/action_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/unit/interface/action_spec.rb')
-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