From f3e79ddcd56a221c7799b35efde7e9803a5c7923 Mon Sep 17 00:00:00 2001 From: David Schmitt Date: Mon, 1 Jun 2015 12:21:59 +0100 Subject: Convert tests to use plain rspec-puppet Tests in the new style produces the following documentation output: abs should not eq nil should run abs() and raise an Puppet::ParseError should run abs(-34) and return 34 should run abs("-34") and return 34 should run abs(34) and return 34 should run abs("34") and return 34 --- spec/functions/count_spec.rb | 43 +++++++++++++++---------------------------- 1 file changed, 15 insertions(+), 28 deletions(-) (limited to 'spec/functions/count_spec.rb') diff --git a/spec/functions/count_spec.rb b/spec/functions/count_spec.rb index f8f1d48..c8d1960 100755 --- a/spec/functions/count_spec.rb +++ b/spec/functions/count_spec.rb @@ -1,31 +1,18 @@ -#! /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) } end -- cgit v1.2.3