summaryrefslogtreecommitdiffstats
path: root/spec/unit/interface/action_spec.rb
diff options
context:
space:
mode:
authorMax Martin <max@puppetlabs.com>2011-04-21 19:04:39 -0700
committerMax Martin <max@puppetlabs.com>2011-04-21 19:04:39 -0700
commit25593abbb044aca86c71cd60e91665eca0ce1bd1 (patch)
treed8703468b9b598c196348b748fbe47333b31a745 /spec/unit/interface/action_spec.rb
parent01f610bb223b435dc52f491260af3ea002930102 (diff)
parente4b31b411a4b3d7cce7f45197491eebc36d047aa (diff)
downloadpuppet-25593abbb044aca86c71cd60e91665eca0ce1bd1.tar.gz
puppet-25593abbb044aca86c71cd60e91665eca0ce1bd1.tar.xz
puppet-25593abbb044aca86c71cd60e91665eca0ce1bd1.zip
Merge branch 'next'
* next: (#6928) Don't blow up when the method is undefined... (#6928) backport Symbol#to_proc for Ruby < 1.8.7 (#7183) Implement "invisible glob" version matching for faces maint: better disabling of Signal#trap in our tests. maint: more robust listing of valid faces. maint: clean up testing code a fraction... maint: better error report for a missing version of a face. maint: handle face clear/reset sanely in the interface spec. maint: stop stubbing log level setting. Move tests from Puppet-acceptance repo (#7116) Handle application-level options in parse_options maint: fix gratuitous whitespace in the code. maint: remove redundant context from the test. (#7062) better argument handling in the action wrapper methods maint: move method comments outside the comment. Fixed #7166 - Replaced deprecated stomp "send" method with "publish" maint: Remove unused faces code
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