Skip to content

Commit 71cdca9

Browse files
committed
refactor warnings spec
1 parent 7783c1b commit 71cdca9

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

spec/lib/ruby_dep/warning_spec.rb

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@
22

33
RSpec.describe RubyDep::Warning do
44
before do
5-
allow(STDERR).to receive(:puts)
5+
stub_const('STDERR', instance_double(IO))
66
stub_const('RUBY_VERSION', ruby_version)
77
stub_const('RUBY_ENGINE', ruby_engine)
8+
allow(STDERR).to receive(:puts)
89
end
910

1011
let(:ruby_engine) { 'ruby' }
1112

1213
describe '#show_warnings' do
14+
before { subject.show_warnings }
1315
context 'when silenced' do
1416
around do |example|
1517
old = ENV['RUBY_DEP_GEM_SILENCE_WARNINGS']
@@ -21,8 +23,7 @@
2123
context 'with any outdated Ruby' do
2224
let(:ruby_version) { '1.9.3' }
2325
it 'does not show warning' do
24-
expect(STDERR).to_not receive(:puts)
25-
subject.show_warnings
26+
expect(STDERR).to_not have_received(:puts)
2627
end
2728
end
2829
end
@@ -31,35 +32,39 @@
3132
context 'with an up-to-date Ruby' do
3233
let(:ruby_version) { '2.3.1' }
3334
it 'does not show warning' do
34-
expect(STDERR).to_not receive(:puts)
35-
subject.show_warnings
35+
expect(STDERR).to_not have_received(:puts)
3636
end
3737
end
3838

3939
context 'with a secure but buggy Ruby' do
4040
let(:ruby_version) { '2.2.4' }
4141
it 'shows warning about bugs' do
42-
expect(STDERR).to receive(:puts).with(
42+
expect(STDERR).to have_received(:puts).with(
4343
%r{RubyDep: WARNING: your Ruby is outdated\/buggy.})
44-
subject.show_warnings
4544
end
4645
end
4746

4847
context 'with an insecure Ruby' do
4948
let(:ruby_version) { '2.2.3' }
5049
it 'shows warning about vulnerability' do
51-
expect(STDERR).to receive(:puts).with(
50+
expect(STDERR).to have_received(:puts).with(
51+
/RubyDep: WARNING: your Ruby has security vulnerabilities!/)
52+
end
53+
end
54+
55+
context 'with an insecure base Ruby' do
56+
let(:ruby_version) { '2.2.3' }
57+
it 'shows warning about vulnerability' do
58+
expect(STDERR).to have_received(:puts).with(
5259
/RubyDep: WARNING: your Ruby has security vulnerabilities!/)
53-
subject.show_warnings
5460
end
5561
end
5662

5763
context 'with an unsupported Ruby' do
5864
let(:ruby_version) { '1.9.3' }
5965
it 'shows warning about vulnerability' do
60-
expect(STDERR).to receive(:puts).with(
66+
expect(STDERR).to have_received(:puts).with(
6167
/RubyDep: WARNING: your Ruby has security vulnerabilities!/)
62-
subject.show_warnings
6368
end
6469
end
6570

@@ -68,8 +73,7 @@
6873
let(:ruby_version) { '2.2.3' }
6974
let(:ruby_engine) { 'jruby' }
7075
it 'does not show warning about vulnerability' do
71-
expect(STDERR).to_not receive(:puts)
72-
subject.show_warnings
76+
expect(STDERR).to_not have_received(:puts)
7377
end
7478
end
7579
end
@@ -79,9 +83,8 @@
7983
let(:ruby_version) { '1.2.3' }
8084
let(:ruby_engine) { 'ironruby' }
8185
it 'shows warning about vulnerability' do
82-
expect(STDERR).to receive(:puts).with(
86+
expect(STDERR).to have_received(:puts).with(
8387
/RubyDep: WARNING: your Ruby has security vulnerabilities!/)
84-
subject.show_warnings
8588
end
8689
end
8790
end

0 commit comments

Comments
 (0)