File tree 11 files changed +86
-2
lines changed
11 files changed +86
-2
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
## [ Unreleased] [ (commits)] ( https://github.com/fastruby/skunk/compare/v0.4.2...HEAD )
8
8
9
9
* [ FEATURE] Rename the tech debt metric: StinkScore => SkunkScore. It's a little friendlier.
10
+ * [ FEATURE] Add ` --out=file.txt ` support to the command line (by [ @manuca ] ( ) )
10
11
11
12
## [ 0.4.2] [ (commits)] ( https://github.com/fastruby/skunk/compare/v0.4.1...v0.4.2 )
12
13
* [ BUGFIX] Fixes table width issues by rounding values (by [ @etagwerker ] [ ] )
Original file line number Diff line number Diff line change 47
47
minitest (5.8.5 )
48
48
minitest-around (0.5.0 )
49
49
minitest (~> 5.0 )
50
+ minitest-stub_any_instance (1.0.2 )
50
51
parallel (1.19.2 )
51
52
parser (2.6.5.0 )
52
53
ast (~> 2.4.0 )
@@ -110,6 +111,7 @@ DEPENDENCIES
110
111
codecov (~> 0.1.16 )
111
112
minitest (~> 5.8.4 )
112
113
minitest-around (~> 0.5.0 )
114
+ minitest-stub_any_instance (~> 1.0.2 )
113
115
rake (~> 13.0 )
114
116
reek (~> 5.4.0 )
115
117
rubocop (< 1.0 )
Original file line number Diff line number Diff line change @@ -53,6 +53,7 @@ There are not that many options but here they are:
53
53
skunk -h
54
54
Usage: skunk [options] [paths]
55
55
-b, --branch BRANCH Set branch to compare
56
+ -o, --out FILE Output report to file
56
57
-v, --version Show gem's version
57
58
-h, --help Show this message
58
59
```
Original file line number Diff line number Diff line change 11
11
module Skunk
12
12
module Cli
13
13
# Knows how to execute command line commands
14
+ # :reek:InstanceVariableAssumption
14
15
class Application < RubyCritic ::Cli ::Application
15
16
COVERAGE_FILE = "coverage/.resultset.json"
16
17
@@ -21,8 +22,10 @@ def initialize(argv)
21
22
def execute
22
23
warn_coverage_info unless File . exist? ( COVERAGE_FILE )
23
24
24
- parsed_options = @options . parse . to_h
25
- reporter = Skunk ::Cli ::CommandFactory . create ( parsed_options ) . execute
25
+ # :reek:NilCheck
26
+ @parsed_options = @options . parse . to_h
27
+ reporter = Skunk ::Cli ::CommandFactory . create ( @parsed_options ) . execute
28
+
26
29
print ( reporter . status_message )
27
30
reporter . status
28
31
rescue OptionParser ::InvalidOption => error
@@ -36,6 +39,16 @@ def warn_coverage_info
36
39
warn "warning: Couldn't find coverage info at #{ COVERAGE_FILE } ."
37
40
warn "warning: Having no coverage metrics will make your SkunkScore worse."
38
41
end
42
+
43
+ # :reek:NilCheck
44
+ def print ( message )
45
+ filename = @parsed_options [ :output_filename ]
46
+ if filename . nil?
47
+ $stdout. puts ( message )
48
+ else
49
+ File . open ( filename , "w" ) { |file | file . puts ( message ) }
50
+ end
51
+ end
39
52
end
40
53
end
41
54
end
Original file line number Diff line number Diff line change @@ -9,6 +9,9 @@ class Options
9
9
# Extends RubyCritic::Cli::Options::Argv to parse a subset of the
10
10
# parameters accepted by RubyCritic
11
11
class Argv < RubyCritic ::Cli ::Options ::Argv
12
+ # :reek:Attribute
13
+ attr_accessor :output_filename
14
+
12
15
def parse # rubocop:disable Metrics/MethodLength
13
16
parser . new do |opts |
14
17
opts . banner = "Usage: skunk [options] [paths]\n "
@@ -19,6 +22,10 @@ def parse # rubocop:disable Metrics/MethodLength
19
22
self . mode = :compare_branches
20
23
end
21
24
25
+ opts . on ( "-o" , "--out FILE" , "Output report to file" ) do |filename |
26
+ self . output_filename = filename
27
+ end
28
+
22
29
opts . on_tail ( "-v" , "--version" , "Show gem's version" ) do
23
30
self . mode = :version
24
31
end
@@ -28,6 +35,10 @@ def parse # rubocop:disable Metrics/MethodLength
28
35
end
29
36
end . parse! ( @argv )
30
37
end
38
+
39
+ def to_h
40
+ super . merge ( output_filename : output_filename )
41
+ end
31
42
end
32
43
end
33
44
end
Original file line number Diff line number Diff line change @@ -45,6 +45,7 @@ Gem::Specification.new do |spec|
45
45
spec . add_development_dependency "codecov" , "~> 0.1.16"
46
46
spec . add_development_dependency "minitest" , "~> 5.8.4"
47
47
spec . add_development_dependency "minitest-around" , "~> 0.5.0"
48
+ spec . add_development_dependency "minitest-stub_any_instance" , "~> 1.0.2"
48
49
spec . add_development_dependency "rake" , "~> 13.0"
49
50
spec . add_development_dependency "reek" , "~> 5.4.0"
50
51
spec . add_development_dependency "rubocop" , "< 1.0"
Original file line number Diff line number Diff line change 2
2
3
3
require "test_helper"
4
4
require "skunk/cli/application"
5
+ require "rubycritic/core/analysed_module"
5
6
6
7
describe Skunk ::Cli ::Application do
7
8
describe "#execute" do
27
28
_ ( result ) . must_equal success_code
28
29
end
29
30
end
31
+
32
+ context "when passing --out option with a file" do
33
+ require "fileutils"
34
+
35
+ let ( :argv ) { [ "--out=tmp/generated_report.txt" , "samples/rubycritic" ] }
36
+ let ( :success_code ) { 0 }
37
+
38
+ it "writes output to the file" do
39
+ FileUtils . rm ( "tmp/generated_report.txt" , force : true )
40
+ FileUtils . mkdir_p ( "tmp" )
41
+
42
+ RubyCritic ::AnalysedModule . stub_any_instance ( :churn , 1 ) do
43
+ RubyCritic ::AnalysedModule . stub_any_instance ( :coverage , 100.0 ) do
44
+ result = application . execute
45
+ _ ( result ) . must_equal success_code
46
+ end
47
+ end
48
+
49
+ _ ( File . read ( "tmp/generated_report.txt" ) )
50
+ . must_equal File . read ( "test/samples/console_output.txt" )
51
+ end
52
+ end
30
53
end
31
54
end
Original file line number Diff line number Diff line change 10
10
MSG = <<~HELP
11
11
Usage: skunk [options] [paths]
12
12
-b, --branch BRANCH Set branch to compare
13
+ -o, --out FILE Output report to file
13
14
-v, --version Show gem's version
14
15
-h, --help Show this message
15
16
HELP
Original file line number Diff line number Diff line change
1
+ # frozen_string_literal: true
2
+
3
+ require "test_helper"
4
+
5
+ require "skunk/cli/options/argv"
6
+
7
+ describe Skunk ::Cli ::Options ::Argv do
8
+ describe "#output_filename" do
9
+ context "passing --out=FILE options" do
10
+ let ( :argv ) { [ "--out=file.txt" ] }
11
+
12
+ it "parses passed filename" do
13
+ parser = Skunk ::Cli ::Options ::Argv . new ( argv )
14
+ parser . parse
15
+ _ ( parser . output_filename ) . must_equal "file.txt"
16
+ end
17
+ end
18
+
19
+ context "not passing the --out option" do
20
+ it "is nil" do
21
+ parser = Skunk ::Cli ::Options ::Argv . new ( [ ] )
22
+ parser . parse
23
+ _ ( parser . output_filename ) . must_be_nil
24
+ end
25
+ end
26
+ end
27
+ end
Original file line number Diff line number Diff line change @@ -8,3 +8,5 @@ SkunkScore Total: 0.59
8
8
Modules Analysed: 1
9
9
SkunkScore Average: 0.59
10
10
Worst SkunkScore: 0.59 (samples/rubycritic/analysed_module.rb)
11
+
12
+ Generated with Skunk v0.4.2
Original file line number Diff line number Diff line change 19
19
require "minitest/autorun"
20
20
require "minitest/pride"
21
21
require "minitest/around/spec"
22
+ require "minitest/stub_any_instance"
23
+
22
24
require "skunk/rubycritic/analysed_module"
23
25
24
26
def context ( *args , &block )
You can’t perform that action at this time.
0 commit comments