rubycritic 2.5.0 → 2.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -0
- data/CHANGELOG.md +5 -0
- data/README.md +1 -0
- data/Rakefile +6 -1
- data/features/command_line_interface/minimum_score.feature +39 -0
- data/features/command_line_interface/options.feature +35 -0
- data/features/step_definitions/rubycritic_steps.rb +31 -0
- data/features/step_definitions/sample_file_steps.rb +30 -0
- data/features/support/env.rb +31 -0
- data/lib/rubycritic/analysers/helpers/modules_locator.rb +0 -1
- data/lib/rubycritic/cli/application.rb +8 -2
- data/lib/rubycritic/cli/options.rb +7 -5
- data/lib/rubycritic/command_factory.rb +10 -7
- data/lib/rubycritic/commands/base.rb +16 -0
- data/lib/rubycritic/commands/ci.rb +2 -14
- data/lib/rubycritic/commands/default.rb +7 -3
- data/lib/rubycritic/commands/help.rb +5 -6
- data/lib/rubycritic/commands/status_reporter.rb +43 -0
- data/lib/rubycritic/commands/version.rb +3 -1
- data/lib/rubycritic/version.rb +1 -1
- data/rubycritic.gemspec +2 -0
- data/test/lib/rubycritic/analysers/helpers/modules_locator_test.rb +2 -2
- data/test/lib/rubycritic/commands/status_reporter_test.rb +67 -0
- data/test/lib/rubycritic/core/analysed_modules_collection_test.rb +1 -1
- data/test/samples/no_methods.rb +4 -0
- metadata +41 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 63f7b195fa4fd7ee15061bdfc41a49f7031e1c6a
|
|
4
|
+
data.tar.gz: bc1b0a3185d7387223aea5467eb62ab1ba93ce9d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a5d3d4dc64f42b8b28650dd3c182633aa7e9e3f153a48f2315ead8969c79d1c99775975d23ca9236ba1a423f4db0073af35b0e96413abf780e7e4c07c9f57b7c
|
|
7
|
+
data.tar.gz: 27e3289f5e5629763e8bcbd505738f3c8cf5d6a9ffae6f8cff1e6cec2a92837170805f5eeee85abd3a491a16458ff0cab0e090cfe0d9d20ff81020d8648738fc
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
# 2.6.0 / 2015-01-21
|
|
2
|
+
|
|
3
|
+
* [FEATURE] Add a minimum score option to the command line interface (by Roberto Schneider)
|
|
4
|
+
* [CHANGE] Display the class and module names when the file has no methods
|
|
5
|
+
|
|
1
6
|
# 2.5.0 / 2015-01-16
|
|
2
7
|
|
|
3
8
|
* [FEATURE] Add a ConsoleReport format (by Josh Bodah)
|
data/README.md
CHANGED
|
@@ -96,6 +96,7 @@ $ rubycritic --help
|
|
|
96
96
|
|--------------------------|-------------------------------------------------------|
|
|
97
97
|
| `-v/--version` | Displays the current version and exits |
|
|
98
98
|
| `-p/--path` | Sets the output directory (tmp/rubycritic by default) |
|
|
99
|
+
| `-s/--minimum-score` | Set a minimum score |
|
|
99
100
|
| `--mode-ci` | Uses CI mode (faster, but only analyses last commit) |
|
|
100
101
|
| `--deduplicate-symlinks` | De-duplicate symlinks based on their final target |
|
|
101
102
|
| `--suppress-ratings` | Suppress letter ratings |
|
data/Rakefile
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
require "bundler/gem_tasks"
|
|
2
2
|
require "rake/testtask"
|
|
3
3
|
require "rubocop/rake_task"
|
|
4
|
+
require "cucumber/rake/task"
|
|
4
5
|
|
|
5
6
|
Rake::TestTask.new do |task|
|
|
6
7
|
task.libs.push "lib"
|
|
@@ -8,6 +9,10 @@ Rake::TestTask.new do |task|
|
|
|
8
9
|
task.pattern = "test/**/*_test.rb"
|
|
9
10
|
end
|
|
10
11
|
|
|
12
|
+
Cucumber::Rake::Task.new(:features) do |t|
|
|
13
|
+
t.cucumber_opts = "features --format progress --color"
|
|
14
|
+
end
|
|
15
|
+
|
|
11
16
|
RuboCop::RakeTask.new
|
|
12
17
|
|
|
13
|
-
task :default => [:test, :rubocop]
|
|
18
|
+
task :default => [:test, :features, :rubocop]
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
Feature: Break if overall score is bellow minimum
|
|
2
|
+
In order to break the Continuous Integration builds based on a score threshold
|
|
3
|
+
Rubycritic returns the exit status according with the score
|
|
4
|
+
|
|
5
|
+
Scenario: Status indicates a success when not using --minimum-score
|
|
6
|
+
Given the smelly file 'smelly.rb' with a score of 93.75
|
|
7
|
+
When I run rubycritic smelly.rb
|
|
8
|
+
Then the exit status indicates a success
|
|
9
|
+
|
|
10
|
+
Scenario: Status indicates an error when score below the minimum
|
|
11
|
+
Given the smelly file 'smelly.rb' with a score of 93.75
|
|
12
|
+
When I run rubycritic --minimum-score 100 smelly.rb
|
|
13
|
+
Then the exit status indicates an error
|
|
14
|
+
|
|
15
|
+
Scenario: Status indicates a success when score is above the minimum
|
|
16
|
+
Given the smelly file 'smelly.rb' with a score of 93.75
|
|
17
|
+
When I run rubycritic --minimum-score 93 smelly.rb
|
|
18
|
+
Then the exit status indicates a success
|
|
19
|
+
|
|
20
|
+
Scenario: Status indicates a success when score is equal the minimum
|
|
21
|
+
Given the clean file 'clean.rb' with a score of 100
|
|
22
|
+
When I run rubycritic --minimum-score 100 clean.rb
|
|
23
|
+
Then the exit status indicates a success
|
|
24
|
+
|
|
25
|
+
Scenario: Prints the score on output
|
|
26
|
+
Given the smelly file 'smelly.rb' with a score of 93.75
|
|
27
|
+
When I run rubycritic smelly.rb
|
|
28
|
+
Then the output should contain:
|
|
29
|
+
"""
|
|
30
|
+
Score: 93.75
|
|
31
|
+
"""
|
|
32
|
+
|
|
33
|
+
Scenario: Prints a message informing the score is below the minimum
|
|
34
|
+
Given the empty file 'empty.rb' with a score of 0
|
|
35
|
+
When I run rubycritic --minimum-score 100 empty.rb
|
|
36
|
+
Then the output should contain:
|
|
37
|
+
"""
|
|
38
|
+
Score (0.0) is below the minimum 100
|
|
39
|
+
"""
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
Feature: Rubycritic can be controlled using command-line options
|
|
2
|
+
In order to change Rubycritic's default behaviour
|
|
3
|
+
As a developer
|
|
4
|
+
I want to supply options on the command line
|
|
5
|
+
|
|
6
|
+
Scenario: return non-zero status on bad option
|
|
7
|
+
When I run rubycritic --no-such-option
|
|
8
|
+
Then the exit status indicates an error
|
|
9
|
+
And it reports the error "Error: invalid option: --no-such-option"
|
|
10
|
+
And there is no output on stdout
|
|
11
|
+
|
|
12
|
+
Scenario: display the current version number
|
|
13
|
+
When I run rubycritic --version
|
|
14
|
+
Then it succeeds
|
|
15
|
+
And it reports the current version
|
|
16
|
+
|
|
17
|
+
Scenario: display the help information
|
|
18
|
+
When I run rubycritic --help
|
|
19
|
+
Then it succeeds
|
|
20
|
+
And it reports:
|
|
21
|
+
"""
|
|
22
|
+
Usage: rubycritic [options] [paths]
|
|
23
|
+
-p, --path [PATH] Set path where report will be saved (tmp/rubycritic by default)
|
|
24
|
+
-f, --format [FORMAT] Report smells in the given format:
|
|
25
|
+
html (default)
|
|
26
|
+
json
|
|
27
|
+
console
|
|
28
|
+
-s, --minimum-score [MIN_SCORE] Set a minimum score
|
|
29
|
+
-m, --mode-ci Use CI mode (faster, but only analyses last commit)
|
|
30
|
+
--deduplicate-symlinks De-duplicate symlinks based on their final target
|
|
31
|
+
--suppress-ratings Suppress letter ratings
|
|
32
|
+
-v, --version Show gem's version
|
|
33
|
+
-h, --help Show this message
|
|
34
|
+
|
|
35
|
+
"""
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
When(/^I run rubycritic (.*)$/) do |args|
|
|
2
|
+
rubycritic(args)
|
|
3
|
+
end
|
|
4
|
+
|
|
5
|
+
Then(/^the exit status indicates an error$/) do
|
|
6
|
+
expect(last_command_started).to have_exit_status(Rubycritic::Command::StatusReporter::SCORE_BELOW_MINIMUM)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
Then(/^the exit status indicates a success$/) do
|
|
10
|
+
expect(last_command_started).to have_exit_status(Rubycritic::Command::StatusReporter::SUCCESS)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
Then(/^it reports:$/) do |report|
|
|
14
|
+
expect(last_command_started).to have_output_on_stdout(report.gsub('\n', "\n"))
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
Then(/^there is no output on stdout$/) do
|
|
18
|
+
expect(last_command_started).to have_output_on_stdout("")
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
Then(/^it reports the current version$/) do
|
|
22
|
+
expect(last_command_started).to have_output("RubyCritic #{Rubycritic::VERSION}\n")
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
Then(/^it reports the error ['"](.*)['"]$/) do |string|
|
|
26
|
+
expect(last_command_started).to have_output_on_stderr(/#{Regexp.escape(string)}/)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
Then(/^it succeeds$/) do
|
|
30
|
+
expect(last_command_started).to have_exit_status(Rubycritic::Command::StatusReporter::SUCCESS)
|
|
31
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
Given(/^the smelly file 'smelly.rb'/) do
|
|
2
|
+
contents = <<-EOS.strip_heredoc
|
|
3
|
+
class AllTheMethods
|
|
4
|
+
def method_missing(method, *args, &block)
|
|
5
|
+
message = "I"
|
|
6
|
+
eval "message = ' did not'"
|
|
7
|
+
eval "message << ' exist,'"
|
|
8
|
+
eval "message << ' but now'"
|
|
9
|
+
eval "message << ' I do.'"
|
|
10
|
+
self.class.send(:define_method, method) { "I did not exist, but now I do." }
|
|
11
|
+
self.send(method)
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
EOS
|
|
15
|
+
write_file("smelly.rb", contents)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
Given(/^the clean file 'clean.rb'/) do
|
|
19
|
+
contents = <<-EOS.strip_heredoc
|
|
20
|
+
# Explanatory comment
|
|
21
|
+
class Clean
|
|
22
|
+
def foo; end
|
|
23
|
+
end
|
|
24
|
+
EOS
|
|
25
|
+
write_file("clean.rb", contents)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
Given(/^the empty file 'empty.rb'/) do
|
|
29
|
+
write_file("clean.rb", "")
|
|
30
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
require_relative "../../lib/rubycritic"
|
|
2
|
+
require_relative "../../lib/rubycritic/cli/application"
|
|
3
|
+
require_relative "../../lib/rubycritic/commands/status_reporter"
|
|
4
|
+
require "aruba/cucumber"
|
|
5
|
+
require "minitest/spec"
|
|
6
|
+
|
|
7
|
+
#
|
|
8
|
+
# Provides runner methods used in the cucumber steps.
|
|
9
|
+
#
|
|
10
|
+
class RubycriticWorld
|
|
11
|
+
extend MiniTest::Assertions
|
|
12
|
+
attr_accessor :assertions
|
|
13
|
+
|
|
14
|
+
def initialize
|
|
15
|
+
self.assertions = 0
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def rubycritic(args)
|
|
19
|
+
run_simple("rubycritic #{args}", false)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
World do
|
|
24
|
+
RubycriticWorld.new
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
Before do
|
|
28
|
+
Aruba.configure do |config|
|
|
29
|
+
config.exit_timeout = 30
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -14,12 +14,18 @@ module Rubycritic
|
|
|
14
14
|
|
|
15
15
|
def execute
|
|
16
16
|
parsed_options = @options.parse
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
|
|
18
|
+
reporter = Rubycritic::CommandFactory.create(parsed_options.to_h).execute
|
|
19
|
+
print(reporter.status_message)
|
|
20
|
+
reporter.status
|
|
19
21
|
rescue OptionParser::InvalidOption => error
|
|
20
22
|
$stderr.puts "Error: #{error}"
|
|
21
23
|
STATUS_ERROR
|
|
22
24
|
end
|
|
25
|
+
|
|
26
|
+
def print(message)
|
|
27
|
+
$stdout.puts message
|
|
28
|
+
end
|
|
23
29
|
end
|
|
24
30
|
end
|
|
25
31
|
end
|
|
@@ -28,6 +28,10 @@ module Rubycritic
|
|
|
28
28
|
@format = format
|
|
29
29
|
end
|
|
30
30
|
|
|
31
|
+
opts.on("-s", "--minimum-score [MIN_SCORE]", "Set a minimum score") do |min_score|
|
|
32
|
+
@minimum_score = Integer(min_score)
|
|
33
|
+
end
|
|
34
|
+
|
|
31
35
|
opts.on("-m", "--mode-ci", "Use CI mode (faster, but only analyses last commit)") do
|
|
32
36
|
@mode = :ci
|
|
33
37
|
end
|
|
@@ -51,10 +55,6 @@ module Rubycritic
|
|
|
51
55
|
self
|
|
52
56
|
end
|
|
53
57
|
|
|
54
|
-
def help_text
|
|
55
|
-
@parser.help
|
|
56
|
-
end
|
|
57
|
-
|
|
58
58
|
def to_h
|
|
59
59
|
{
|
|
60
60
|
:mode => @mode,
|
|
@@ -62,7 +62,9 @@ module Rubycritic
|
|
|
62
62
|
:format => @format,
|
|
63
63
|
:deduplicate_symlinks => @deduplicate_symlinks,
|
|
64
64
|
:paths => paths,
|
|
65
|
-
:suppress_ratings => @suppress_ratings
|
|
65
|
+
:suppress_ratings => @suppress_ratings,
|
|
66
|
+
:help_text => @parser.help,
|
|
67
|
+
:minimum_score => @minimum_score || 0
|
|
66
68
|
}
|
|
67
69
|
end
|
|
68
70
|
|
|
@@ -3,21 +3,24 @@ require "rubycritic/configuration"
|
|
|
3
3
|
module Rubycritic
|
|
4
4
|
class CommandFactory
|
|
5
5
|
def self.create(options = {})
|
|
6
|
-
|
|
7
|
-
Config.
|
|
8
|
-
|
|
6
|
+
Config.set(options)
|
|
7
|
+
command_class(Config.mode).new(options)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def self.command_class(mode)
|
|
11
|
+
case mode
|
|
9
12
|
when :version
|
|
10
13
|
require "rubycritic/commands/version"
|
|
11
|
-
Command::Version
|
|
14
|
+
Command::Version
|
|
12
15
|
when :help
|
|
13
16
|
require "rubycritic/commands/help"
|
|
14
|
-
Command::Help
|
|
17
|
+
Command::Help
|
|
15
18
|
when :ci
|
|
16
19
|
require "rubycritic/commands/ci"
|
|
17
|
-
Command::Ci
|
|
20
|
+
Command::Ci
|
|
18
21
|
else
|
|
19
22
|
require "rubycritic/commands/default"
|
|
20
|
-
Command::Default
|
|
23
|
+
Command::Default
|
|
21
24
|
end
|
|
22
25
|
end
|
|
23
26
|
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
require "rubycritic/commands/status_reporter"
|
|
2
|
+
|
|
3
|
+
module Rubycritic
|
|
4
|
+
module Command
|
|
5
|
+
class Base
|
|
6
|
+
def initialize(options)
|
|
7
|
+
@options = options
|
|
8
|
+
@status_reporter = Rubycritic::Command::StatusReporter.new(@options)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def execute
|
|
12
|
+
raise NotImplementedError
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -1,26 +1,14 @@
|
|
|
1
1
|
require "rubycritic/source_control_systems/base"
|
|
2
2
|
require "rubycritic/analysers_runner"
|
|
3
3
|
require "rubycritic/reporter"
|
|
4
|
+
require "rubycritic/commands/default"
|
|
4
5
|
|
|
5
6
|
module Rubycritic
|
|
6
7
|
module Command
|
|
7
|
-
class Ci
|
|
8
|
-
def initialize(paths)
|
|
9
|
-
@paths = paths
|
|
10
|
-
Config.source_control_system = SourceControlSystem::Base.create
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def execute
|
|
14
|
-
report(critique)
|
|
15
|
-
end
|
|
16
|
-
|
|
8
|
+
class Ci < Default
|
|
17
9
|
def critique
|
|
18
10
|
AnalysersRunner.new(@paths).run
|
|
19
11
|
end
|
|
20
|
-
|
|
21
|
-
def report(analysed_modules)
|
|
22
|
-
Reporter.generate_report(analysed_modules)
|
|
23
|
-
end
|
|
24
12
|
end
|
|
25
13
|
end
|
|
26
14
|
end
|
|
@@ -2,17 +2,20 @@ require "rubycritic/source_control_systems/base"
|
|
|
2
2
|
require "rubycritic/analysers_runner"
|
|
3
3
|
require "rubycritic/revision_comparator"
|
|
4
4
|
require "rubycritic/reporter"
|
|
5
|
+
require "rubycritic/commands/base"
|
|
5
6
|
|
|
6
7
|
module Rubycritic
|
|
7
8
|
module Command
|
|
8
|
-
class Default
|
|
9
|
-
def initialize(
|
|
10
|
-
|
|
9
|
+
class Default < Base
|
|
10
|
+
def initialize(options)
|
|
11
|
+
super
|
|
12
|
+
@paths = options[:paths]
|
|
11
13
|
Config.source_control_system = SourceControlSystem::Base.create
|
|
12
14
|
end
|
|
13
15
|
|
|
14
16
|
def execute
|
|
15
17
|
report(critique)
|
|
18
|
+
@status_reporter
|
|
16
19
|
end
|
|
17
20
|
|
|
18
21
|
def critique
|
|
@@ -22,6 +25,7 @@ module Rubycritic
|
|
|
22
25
|
|
|
23
26
|
def report(analysed_modules)
|
|
24
27
|
Reporter.generate_report(analysed_modules)
|
|
28
|
+
@status_reporter.score = analysed_modules.score
|
|
25
29
|
end
|
|
26
30
|
end
|
|
27
31
|
end
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
+
require "rubycritic/commands/base"
|
|
2
|
+
|
|
1
3
|
module Rubycritic
|
|
2
4
|
module Command
|
|
3
|
-
class Help
|
|
4
|
-
def initialize(help_text)
|
|
5
|
-
@help_text = help_text
|
|
6
|
-
end
|
|
7
|
-
|
|
5
|
+
class Help < Base
|
|
8
6
|
def execute
|
|
9
|
-
puts @help_text
|
|
7
|
+
puts @options[:help_text]
|
|
8
|
+
@status_reporter
|
|
10
9
|
end
|
|
11
10
|
end
|
|
12
11
|
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
module Rubycritic
|
|
2
|
+
module Command
|
|
3
|
+
class StatusReporter
|
|
4
|
+
attr_reader :status, :status_message
|
|
5
|
+
SUCCESS = 0
|
|
6
|
+
SCORE_BELOW_MINIMUM = 1
|
|
7
|
+
|
|
8
|
+
def initialize(options)
|
|
9
|
+
@options = options
|
|
10
|
+
@status = SUCCESS
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def score=(score)
|
|
14
|
+
@score = score
|
|
15
|
+
update_status
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
private
|
|
19
|
+
|
|
20
|
+
def update_status
|
|
21
|
+
@status = current_status
|
|
22
|
+
update_status_message
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def current_status
|
|
26
|
+
satisfy_minimum_score_rule ? SUCCESS : SCORE_BELOW_MINIMUM
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def satisfy_minimum_score_rule
|
|
30
|
+
@score >= @options[:minimum_score]
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def update_status_message
|
|
34
|
+
case @status
|
|
35
|
+
when SUCCESS
|
|
36
|
+
@status_message = "Score: #{@score}"
|
|
37
|
+
when SCORE_BELOW_MINIMUM
|
|
38
|
+
@status_message = "Score (#{@score}) is below the minimum #{@options[:minimum_score]}"
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
data/lib/rubycritic/version.rb
CHANGED
data/rubycritic.gemspec
CHANGED
|
@@ -27,7 +27,9 @@ Gem::Specification.new do |spec|
|
|
|
27
27
|
spec.add_runtime_dependency "parser", ">= 2.2.0", "< 3.0"
|
|
28
28
|
spec.add_runtime_dependency "colorize"
|
|
29
29
|
|
|
30
|
+
spec.add_development_dependency "aruba"
|
|
30
31
|
spec.add_development_dependency "bundler", "~> 1.3"
|
|
32
|
+
spec.add_development_dependency "cucumber"
|
|
31
33
|
spec.add_development_dependency "rake"
|
|
32
34
|
spec.add_development_dependency "minitest", "~> 5.3"
|
|
33
35
|
spec.add_development_dependency "mocha", "~> 1.0"
|
|
@@ -39,13 +39,13 @@ describe Rubycritic::ModulesLocator do
|
|
|
39
39
|
end
|
|
40
40
|
|
|
41
41
|
context "when a file has no methods" do
|
|
42
|
-
it "returns the
|
|
42
|
+
it "returns the names of all the classes and modules inside the file" do
|
|
43
43
|
analysed_module = Rubycritic::AnalysedModule.new(
|
|
44
44
|
:pathname => Pathname.new("test/samples/no_methods.rb"),
|
|
45
45
|
:methods_count => 0
|
|
46
46
|
)
|
|
47
47
|
capture_output_streams do
|
|
48
|
-
Rubycritic::ModulesLocator.new(analysed_module).names.must_equal ["NoMethods"]
|
|
48
|
+
Rubycritic::ModulesLocator.new(analysed_module).names.must_equal ["Foo::NoMethods"]
|
|
49
49
|
end
|
|
50
50
|
end
|
|
51
51
|
end
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
require "test_helper"
|
|
2
|
+
require "rubycritic/commands/status_reporter"
|
|
3
|
+
require "rubycritic/cli/options"
|
|
4
|
+
|
|
5
|
+
describe Rubycritic::Command::StatusReporter do
|
|
6
|
+
let(:success_status) { Rubycritic::Command::StatusReporter::SUCCESS }
|
|
7
|
+
let(:score_below_minimum) { Rubycritic::Command::StatusReporter::SCORE_BELOW_MINIMUM }
|
|
8
|
+
|
|
9
|
+
describe "with default options" do
|
|
10
|
+
before do
|
|
11
|
+
@options = Rubycritic::Cli::Options.new([])
|
|
12
|
+
@options.parse
|
|
13
|
+
@reporter = Rubycritic::Command::StatusReporter.new(@options.to_h)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it "has a default" do
|
|
17
|
+
@reporter.status.must_equal success_status
|
|
18
|
+
@reporter.status_message.must_be_nil
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it "accept a score" do
|
|
22
|
+
@reporter.score = 50
|
|
23
|
+
@reporter.status.must_equal success_status
|
|
24
|
+
@reporter.status_message.must_equal "Score: 50"
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
describe "with minimum-score option" do
|
|
29
|
+
before do
|
|
30
|
+
@options = Rubycritic::Cli::Options.new(["-s", "99"])
|
|
31
|
+
@options.parse
|
|
32
|
+
@reporter = Rubycritic::Command::StatusReporter.new(@options.to_h)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it "has a default" do
|
|
36
|
+
@reporter.status.must_equal success_status
|
|
37
|
+
@reporter.status_message.must_be_nil
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
describe "when score is below minimum" do
|
|
41
|
+
let(:score) { 98 }
|
|
42
|
+
it "should return the correct status" do
|
|
43
|
+
@reporter.score = score
|
|
44
|
+
@reporter.status.must_equal score_below_minimum
|
|
45
|
+
@reporter.status_message.must_equal "Score (98) is below the minimum 99"
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
describe "when score is equal the minimum" do
|
|
50
|
+
let(:score) { 99 }
|
|
51
|
+
it "should return the correct status" do
|
|
52
|
+
@reporter.score = score
|
|
53
|
+
@reporter.status.must_equal success_status
|
|
54
|
+
@reporter.status_message.must_equal "Score: 99"
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
describe "when score is above the minimum" do
|
|
59
|
+
let(:score) { 100 }
|
|
60
|
+
it "should return the correct status" do
|
|
61
|
+
@reporter.score = score
|
|
62
|
+
@reporter.status.must_equal success_status
|
|
63
|
+
@reporter.status_message.must_equal "Score: 100"
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rubycritic
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.
|
|
4
|
+
version: 2.6.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Guilherme Simoes
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2016-01-
|
|
11
|
+
date: 2016-01-22 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: virtus
|
|
@@ -100,6 +100,20 @@ dependencies:
|
|
|
100
100
|
- - ">="
|
|
101
101
|
- !ruby/object:Gem::Version
|
|
102
102
|
version: '0'
|
|
103
|
+
- !ruby/object:Gem::Dependency
|
|
104
|
+
name: aruba
|
|
105
|
+
requirement: !ruby/object:Gem::Requirement
|
|
106
|
+
requirements:
|
|
107
|
+
- - ">="
|
|
108
|
+
- !ruby/object:Gem::Version
|
|
109
|
+
version: '0'
|
|
110
|
+
type: :development
|
|
111
|
+
prerelease: false
|
|
112
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
113
|
+
requirements:
|
|
114
|
+
- - ">="
|
|
115
|
+
- !ruby/object:Gem::Version
|
|
116
|
+
version: '0'
|
|
103
117
|
- !ruby/object:Gem::Dependency
|
|
104
118
|
name: bundler
|
|
105
119
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -114,6 +128,20 @@ dependencies:
|
|
|
114
128
|
- - "~>"
|
|
115
129
|
- !ruby/object:Gem::Version
|
|
116
130
|
version: '1.3'
|
|
131
|
+
- !ruby/object:Gem::Dependency
|
|
132
|
+
name: cucumber
|
|
133
|
+
requirement: !ruby/object:Gem::Requirement
|
|
134
|
+
requirements:
|
|
135
|
+
- - ">="
|
|
136
|
+
- !ruby/object:Gem::Version
|
|
137
|
+
version: '0'
|
|
138
|
+
type: :development
|
|
139
|
+
prerelease: false
|
|
140
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
141
|
+
requirements:
|
|
142
|
+
- - ">="
|
|
143
|
+
- !ruby/object:Gem::Version
|
|
144
|
+
version: '0'
|
|
117
145
|
- !ruby/object:Gem::Dependency
|
|
118
146
|
name: rake
|
|
119
147
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -189,6 +217,11 @@ files:
|
|
|
189
217
|
- README.md
|
|
190
218
|
- Rakefile
|
|
191
219
|
- bin/rubycritic
|
|
220
|
+
- features/command_line_interface/minimum_score.feature
|
|
221
|
+
- features/command_line_interface/options.feature
|
|
222
|
+
- features/step_definitions/rubycritic_steps.rb
|
|
223
|
+
- features/step_definitions/sample_file_steps.rb
|
|
224
|
+
- features/support/env.rb
|
|
192
225
|
- lib/rubycritic.rb
|
|
193
226
|
- lib/rubycritic/analysers/attributes.rb
|
|
194
227
|
- lib/rubycritic/analysers/churn.rb
|
|
@@ -208,9 +241,11 @@ files:
|
|
|
208
241
|
- lib/rubycritic/cli/options.rb
|
|
209
242
|
- lib/rubycritic/colorize.rb
|
|
210
243
|
- lib/rubycritic/command_factory.rb
|
|
244
|
+
- lib/rubycritic/commands/base.rb
|
|
211
245
|
- lib/rubycritic/commands/ci.rb
|
|
212
246
|
- lib/rubycritic/commands/default.rb
|
|
213
247
|
- lib/rubycritic/commands/help.rb
|
|
248
|
+
- lib/rubycritic/commands/status_reporter.rb
|
|
214
249
|
- lib/rubycritic/commands/version.rb
|
|
215
250
|
- lib/rubycritic/configuration.rb
|
|
216
251
|
- lib/rubycritic/core/analysed_module.rb
|
|
@@ -268,6 +303,7 @@ files:
|
|
|
268
303
|
- test/lib/rubycritic/analysers/smells/flay_test.rb
|
|
269
304
|
- test/lib/rubycritic/analysers/smells/flog_test.rb
|
|
270
305
|
- test/lib/rubycritic/analysers/smells/reek_test.rb
|
|
306
|
+
- test/lib/rubycritic/commands/status_reporter_test.rb
|
|
271
307
|
- test/lib/rubycritic/configuration_test.rb
|
|
272
308
|
- test/lib/rubycritic/core/analysed_module_test.rb
|
|
273
309
|
- test/lib/rubycritic/core/analysed_modules_collection_test.rb
|
|
@@ -298,6 +334,7 @@ files:
|
|
|
298
334
|
- test/samples/location/file_with_no_extension
|
|
299
335
|
- test/samples/methods_count.rb
|
|
300
336
|
- test/samples/module_names.rb
|
|
337
|
+
- test/samples/no_methods.rb
|
|
301
338
|
- test/samples/reek/not_smelly.rb
|
|
302
339
|
- test/samples/reek/smelly.rb
|
|
303
340
|
- test/samples/unparsable.rb
|
|
@@ -335,6 +372,7 @@ test_files:
|
|
|
335
372
|
- test/lib/rubycritic/analysers/smells/flay_test.rb
|
|
336
373
|
- test/lib/rubycritic/analysers/smells/flog_test.rb
|
|
337
374
|
- test/lib/rubycritic/analysers/smells/reek_test.rb
|
|
375
|
+
- test/lib/rubycritic/commands/status_reporter_test.rb
|
|
338
376
|
- test/lib/rubycritic/configuration_test.rb
|
|
339
377
|
- test/lib/rubycritic/core/analysed_module_test.rb
|
|
340
378
|
- test/lib/rubycritic/core/analysed_modules_collection_test.rb
|
|
@@ -365,6 +403,7 @@ test_files:
|
|
|
365
403
|
- test/samples/location/file_with_no_extension
|
|
366
404
|
- test/samples/methods_count.rb
|
|
367
405
|
- test/samples/module_names.rb
|
|
406
|
+
- test/samples/no_methods.rb
|
|
368
407
|
- test/samples/reek/not_smelly.rb
|
|
369
408
|
- test/samples/reek/smelly.rb
|
|
370
409
|
- test/samples/unparsable.rb
|