Update stdlib and concat to 6.1.0 both
[mirror/dsa-puppet.git] / 3rdparty / modules / concat / spec / spec_helper_local.rb
1 if ENV['COVERAGE'] == 'yes'
2   require 'simplecov'
3   require 'simplecov-console'
4   require 'codecov'
5
6   SimpleCov.formatters = [
7     SimpleCov::Formatter::HTMLFormatter,
8     SimpleCov::Formatter::Console,
9     SimpleCov::Formatter::Codecov,
10   ]
11   SimpleCov.start do
12     track_files 'lib/**/*.rb'
13
14     add_filter '/spec'
15
16     # do not track vendored files
17     add_filter '/vendor'
18     add_filter '/.vendor'
19
20     # do not track gitignored files
21     # this adds about 4 seconds to the coverage check
22     # this could definitely be optimized
23     add_filter do |f|
24       # system returns true if exit status is 0, which with git-check-ignore means file is ignored
25       system("git check-ignore --quiet #{f.filename}")
26     end
27   end
28 end
29
30 shared_examples 'Puppet::Parameter::Boolean' do |parameter|
31   [true, :true, 'true', :yes, 'yes'].each do |value|
32     it "accepts #{value} (#{value.class}) as a value" do
33       resource[parameter] = value
34       expect(resource[parameter]).to eq(true)
35     end
36   end
37
38   [false, :false, 'false', :no, 'no'].each do |value|
39     it "accepts #{value} (#{value.class}) as a value" do
40       resource[parameter] = value
41       expect(resource[parameter]).to eq(false)
42     end
43   end
44
45   it 'does not accept "foo" as a value' do
46     expect { resource[parameter] = 'foo' }.to raise_error(%r{Invalid value "foo"})
47   end
48 end
49
50 shared_examples 'a parameter that accepts only string values' do |parameter|
51   it 'accepts a string value' do
52     resource[parameter] = 'foo'
53     expect(resource[parameter]).to eq('foo')
54   end
55
56   it 'does not accept an array value' do
57     expect { resource[parameter] = ['foo', 'bar'] }.to raise_error(%r{must be a String})
58   end
59
60   it 'does not accept a hash value' do
61     expect { resource[parameter] = { foo: 'bar' } }.to raise_error(%r{must be a String})
62   end
63
64   it 'does not accept an integer value' do
65     expect { resource[parameter] = 9001 }.to raise_error(%r{must be a String})
66   end
67
68   it 'does not accept a boolean true value' do
69     expect { resource[parameter] = true }.to raise_error(%r{must be a String})
70   end
71
72   it 'does not accept a boolean false value' do
73     expect { resource[parameter] = false }.to raise_error(%r{must be a String})
74   end
75 end