Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/bundler/audit/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class CLI < ::Thor
method_option :verbose, :type => :boolean, :aliases => '-v'
method_option :ignore, :type => :array, :aliases => '-i'
method_option :update, :type => :boolean, :aliases => '-u'
method_option :no_exit_on_warn, :type => :boolean

def check
update if options[:update]
Expand All @@ -54,6 +55,7 @@ def check

if vulnerable
say "Vulnerabilities found!", :red
exit 0 if options.no_exit_on_warn?
exit 1
else
say("No vulnerabilities found", :green) unless options.quiet?
Expand Down
64 changes: 64 additions & 0 deletions spec/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,70 @@
require 'bundler/audit/cli'

describe Bundler::Audit::CLI do

describe "#check" do
context "when check is vulnerable" do
before do
scanner = double
expect(Bundler::Audit::Scanner).to receive(:new).and_return(scanner)
allow(scanner).to receive(:scan).and_yield(true)
end

context "not --no_exit_on_warn (the default)" do
before do
options = double("Options", ignore: nil)
allow(options).to receive(:[]).with(:update).and_return(false)
end

it "prints message" do
expect do
begin
subject.check
rescue SystemExit
end
end.to output(/Vulnerabilities found!/).to_stdout
end

it "should exit 1" do
expect do
# Capture output of `check` only to keep spec output clean.
# The test regarding specific output is above.
expect { subject.check }.to output.to_stdout
end.to raise_error(SystemExit) do |error|
expect(error.success?).to eq(false)
expect(error.status).to eq(1)
end
end
end

context "--no_exit_on_warn" do
it "prints message" do
expect do
begin
subject.check
rescue SystemExit
end
end.to output(/Vulnerabilities found!/).to_stdout
end

it "should exit 0" do
options = double("Options", no_exit_on_warn?: true, ignore: nil)
allow(options).to receive(:[]).with(:update).and_return(false)
allow(subject).to receive(:options).and_return(options)

expect do
# Capture output of `check` only to keep spec output clean.
# The test regarding specific output is above.
expect { subject.check }.to output.to_stdout
end.to raise_error(SystemExit) do |error|
expect(error.success?).to eq(true)
expect(error.status).to eq(0)
end
end
end
end
end

describe "#update" do
context "not --quiet (the default)" do
context "when update succeeds" do
Expand Down