Skip to content

Commit 3985c8d

Browse files
committed
Update StatusReporter class
This class used to return the Console message but now it does not have that responsibility and will only return an empty string until we get the GPA Score on Skunk, we will print it as RubyCritic does
1 parent 0d827b8 commit 3985c8d

File tree

8 files changed

+33
-67
lines changed

8 files changed

+33
-67
lines changed

bin/console

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ puts ARGV.inspect
1313
require "skunk/cli/application"
1414
require "skunk/config"
1515

16-
Skunk::Config.formats = %i[json html]
16+
Skunk::Config.formats = %i[json console html]
1717
Skunk::Cli::Application.new(ARGV).execute

lib/skunk/commands/default.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@ def execute
3737
# @param [RubyCritic::AnalysedModulesCollection] A collection of analysed modules
3838
def report(analysed_modules)
3939
Reporter.generate_report(analysed_modules)
40-
41-
status_reporter.analysed_modules = analysed_modules
42-
status_reporter.score = analysed_modules.score
4340
end
4441
end
4542
end

lib/skunk/commands/status_reporter.rb

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,14 @@
44

55
module Skunk
66
module Command
7-
# Knows how to report status for stinky files
7+
# Extends RubyCritic::Command::StatusReporter to silence the status message
88
class StatusReporter < RubyCritic::Command::StatusReporter
9-
attr_accessor :analysed_modules
10-
119
def initialize(options = {})
1210
super(options)
1311
end
1412

15-
# Returns a simple status message indicating the analysis is complete
1613
def update_status_message
17-
@status_message = "Skunk Report Completed"
14+
@status_message = ""
1815
end
1916
end
2017
end

lib/skunk/generators/html_report.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def initialize(analysed_modules)
1818

1919
def generate_report
2020
create_directories_and_files
21-
puts "Skunk report generated at #{report_location}"
21+
puts "#{report_name} generated at #{report_location}"
2222
browser.open unless RubyCritic::Config.no_browser
2323
end
2424

@@ -40,6 +40,13 @@ def generators
4040
def overview_generator
4141
@overview_generator ||= Skunk::Generator::Html::Overview.new(@analysed_modules)
4242
end
43+
44+
def report_name
45+
self.class.name.split("::").last
46+
.gsub(/([a-z])([A-Z])/, '\1 \2')
47+
.downcase
48+
.capitalize
49+
end
4350
end
4451
end
4552
end
Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,33 @@
11
# frozen_string_literal: true
22

3-
require "rubycritic/generators/json_report"
4-
53
require "skunk/generators/json/simple"
64

75
module Skunk
86
module Generator
97
# Generates a JSON report for the analysed modules.
10-
class JsonReport < RubyCritic::Generator::JsonReport
8+
class JsonReport
119
def initialize(analysed_modules)
12-
super
1310
@analysed_modules = analysed_modules
1411
end
1512

13+
def generate_report
14+
FileUtils.mkdir_p(generator.file_directory)
15+
puts "#{report_name} generated at #{generator.file_pathname}"
16+
File.write(generator.file_pathname, generator.render)
17+
end
18+
1619
private
1720

1821
def generator
1922
Skunk::Generator::Json::Simple.new(@analysed_modules)
2023
end
24+
25+
def report_name
26+
self.class.name.split("::").last
27+
.gsub(/([a-z])([A-Z])/, '\1 \2')
28+
.downcase
29+
.capitalize
30+
end
2131
end
2232
end
2333
end

lib/skunk/reporter.rb

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@ def self.generate_report(analysed_modules)
1313
end
1414

1515
def self.report_generator_class(config_format)
16-
return unless Config.supported_format?(config_format)
17-
18-
require "skunk/generators/#{config_format}_report"
19-
Generator.const_get("#{config_format.capitalize}Report")
16+
if Config.supported_format?(config_format)
17+
require "skunk/generators/#{config_format}_report"
18+
Generator.const_get("#{config_format.capitalize}Report")
19+
else
20+
require "skunk/generators/console_report"
21+
Generator::ConsoleReport
22+
end
2023
end
2124
end
2225
end

test/lib/skunk/commands/status_reporter_test.rb

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,52 +2,14 @@
22

33
require "test_helper"
44

5-
require "rubycritic/analysers_runner"
6-
require "skunk/rubycritic/analysed_modules_collection"
75
require "skunk/commands/status_reporter"
86

97
describe Skunk::Command::StatusReporter do
10-
let(:paths) { "samples/rubycritic" }
11-
128
describe "#update_status_message" do
13-
let(:output) { File.read("test/samples/console_output.txt") }
149
let(:reporter) { Skunk::Command::StatusReporter.new({}) }
1510

16-
around do |example|
17-
RubyCritic::Config.source_control_system = MockGit.new
18-
runner = RubyCritic::AnalysersRunner.new(paths)
19-
analysed_modules = runner.run
20-
analysed_modules.each do |analysed_module|
21-
def analysed_module.coverage
22-
100.0
23-
end
24-
25-
def analysed_module.churn
26-
1
27-
end
28-
end
29-
30-
reporter.analysed_modules = analysed_modules
31-
reporter.score = analysed_modules.score
32-
example.call
33-
end
34-
3511
it "reports a simple status message" do
36-
_(reporter.update_status_message).must_equal "Skunk analysis complete. Use --format console to see detailed output."
12+
_(reporter.update_status_message).must_equal ""
3713
end
38-
39-
context "When there's nested spec files" do
40-
let(:paths) { "samples" }
41-
it "reports a simple status message" do
42-
_(reporter.update_status_message).must_equal "Skunk analysis complete. Use --format console to see detailed output."
43-
end
44-
end
45-
end
46-
end
47-
48-
# A Mock Git class that returns always 1 for revisions_count
49-
class MockGit < RubyCritic::SourceControlSystem::Git
50-
def revisions_count(_)
51-
1
5214
end
5315
end

test/samples/console_output.txt

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)