Skip to content

Commit 331118f

Browse files
committed
Adding unit tests
1 parent a376238 commit 331118f

File tree

5 files changed

+86
-0
lines changed

5 files changed

+86
-0
lines changed

spec/functions/empty_spec.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,21 @@
1919

2020
it { is_expected.to run.with_params({}).and_return(true) }
2121
it { is_expected.to run.with_params('key' => 'value').and_return(false) }
22+
23+
context 'with deprecation warning' do
24+
after(:each) do
25+
ENV.delete('STDLIB_LOG_DEPRECATIONS')
26+
end
27+
# Checking for deprecation warning, which should only be provoked when the env variable for it is set.
28+
it 'displays a single deprecation' do
29+
ENV['STDLIB_LOG_DEPRECATIONS'] = 'true'
30+
scope.expects(:warning).with(includes('This method is deprecated'))
31+
is_expected.to run.with_params(0).and_return(false)
32+
end
33+
it 'displays no warning for deprecation' do
34+
ENV['STDLIB_LOG_DEPRECATIONS'] = 'false'
35+
scope.expects(:warning).with(includes('This method is deprecated')).never
36+
is_expected.to run.with_params(0).and_return(false)
37+
end
38+
end
2239
end

spec/functions/flatten_spec.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
require 'spec_helper'
22

3+
# rubocop:disable Style/WordArray, Layout/SpaceAfterComma
34
describe 'flatten' do
45
it { is_expected.not_to eq(nil) }
56
it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError) } if Puppet.version < '5.5.0'
@@ -12,4 +13,21 @@
1213
it { is_expected.to run.with_params(%w[a b c d e f g]).and_return(%w[a b c d e f g]) }
1314
it { is_expected.to run.with_params([['a', 'b', ['c', %w[d e], 'f', 'g']]]).and_return(%w[a b c d e f g]) }
1415
it { is_expected.to run.with_params(['ã', 'β', ['ĉ', %w[đ ƒ ġ]]]).and_return(%w[ã β ĉ đ ƒ ġ]) }
16+
17+
context 'with deprecation warning' do
18+
after(:each) do
19+
ENV.delete('STDLIB_LOG_DEPRECATIONS')
20+
end
21+
# Checking for deprecation warning, which should only be provoked when the env variable for it is set.
22+
it 'displays a single deprecation' do
23+
ENV['STDLIB_LOG_DEPRECATIONS'] = 'true'
24+
scope.expects(:warning).with(includes('This method is deprecated'))
25+
is_expected.to run.with_params(['a', ['b', ['c']]]).and_return(['a','b','c'])
26+
end
27+
it 'displays no warning for deprecation' do
28+
ENV['STDLIB_LOG_DEPRECATIONS'] = 'false'
29+
scope.expects(:warning).with(includes('This method is deprecated')).never
30+
is_expected.to run.with_params(['a', ['b', ['c']]]).and_return(['a','b','c'])
31+
end
32+
end
1533
end

spec/functions/join_spec.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,21 @@
1717
it { is_expected.to run.with_params(%w[one two three]).and_return('onetwothree') }
1818
it { is_expected.to run.with_params(%w[one two three], ':').and_return('one:two:three') }
1919
it { is_expected.to run.with_params(%w[ōŋể ŧשợ ţђŕẽё], ':').and_return('ōŋể:ŧשợ:ţђŕẽё') }
20+
21+
context 'with deprecation warning' do
22+
after(:each) do
23+
ENV.delete('STDLIB_LOG_DEPRECATIONS')
24+
end
25+
# Checking for deprecation warning, which should only be provoked when the env variable for it is set.
26+
it 'displays a single deprecation' do
27+
ENV['STDLIB_LOG_DEPRECATIONS'] = 'true'
28+
scope.expects(:warning).with(includes('This method is deprecated'))
29+
is_expected.to run.with_params([]).and_return('')
30+
end
31+
it 'displays no warning for deprecation' do
32+
ENV['STDLIB_LOG_DEPRECATIONS'] = 'false'
33+
scope.expects(:warning).with(includes('This method is deprecated')).never
34+
is_expected.to run.with_params([]).and_return('')
35+
end
36+
end
2037
end

spec/functions/keys_spec.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,21 @@
2424
expect(result).to match_array(%w[ҝểү キー])
2525
end
2626
end
27+
28+
context 'with deprecation warning' do
29+
after(:each) do
30+
ENV.delete('STDLIB_LOG_DEPRECATIONS')
31+
end
32+
# Checking for deprecation warning, which should only be provoked when the env variable for it is set.
33+
it 'displays a single deprecation' do
34+
ENV['STDLIB_LOG_DEPRECATIONS'] = 'true'
35+
scope.expects(:warning).with(includes('This method is deprecated'))
36+
is_expected.to run.with_params({}).and_return([])
37+
end
38+
it 'displays no warning for deprecation' do
39+
ENV['STDLIB_LOG_DEPRECATIONS'] = 'false'
40+
scope.expects(:warning).with(includes('This method is deprecated')).never
41+
is_expected.to run.with_params({}).and_return([])
42+
end
43+
end
2744
end

spec/functions/values_spec.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,21 @@
2323
expect(result).to match_array(['使用', '√ẩŀứệ', '√ẩŀứệ'])
2424
end
2525
end
26+
27+
context 'with deprecation warning' do
28+
after(:each) do
29+
ENV.delete('STDLIB_LOG_DEPRECATIONS')
30+
end
31+
# Checking for deprecation warning, which should only be provoked when the env variable for it is set.
32+
it 'displays a single deprecation' do
33+
ENV['STDLIB_LOG_DEPRECATIONS'] = 'true'
34+
scope.expects(:warning).with(includes('This method is deprecated'))
35+
is_expected.to run.with_params('key' => 'value').and_return(['value'])
36+
end
37+
it 'displays no warning for deprecation' do
38+
ENV['STDLIB_LOG_DEPRECATIONS'] = 'false'
39+
scope.expects(:warning).with(includes('This method is deprecated')).never
40+
is_expected.to run.with_params('key' => 'value').and_return(['value'])
41+
end
42+
end
2643
end

0 commit comments

Comments
 (0)