diff options
author | Jeff McCune <jeff@puppetlabs.com> | 2013-04-10 14:40:13 -0700 |
---|---|---|
committer | Jeff McCune <jeff@puppetlabs.com> | 2013-04-10 14:40:13 -0700 |
commit | 2e2830deda7eede79110a191d0de9d6fc423b440 (patch) | |
tree | d16e812759ffb19855c8bb13cffdf15104c41f07 /spec/unit | |
parent | 6f9361e383982c5b719bbdf17ed72b85850b9d91 (diff) | |
parent | e81a45ee0085597dad5067cada94b05cf11c6c0c (diff) | |
download | puppet-stdlib-2e2830deda7eede79110a191d0de9d6fc423b440.tar.gz puppet-stdlib-2e2830deda7eede79110a191d0de9d6fc423b440.tar.bz2 |
Merge branch 'dalen-count'
* dalen-count:
(maint) Make stdlib usable as a Ruby GEM
(maint) Add the behavior for count() with arrays and hashes
Add a count function
closes #143
Diffstat (limited to 'spec/unit')
-rw-r--r-- | spec/unit/puppet/parser/functions/count_spec.rb | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/spec/unit/puppet/parser/functions/count_spec.rb b/spec/unit/puppet/parser/functions/count_spec.rb new file mode 100644 index 0000000..2453815 --- /dev/null +++ b/spec/unit/puppet/parser/functions/count_spec.rb @@ -0,0 +1,31 @@ +#! /usr/bin/env ruby -S rspec + +require 'spec_helper' + +describe "the count function" do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + it "should exist" do + Puppet::Parser::Functions.function("count").should == "function_count" + end + + it "should raise a ArgumentError if there is more than 2 arguments" do + lambda { scope.function_count(['foo', 'bar', 'baz']) }.should( raise_error(ArgumentError)) + end + + it "should be able to count arrays" do + scope.function_count([["1","2","3"]]).should(eq(3)) + end + + it "should be able to count matching elements in arrays" do + scope.function_count([["1", "2", "2"], "2"]).should(eq(2)) + end + + it "should not count nil or empty strings" do + scope.function_count([["foo","bar",nil,""]]).should(eq(2)) + end + + it 'does not count an undefined hash key or an out of bound array index (which are both :undef)' do + expect(scope.function_count([["foo",:undef,:undef]])).to eq(1) + end +end |