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/bool2str_spec.rb | 49 ++++++----------------------------------- 1 file changed, 7 insertions(+), 42 deletions(-) (limited to 'spec/functions/bool2str_spec.rb') diff --git a/spec/functions/bool2str_spec.rb b/spec/functions/bool2str_spec.rb index b878891..8d35598 100755 --- a/spec/functions/bool2str_spec.rb +++ b/spec/functions/bool2str_spec.rb @@ -1,46 +1,11 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' -describe "the bool2str function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - expect(Puppet::Parser::Functions.function("bool2str")).to eq("function_bool2str") - end - - it "should raise a ParseError if there is less than 1 arguments" do - expect { scope.function_bool2str([]) }.to( raise_error(Puppet::ParseError)) - end - - it "should convert true to 'true'" do - result = scope.function_bool2str([true]) - expect(result).to(eq('true')) - end - - it "should convert true to a string" do - result = scope.function_bool2str([true]) - expect(result.class).to(eq(String)) - end - - it "should convert false to 'false'" do - result = scope.function_bool2str([false]) - expect(result).to(eq('false')) - end - - it "should convert false to a string" do - result = scope.function_bool2str([false]) - expect(result.class).to(eq(String)) - end - - it "should not accept a string" do - expect { scope.function_bool2str(["false"]) }.to( raise_error(Puppet::ParseError)) - end - - it "should not accept a nil value" do - expect { scope.function_bool2str([nil]) }.to( raise_error(Puppet::ParseError)) - end - - it "should not accept an undef" do - expect { scope.function_bool2str([:undef]) }.to( raise_error(Puppet::ParseError)) +describe 'bool2str' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError) } + [ 'true', 'false', nil, :undef, ''].each do |invalid| + it { is_expected.to run.with_params(invalid).and_raise_error(Puppet::ParseError) } end + it { is_expected.to run.with_params(true).and_return("true") } + it { is_expected.to run.with_params(false).and_return("false") } end -- cgit v1.2.3