|
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 |
|
| 13 | + def rquote(str) |
| 14 | + Regexp.new(Regexp.quote(str)) |
| 15 | + end |
| 16 | + |
12 | 17 | describe '#show_warnings' do |
| 18 | + before { subject.show_warnings } |
13 | 19 | context 'when silenced' do |
14 | 20 | around do |example| |
15 | 21 | old = ENV['RUBY_DEP_GEM_SILENCE_WARNINGS'] |
|
21 | 27 | context 'with any outdated Ruby' do |
22 | 28 | let(:ruby_version) { '1.9.3' } |
23 | 29 | it 'does not show warning' do |
24 | | - expect(STDERR).to_not receive(:puts) |
25 | | - subject.show_warnings |
| 30 | + expect(STDERR).to_not have_received(:puts) |
26 | 31 | end |
27 | 32 | end |
28 | 33 | end |
|
31 | 36 | context 'with an up-to-date Ruby' do |
32 | 37 | let(:ruby_version) { '2.3.1' } |
33 | 38 | it 'does not show warning' do |
34 | | - expect(STDERR).to_not receive(:puts) |
35 | | - subject.show_warnings |
| 39 | + expect(STDERR).to_not have_received(:puts) |
36 | 40 | end |
37 | 41 | end |
38 | 42 |
|
39 | 43 | context 'with a secure but buggy Ruby' do |
40 | 44 | let(:ruby_version) { '2.2.4' } |
41 | 45 | it 'shows warning about bugs' do |
42 | | - expect(STDERR).to receive(:puts).with( |
43 | | - %r{RubyDep: WARNING: your Ruby is outdated\/buggy.}) |
44 | | - subject.show_warnings |
| 46 | + expect(STDERR).to have_received(:puts).with( |
| 47 | + %r{Your Ruby is outdated\/buggy.}) |
| 48 | + end |
| 49 | + |
| 50 | + it 'shows recommended action' do |
| 51 | + expected = rquote( |
| 52 | + 'Your Ruby is: 2.2.4 (buggy). Recommendation: install'\ |
| 53 | + ' 2.2.5 or 2.3.1') |
| 54 | + expect(STDERR).to have_received(:puts).with(expected) |
45 | 55 | end |
46 | 56 | end |
47 | 57 |
|
48 | 58 | context 'with an insecure Ruby' do |
49 | 59 | let(:ruby_version) { '2.2.3' } |
50 | 60 | it 'shows warning about vulnerability' do |
51 | | - expect(STDERR).to receive(:puts).with( |
52 | | - /RubyDep: WARNING: your Ruby has security vulnerabilities!/) |
53 | | - subject.show_warnings |
| 61 | + expect(STDERR).to have_received(:puts).with( |
| 62 | + /Your Ruby has security vulnerabilities!/) |
| 63 | + end |
| 64 | + |
| 65 | + it 'shows recommended action' do |
| 66 | + expected = rquote( |
| 67 | + 'Your Ruby is: 2.2.3 (insecure). Recommendation:'\ |
| 68 | + ' install 2.2.5 or 2.3.1. (Or, at least to 2.2.4 or 2.3.0)') |
| 69 | + expect(STDERR).to have_received(:puts).with(expected) |
| 70 | + end |
| 71 | + end |
| 72 | + |
| 73 | + context 'with an insecure base Ruby' do |
| 74 | + let(:ruby_version) { '2.2.0' } |
| 75 | + it 'shows warning about vulnerability' do |
| 76 | + expect(STDERR).to have_received(:puts).with( |
| 77 | + /Your Ruby has security vulnerabilities!/) |
| 78 | + end |
| 79 | + |
| 80 | + it 'shows recommended action' do |
| 81 | + expected = rquote( |
| 82 | + 'Your Ruby is: 2.2.0 (insecure). Recommendation: install 2.2.5'\ |
| 83 | + ' or 2.3.1. (Or, at least to 2.2.4 or 2.3.0)') |
| 84 | + expect(STDERR).to have_received(:puts).with(expected) |
54 | 85 | end |
55 | 86 | end |
56 | 87 |
|
57 | 88 | context 'with an unsupported Ruby' do |
58 | 89 | let(:ruby_version) { '1.9.3' } |
59 | 90 | it 'shows warning about vulnerability' do |
60 | | - expect(STDERR).to receive(:puts).with( |
61 | | - /RubyDep: WARNING: your Ruby has security vulnerabilities!/) |
62 | | - subject.show_warnings |
| 91 | + expect(STDERR).to have_received(:puts).with( |
| 92 | + /Your Ruby has security vulnerabilities!/) |
| 93 | + end |
| 94 | + |
| 95 | + it 'shows recommended action' do |
| 96 | + expected = rquote( |
| 97 | + 'Your Ruby is: 1.9.3 (insecure). Recommendation: install 2.2.5'\ |
| 98 | + ' or 2.3.1. (Or, at least to 2.1.9 or 2.2.4 or 2.3.0)') |
| 99 | + expect(STDERR).to have_received(:puts).with(expected) |
63 | 100 | end |
64 | 101 | end |
65 | 102 |
|
|
68 | 105 | let(:ruby_version) { '2.2.3' } |
69 | 106 | let(:ruby_engine) { 'jruby' } |
70 | 107 | it 'does not show warning about vulnerability' do |
71 | | - expect(STDERR).to_not receive(:puts) |
72 | | - subject.show_warnings |
| 108 | + expect(STDERR).to_not have_received(:puts) |
| 109 | + end |
| 110 | + |
| 111 | + it 'does not show a recommendation' do |
| 112 | + expect(STDERR).to_not have_received(:puts).with( |
| 113 | + /RubyDep: Your Ruby is:/) |
| 114 | + expect(STDERR).to_not have_received(:puts).with(/Recommendation:/) |
73 | 115 | end |
74 | 116 | end |
75 | 117 | end |
76 | 118 |
|
77 | | - context 'with an untracked ruby' do |
| 119 | + context 'with JRuby head' do |
78 | 120 | context 'when the JRuby is not known to be vulnerable' do |
| 121 | + let(:ruby_version) { '2.3.0' } |
| 122 | + let(:ruby_engine) { 'jruby' } |
| 123 | + it 'does not show warning about vulnerability' do |
| 124 | + expect(STDERR).to_not have_received(:puts) |
| 125 | + end |
| 126 | + |
| 127 | + it 'does not show a recommendation' do |
| 128 | + expect(STDERR).to_not have_received(:puts).with( |
| 129 | + /RubyDep: Your Ruby is:/) |
| 130 | + expect(STDERR).to_not have_received(:puts).with(/Recommendation:/) |
| 131 | + end |
| 132 | + end |
| 133 | + end |
| 134 | + |
| 135 | + context 'with an untracked ruby' do |
| 136 | + context 'when the Ruby is not listed' do |
79 | 137 | let(:ruby_version) { '1.2.3' } |
80 | 138 | let(:ruby_engine) { 'ironruby' } |
81 | 139 | it 'shows warning about vulnerability' do |
82 | | - expect(STDERR).to receive(:puts).with( |
83 | | - /RubyDep: WARNING: your Ruby has security vulnerabilities!/) |
84 | | - subject.show_warnings |
| 140 | + expect(STDERR).to have_received(:puts).with( |
| 141 | + /Your Ruby has security vulnerabilities!/) |
| 142 | + end |
| 143 | + |
| 144 | + it 'shows recommended action' do |
| 145 | + expected = rquote( |
| 146 | + "Your Ruby is: 1.2.3 'ironruby' (unrecognized). If this"\ |
| 147 | + ' version is important, please open an issue at'\ |
| 148 | + ' http://github.com/e2/ruby_dep') |
| 149 | + expect(STDERR).to have_received(:puts).with(expected) |
85 | 150 | end |
86 | 151 | end |
87 | 152 | end |
|
0 commit comments