|
2 | 2 | require 'bundler/audit/cli' |
3 | 3 |
|
4 | 4 | describe Bundler::Audit::CLI do |
| 5 | + let(:database_path) { "/path/to/ruby-advisory-db" } |
| 6 | + |
5 | 7 | describe ".start" do |
6 | 8 | context "with wrong arguments" do |
7 | 9 | it "exits with error status code" do |
|
76 | 78 |
|
77 | 79 | context "when update fails" do |
78 | 80 | before do |
79 | | - expect(database).to receive(:update!).and_return(false) |
| 81 | + expect(database).to receive(:update!).with(quiet: false).and_raise( |
| 82 | + Bundler::Audit::Database::UpdateFailed, |
| 83 | + "failed to update #{database_path.inspect}" |
| 84 | + ) |
80 | 85 | end |
81 | 86 |
|
82 | | - it "prints failure message" do |
| 87 | + it "must print an error message and exit with 1" do |
83 | 88 | expect { |
84 | | - begin |
| 89 | + expect { |
85 | 90 | subject.update |
86 | | - rescue SystemExit |
87 | | - end |
88 | | - }.to output(/Failed updating ruby-advisory-db!/).to_stderr |
89 | | - end |
90 | | - |
91 | | - it "exits with error status code" do |
92 | | - expect { |
93 | | - # Capture output of `update` only to keep spec output clean. |
94 | | - # The test regarding specific output is above. |
95 | | - expect { subject.update }.to output.to_stdout |
| 91 | + }.to output("failed to update #{database_path.inspect}").to_stderr |
96 | 92 | }.to raise_error(SystemExit) do |error| |
97 | 93 | expect(error.success?).to eq(false) |
98 | 94 | expect(error.status).to eq(1) |
|
136 | 132 |
|
137 | 133 | context "when update succeeds" do |
138 | 134 | before do |
139 | | - expect(database).to( |
140 | | - receive(:update!).with(quiet: true).and_return(true) |
141 | | - ) |
| 135 | + expect(database).to receive(:update!).with(quiet: true).and_return(true) |
142 | 136 | end |
143 | 137 |
|
144 | 138 | it "does not print any output" do |
|
148 | 142 |
|
149 | 143 | context "when update fails" do |
150 | 144 | before do |
151 | | - expect(database).to( |
152 | | - receive(:update!).with(quiet: true).and_return(false) |
| 145 | + expect(database).to receive(:update!).with(quiet: true).and_raise( |
| 146 | + Bundler::Audit::Database::UpdateFailed, |
| 147 | + "failed to update #{database_path.inspect}" |
153 | 148 | ) |
154 | 149 | end |
155 | 150 |
|
156 | | - it "prints failure message" do |
| 151 | + it "must print the error message and exit with an error code" do |
157 | 152 | expect { |
158 | | - begin |
| 153 | + expect { |
159 | 154 | subject.update |
160 | | - rescue SystemExit |
161 | | - end |
162 | | - }.to_not output.to_stderr |
163 | | - end |
164 | | - |
165 | | - it "exits with error status code" do |
166 | | - expect { |
167 | | - # Capture output of `update` only to keep spec output clean. |
168 | | - # The test regarding specific output is above. |
169 | | - expect { subject.update }.to output.to_stdout |
| 155 | + }.to output("failed to update: #{database_path.inspect}").to_stderr |
170 | 156 | }.to raise_error(SystemExit) do |error| |
171 | 157 | expect(error.success?).to eq(false) |
172 | 158 | expect(error.status).to eq(1) |
|
0 commit comments