Skip to content
Snippets Groups Projects
Commit 17aa2b69 authored by Doug Barrett's avatar Doug Barrett :two:
Browse files

Refactor for maintainability

parent c78654f1
No related branches found
No related tags found
Loading
......@@ -24,18 +24,7 @@ module GDK
show_results(diagnostic_results)
return 2 if @unexpected_error
out.puts("\n")
if correctable_results.any?
if @should_autocorrect
perform_corrections
else
out.info("You may autocorrect #{correctable_results.size} problems by running `gdk doctor --correct` or `gdk doctor -C`")
end
elsif @should_autocorrect
out.warn('No problems to autocorrect.')
end
handle_correctable_results(correctable_results)
return 2 if @unexpected_error
diagnostic_results.empty?
......@@ -48,7 +37,7 @@ module GDK
def installed?
# TODO: Eventually, the Procfile will no longer exists so we need a better
# way to determine this, but this will be OK for now.
GDK.root.join('Procfile')&.exist?
GDK.root.join('Procfile').exist?
end
def diagnostic_results
......@@ -91,6 +80,20 @@ module GDK
diagnostic
end
def handle_correctable_results(correctable_results)
out.puts("\n")
if correctable_results.any?
if @should_autocorrect
perform_corrections
else
out.info("You may autocorrect #{correctable_results.size} problems by running `gdk doctor --correct` or `gdk doctor -C`")
end
elsif @should_autocorrect
out.warn('No problems to autocorrect.')
end
end
def start_necessary_services
Runit.start('postgresql', quiet: true)
# Give services a chance to start up..
......
......@@ -5,10 +5,6 @@ module GDK
class GitMaintenance < Base
TITLE = 'Git Maintenance Recommendation'
def correctable?
true
end
def success?
repos_without_git_maintenance.empty?
end
......
......@@ -5,11 +5,11 @@ require 'stringio'
RSpec.describe GDK::Command::Doctor, :hide_output do
# rubocop:todo RSpec/VerifiedDoubles
let(:successful_diagnostic) do
double(GDK::Diagnostic, unexpected_error: nil, success?: true, correctable?: true, correct?: true, message: nil)
double(GDK::Diagnostic, unexpected_error: nil, success?: true, correctable?: false, correct?: false, message: nil)
end
let(:failing_diagnostic) do
double(GDK::Diagnostic, unexpected_error: nil, success?: false, correctable?: true, correct?: true, message: 'check failed')
double(GDK::Diagnostic, unexpected_error: nil, success?: false, correctable?: false, correct?: false, message: 'check failed')
end
let(:correctable_diagnostic) do
......@@ -89,6 +89,12 @@ RSpec.describe GDK::Command::Doctor, :hide_output do
expect(subject.run).to be(false)
end
it 'does not attempt to correct failed diagnostics' do
expect(failing_diagnostic).not_to receive(:correct?)
expect(subject.run).to be(false)
end
it 'prints a warning' do
expect(GDK::Output).to receive(:puts).with("\n").ordered
expect(GDK::Output).to receive(:warn).with('Your GDK may need attention.').ordered
......@@ -114,6 +120,12 @@ RSpec.describe GDK::Command::Doctor, :hide_output do
expect(subject.run).to be(false)
end
it 'does not attempt to correct failed diagnostics' do
expect(failing_diagnostic).not_to receive(:correct?)
expect(subject.run).to be(false)
end
it 'does not check if successful diagnostics are correctable' do
expect(successful_diagnostic).not_to receive(:correctable?)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment