X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=3rdparty%2Fmodules%2Fconcat%2Fspec%2Fspec_helper_local.rb;fp=3rdparty%2Fmodules%2Fconcat%2Fspec%2Fspec_helper_local.rb;h=fc2982789d44418bb18d54034ceb781829d7ca7c;hb=30caaa85aed7015ca0d77216bff175eebd917eb7;hp=0000000000000000000000000000000000000000;hpb=6f656bd4265e3dab13b9af2bf96e9044322e9d8f;p=mirror%2Fdsa-puppet.git diff --git a/3rdparty/modules/concat/spec/spec_helper_local.rb b/3rdparty/modules/concat/spec/spec_helper_local.rb new file mode 100644 index 000000000..fc2982789 --- /dev/null +++ b/3rdparty/modules/concat/spec/spec_helper_local.rb @@ -0,0 +1,75 @@ +if ENV['COVERAGE'] == 'yes' + require 'simplecov' + require 'simplecov-console' + require 'codecov' + + SimpleCov.formatters = [ + SimpleCov::Formatter::HTMLFormatter, + SimpleCov::Formatter::Console, + SimpleCov::Formatter::Codecov, + ] + SimpleCov.start do + track_files 'lib/**/*.rb' + + add_filter '/spec' + + # do not track vendored files + add_filter '/vendor' + add_filter '/.vendor' + + # do not track gitignored files + # this adds about 4 seconds to the coverage check + # this could definitely be optimized + add_filter do |f| + # system returns true if exit status is 0, which with git-check-ignore means file is ignored + system("git check-ignore --quiet #{f.filename}") + end + end +end + +shared_examples 'Puppet::Parameter::Boolean' do |parameter| + [true, :true, 'true', :yes, 'yes'].each do |value| + it "accepts #{value} (#{value.class}) as a value" do + resource[parameter] = value + expect(resource[parameter]).to eq(true) + end + end + + [false, :false, 'false', :no, 'no'].each do |value| + it "accepts #{value} (#{value.class}) as a value" do + resource[parameter] = value + expect(resource[parameter]).to eq(false) + end + end + + it 'does not accept "foo" as a value' do + expect { resource[parameter] = 'foo' }.to raise_error(%r{Invalid value "foo"}) + end +end + +shared_examples 'a parameter that accepts only string values' do |parameter| + it 'accepts a string value' do + resource[parameter] = 'foo' + expect(resource[parameter]).to eq('foo') + end + + it 'does not accept an array value' do + expect { resource[parameter] = ['foo', 'bar'] }.to raise_error(%r{must be a String}) + end + + it 'does not accept a hash value' do + expect { resource[parameter] = { foo: 'bar' } }.to raise_error(%r{must be a String}) + end + + it 'does not accept an integer value' do + expect { resource[parameter] = 9001 }.to raise_error(%r{must be a String}) + end + + it 'does not accept a boolean true value' do + expect { resource[parameter] = true }.to raise_error(%r{must be a String}) + end + + it 'does not accept a boolean false value' do + expect { resource[parameter] = false }.to raise_error(%r{must be a String}) + end +end