Skip to content

Commit 8da322f

Browse files
committed
Adding unit tests
1 parent a376238 commit 8da322f

File tree

4 files changed

+68
-0
lines changed

4 files changed

+68
-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: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,21 @@
1212
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]) }
1313
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]) }
1414
it { is_expected.to run.with_params(['ã', 'β', ['ĉ', %w[đ ƒ ġ]]]).and_return(%w[ã β ĉ đ ƒ ġ]) }
15+
16+
context 'with deprecation warning' do
17+
after(:each) do
18+
ENV.delete('STDLIB_LOG_DEPRECATIONS')
19+
end
20+
# Checking for deprecation warning, which should only be provoked when the env variable for it is set.
21+
it 'displays a single deprecation' do
22+
ENV['STDLIB_LOG_DEPRECATIONS'] = 'true'
23+
scope.expects(:warning).with(includes('This method is deprecated'))
24+
is_expected.to run.with_params(['a', ['b', ['c']]]).and_return(['a','b','c'])
25+
end
26+
it 'displays no warning for deprecation' do
27+
ENV['STDLIB_LOG_DEPRECATIONS'] = 'false'
28+
scope.expects(:warning).with(includes('This method is deprecated')).never
29+
is_expected.to run.with_params(['a', ['b', ['c']]]).and_return(['a','b','c'])
30+
end
31+
end
1532
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/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)