|
2 | 2 |
|
3 | 3 | RSpec.describe RubyDep::Warning do |
4 | 4 | before do |
5 | | - allow(STDERR).to receive(:puts) |
| 5 | + stub_const('STDERR', instance_double(IO)) |
6 | 6 | stub_const('RUBY_VERSION', ruby_version) |
7 | 7 | stub_const('RUBY_ENGINE', ruby_engine) |
| 8 | + allow(STDERR).to receive(:puts) |
8 | 9 | end |
9 | 10 |
|
10 | 11 | let(:ruby_engine) { 'ruby' } |
11 | 12 |
|
12 | 13 | describe '#show_warnings' do |
| 14 | + before { subject.show_warnings } |
13 | 15 | context 'when silenced' do |
14 | 16 | around do |example| |
15 | 17 | old = ENV['RUBY_DEP_GEM_SILENCE_WARNINGS'] |
|
21 | 23 | context 'with any outdated Ruby' do |
22 | 24 | let(:ruby_version) { '1.9.3' } |
23 | 25 | 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) |
26 | 27 | end |
27 | 28 | end |
28 | 29 | end |
|
31 | 32 | context 'with an up-to-date Ruby' do |
32 | 33 | let(:ruby_version) { '2.3.1' } |
33 | 34 | 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) |
36 | 36 | end |
37 | 37 | end |
38 | 38 |
|
39 | 39 | context 'with a secure but buggy Ruby' do |
40 | 40 | let(:ruby_version) { '2.2.4' } |
41 | 41 | it 'shows warning about bugs' do |
42 | | - expect(STDERR).to receive(:puts).with( |
| 42 | + expect(STDERR).to have_received(:puts).with( |
43 | 43 | %r{RubyDep: WARNING: your Ruby is outdated\/buggy.}) |
44 | | - subject.show_warnings |
45 | 44 | end |
46 | 45 | end |
47 | 46 |
|
48 | 47 | context 'with an insecure Ruby' do |
49 | 48 | let(:ruby_version) { '2.2.3' } |
50 | 49 | 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( |
52 | 59 | /RubyDep: WARNING: your Ruby has security vulnerabilities!/) |
53 | | - subject.show_warnings |
54 | 60 | end |
55 | 61 | end |
56 | 62 |
|
57 | 63 | context 'with an unsupported Ruby' do |
58 | 64 | let(:ruby_version) { '1.9.3' } |
59 | 65 | it 'shows warning about vulnerability' do |
60 | | - expect(STDERR).to receive(:puts).with( |
| 66 | + expect(STDERR).to have_received(:puts).with( |
61 | 67 | /RubyDep: WARNING: your Ruby has security vulnerabilities!/) |
62 | | - subject.show_warnings |
63 | 68 | end |
64 | 69 | end |
65 | 70 |
|
|
68 | 73 | let(:ruby_version) { '2.2.3' } |
69 | 74 | let(:ruby_engine) { 'jruby' } |
70 | 75 | 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) |
73 | 77 | end |
74 | 78 | end |
75 | 79 | end |
|
79 | 83 | let(:ruby_version) { '1.2.3' } |
80 | 84 | let(:ruby_engine) { 'ironruby' } |
81 | 85 | it 'shows warning about vulnerability' do |
82 | | - expect(STDERR).to receive(:puts).with( |
| 86 | + expect(STDERR).to have_received(:puts).with( |
83 | 87 | /RubyDep: WARNING: your Ruby has security vulnerabilities!/) |
84 | | - subject.show_warnings |
85 | 88 | end |
86 | 89 | end |
87 | 90 | end |
|
0 commit comments