X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=3rdparty%2Fmodules%2Fstdlib%2Fspec%2Ffunctions%2Fcount_spec.rb;h=3854cb877417fd9e1ca4af05872ed899efdd3d21;hb=1eb059797393099ff8bbfd961718a0fd46f18379;hp=f8f1d484277672cfd64fab87c0f6be3fa2ff4fa7;hpb=ad88f67c13ae0f1a08936dad643f1e3509ab5f40;p=mirror%2Fdsa-puppet.git diff --git a/3rdparty/modules/stdlib/spec/functions/count_spec.rb b/3rdparty/modules/stdlib/spec/functions/count_spec.rb index f8f1d4842..3854cb877 100755 --- a/3rdparty/modules/stdlib/spec/functions/count_spec.rb +++ b/3rdparty/modules/stdlib/spec/functions/count_spec.rb @@ -1,31 +1,23 @@ -#! /usr/bin/env ruby -S rspec - require 'spec_helper' -describe "the count function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - expect(Puppet::Parser::Functions.function("count")).to eq("function_count") - end - - it "should raise a ArgumentError if there is more than 2 arguments" do - expect { scope.function_count(['foo', 'bar', 'baz']) }.to( raise_error(ArgumentError)) - end - - it "should be able to count arrays" do - expect(scope.function_count([["1","2","3"]])).to(eq(3)) - end - - it "should be able to count matching elements in arrays" do - expect(scope.function_count([["1", "2", "2"], "2"])).to(eq(2)) - end - - it "should not count nil or empty strings" do - expect(scope.function_count([["foo","bar",nil,""]])).to(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 +describe 'count' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(ArgumentError) } + it { is_expected.to run.with_params("one").and_raise_error(ArgumentError) } + it { is_expected.to run.with_params("one", "two").and_return(1) } + it { + pending("should actually be like this, and not like above") + is_expected.to run.with_params("one", "two").and_raise_error(ArgumentError) + } + it { is_expected.to run.with_params("one", "two", "three").and_raise_error(ArgumentError) } + it { is_expected.to run.with_params(["one", "two", "three"]).and_return(3) } + it { is_expected.to run.with_params(["one", "two", "two"], "two").and_return(2) } + it { is_expected.to run.with_params(["one", nil, "two"]).and_return(2) } + it { is_expected.to run.with_params(["one", "", "two"]).and_return(2) } + it { is_expected.to run.with_params(["one", :undef, "two"]).and_return(2) } + + it { is_expected.to run.with_params(["ổņ℮", "ŧщộ", "three"]).and_return(3) } + it { is_expected.to run.with_params(["ổņ℮", "ŧщộ", "ŧщộ"], "ŧщộ").and_return(2) } + it { is_expected.to run.with_params(["ổņ℮", nil, "ŧщộ"]).and_return(2) } + it { is_expected.to run.with_params(["ổņ℮", :undef, "ŧщộ"]).and_return(2) } end