rubycritic 0.0.5 → 1.4.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 +593 -0
- data/.travis.yml +11 -0
- data/CHANGELOG.md +45 -0
- data/CONTRIBUTING.md +67 -15
- data/README.md +105 -14
- data/Rakefile +9 -6
- data/bin/rubycritic +3 -1
- data/lib/rubycritic/analysers/attributes.rb +21 -0
- data/lib/rubycritic/analysers/churn.rb +21 -0
- data/lib/rubycritic/analysers/complexity.rb +22 -0
- data/lib/rubycritic/analysers/helpers/ast_node.rb +69 -0
- data/lib/rubycritic/analysers/{config.reek → helpers/config.reek} +8 -0
- data/lib/rubycritic/analysers/helpers/flay.rb +13 -0
- data/lib/rubycritic/analysers/helpers/flog.rb +17 -0
- data/lib/rubycritic/analysers/helpers/methods_counter.rb +25 -0
- data/lib/rubycritic/analysers/helpers/modules_locator.rb +43 -0
- data/lib/rubycritic/analysers/helpers/parser.rb +12 -0
- data/lib/rubycritic/analysers/helpers/reek.rb +17 -0
- data/lib/rubycritic/analysers/smells/flay.rb +68 -0
- data/lib/rubycritic/analysers/smells/flog.rb +62 -0
- data/lib/rubycritic/analysers/smells/reek.rb +44 -0
- data/lib/rubycritic/analysers_runner.rb +21 -10
- data/lib/rubycritic/cli/application.rb +24 -0
- data/lib/rubycritic/cli/options.rb +79 -0
- data/lib/rubycritic/commands/ci.rb +26 -0
- data/lib/rubycritic/commands/default.rb +28 -0
- data/lib/rubycritic/commands/help.rb +13 -0
- data/lib/rubycritic/commands/version.rb +11 -0
- data/lib/rubycritic/configuration.rb +33 -0
- data/lib/rubycritic/core/analysed_module.rb +66 -0
- data/lib/rubycritic/{location.rb → core/location.rb} +17 -2
- data/lib/rubycritic/core/rating.rb +30 -0
- data/lib/rubycritic/{smell.rb → core/smell.rb} +22 -13
- data/lib/rubycritic/generators/html/assets/javascripts/application.js +104 -0
- data/lib/rubycritic/generators/html/assets/javascripts/highcharts.src-4.0.1.js +17672 -0
- data/lib/rubycritic/generators/html/assets/javascripts/jquery.floatThead-v1.2.7.js +754 -0
- data/lib/rubycritic/generators/html/assets/javascripts/jquery.scrollTo-1.4.11.js +186 -0
- data/lib/rubycritic/generators/html/assets/javascripts/jquery.tablesorter.js +2089 -0
- data/lib/rubycritic/generators/html/assets/javascripts/jquery.timeago-v1.4.1.js +214 -0
- data/lib/rubycritic/generators/html/assets/stylesheets/application.css +303 -0
- data/lib/rubycritic/{report_generators → generators/html}/assets/stylesheets/prettify.custom_theme.css +1 -4
- data/lib/rubycritic/generators/html/base.rb +52 -0
- data/lib/rubycritic/generators/html/code_file.rb +40 -0
- data/lib/rubycritic/generators/html/code_index.rb +26 -0
- data/lib/rubycritic/generators/html/line.rb +37 -0
- data/lib/rubycritic/generators/html/overview.rb +27 -0
- data/lib/rubycritic/generators/html/smells_index.rb +38 -0
- data/lib/rubycritic/generators/html/templates/code_file.html.erb +38 -0
- data/lib/rubycritic/generators/html/templates/code_index.html.erb +30 -0
- data/lib/rubycritic/generators/html/templates/layouts/application.html.erb +34 -0
- data/lib/rubycritic/generators/html/templates/overview.html.erb +5 -0
- data/lib/rubycritic/generators/html/templates/smells_index.html.erb +26 -0
- data/lib/rubycritic/{report_generators → generators/html}/templates/smelly_line.html.erb +1 -1
- data/lib/rubycritic/generators/html/turbulence.rb +17 -0
- data/lib/rubycritic/generators/html/view_helpers.rb +43 -0
- data/lib/rubycritic/generators/html_report.rb +66 -0
- data/lib/rubycritic/generators/json/simple.rb +30 -0
- data/lib/rubycritic/generators/json_report.rb +23 -0
- data/lib/rubycritic/reporter.rb +20 -0
- data/lib/rubycritic/revision_comparator.rb +27 -29
- data/lib/rubycritic/serializer.rb +32 -0
- data/lib/rubycritic/smells_status_setter.rb +7 -16
- data/lib/rubycritic/source_control_systems/base.rb +37 -0
- data/lib/rubycritic/source_control_systems/double.rb +18 -0
- data/lib/rubycritic/source_control_systems/git.rb +41 -37
- data/lib/rubycritic/source_control_systems/mercurial.rb +29 -0
- data/lib/rubycritic/source_locator.rb +25 -13
- data/lib/rubycritic/version.rb +1 -1
- data/lib/rubycritic.rb +17 -22
- data/rubycritic.gemspec +10 -7
- data/test/analysers_test_helper.rb +3 -0
- data/test/lib/rubycritic/analysers/churn_test.rb +33 -0
- data/test/lib/rubycritic/analysers/complexity_test.rb +16 -0
- data/test/lib/rubycritic/analysers/helpers/methods_counter_test.rb +29 -0
- data/test/lib/rubycritic/analysers/helpers/modules_locator_test.rb +53 -0
- data/test/lib/rubycritic/analysers/smells/flay_test.rb +39 -0
- data/test/lib/rubycritic/analysers/smells/flog_test.rb +26 -0
- data/test/lib/rubycritic/analysers/smells/reek_test.rb +33 -0
- data/test/lib/rubycritic/configuration_test.rb +29 -0
- data/test/lib/rubycritic/core/analysed_module_test.rb +88 -0
- data/test/lib/rubycritic/{location_test.rb → core/location_test.rb} +8 -4
- data/test/lib/rubycritic/core/smell_test.rb +72 -0
- data/test/lib/rubycritic/{smells_array_test.rb → core/smells_array_test.rb} +1 -1
- data/test/lib/rubycritic/report_generators/turbulence_test.rb +17 -0
- data/test/lib/rubycritic/report_generators/view_helpers_test.rb +83 -0
- data/test/lib/rubycritic/smells_status_setter_test.rb +5 -5
- data/test/lib/rubycritic/source_control_systems/base_test.rb +29 -0
- data/test/lib/rubycritic/source_control_systems/double_test.rb +11 -0
- data/test/lib/rubycritic/source_control_systems/git_test.rb +13 -0
- data/test/lib/rubycritic/source_control_systems/interfaces/basic.rb +7 -0
- data/test/lib/rubycritic/source_control_systems/interfaces/time_travel.rb +7 -0
- data/test/lib/rubycritic/source_control_systems/mercurial_test.rb +11 -0
- data/test/lib/rubycritic/source_locator_test.rb +42 -18
- data/test/lib/rubycritic/version_test.rb +1 -0
- data/test/samples/empty.rb +0 -0
- data/test/samples/flay/smelly.rb +8 -0
- data/test/samples/flay/smelly2.rb +8 -0
- data/test/samples/flog/complex.rb +11 -0
- data/test/samples/flog/smelly.rb +7 -2
- data/test/samples/location/file0_symlink.rb +0 -0
- data/test/samples/methods_count.rb +7 -0
- data/test/samples/module_names.rb +18 -0
- data/test/samples/reek/not_smelly.rb +31 -3
- data/test/samples/unparsable.rb +1 -0
- data/test/test_helper.rb +39 -0
- metadata +178 -53
- data/SPEC.md +0 -58
- data/lib/rubycritic/analysers/flog.rb +0 -20
- data/lib/rubycritic/analysers/reek.rb +0 -15
- data/lib/rubycritic/cli.rb +0 -25
- data/lib/rubycritic/report_generators/assets/javascripts/application.js +0 -25
- data/lib/rubycritic/report_generators/assets/stylesheets/application.css +0 -26
- data/lib/rubycritic/report_generators/base_generator.rb +0 -42
- data/lib/rubycritic/report_generators/file_generator.rb +0 -42
- data/lib/rubycritic/report_generators/index_generator.rb +0 -28
- data/lib/rubycritic/report_generators/line_generator.rb +0 -27
- data/lib/rubycritic/report_generators/reporter.rb +0 -45
- data/lib/rubycritic/report_generators/templates/file.html.erb +0 -3
- data/lib/rubycritic/report_generators/templates/index.html.erb +0 -14
- data/lib/rubycritic/report_generators/templates/layouts/application.html.erb +0 -19
- data/lib/rubycritic/report_generators/view_helpers.rb +0 -26
- data/lib/rubycritic/smell_adapters/flog.rb +0 -41
- data/lib/rubycritic/smell_adapters/reek.rb +0 -35
- data/lib/rubycritic/smells_aggregator.rb +0 -29
- data/lib/rubycritic/smelly_pathnames_serializer.rb +0 -34
- data/lib/rubycritic/source_control_systems/source_control_system.rb +0 -42
- data/test/lib/rubycritic/metric_adapters/flog_adapter_test.rb +0 -25
- data/test/lib/rubycritic/metric_adapters/reek_adapter_test.rb +0 -34
- data/test/lib/rubycritic/smell_test.rb +0 -71
- data/test/lib/rubycritic/smells_aggregator_test.rb +0 -47
- data/test/lib/rubycritic/source_control_systems/source_control_system_test.rb +0 -26
- /data/lib/rubycritic/{report_generators → generators/html}/assets/javascripts/jquery-2.1.0.js +0 -0
- /data/lib/rubycritic/{report_generators/assets/javascripts/prettify.js → generators/html/assets/javascripts/prettify-4-Mar-2013.js} +0 -0
- /data/lib/rubycritic/{report_generators → generators/html}/templates/line.html.erb +0 -0
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
require "rubycritic/report_generators/base_generator"
|
|
2
|
-
require "rubycritic/report_generators/file_generator"
|
|
3
|
-
require "rubycritic/report_generators/index_generator"
|
|
4
|
-
require "fileutils"
|
|
5
|
-
|
|
6
|
-
module Rubycritic
|
|
7
|
-
|
|
8
|
-
class Reporter
|
|
9
|
-
ASSETS_DIR = File.expand_path("../assets", __FILE__)
|
|
10
|
-
|
|
11
|
-
def initialize(source_pathnames, smelly_pathnames)
|
|
12
|
-
@source_pathnames = source_pathnames
|
|
13
|
-
@smelly_pathnames = smelly_pathnames
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def generate_report
|
|
17
|
-
generators.each do |generator|
|
|
18
|
-
FileUtils.mkdir_p(generator.file_directory)
|
|
19
|
-
File.open(generator.file_pathname, "w+") do |file|
|
|
20
|
-
file.write(generator.render)
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
FileUtils.cp_r(ASSETS_DIR, BaseGenerator::REPORT_DIR)
|
|
24
|
-
index_generator.file_href
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
private
|
|
28
|
-
|
|
29
|
-
def generators
|
|
30
|
-
file_generators + [index_generator]
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
def index_generator
|
|
34
|
-
@index_generator ||= IndexGenerator.new(file_generators)
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
def file_generators
|
|
38
|
-
@file_generators ||= @source_pathnames.map do |pathname|
|
|
39
|
-
file_smells = @smelly_pathnames[pathname]
|
|
40
|
-
FileGenerator.new(pathname, file_smells)
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
end
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
<table>
|
|
2
|
-
<thead>
|
|
3
|
-
<tr>
|
|
4
|
-
<th>Name</th>
|
|
5
|
-
</tr>
|
|
6
|
-
</thead>
|
|
7
|
-
<tbody>
|
|
8
|
-
<% @file_generators.each do |file_generator| %>
|
|
9
|
-
<tr>
|
|
10
|
-
<td><a href="<%= file_generator.file_pathname %>"><%= file_generator.analysed_file_name %></a></td>
|
|
11
|
-
</tr>
|
|
12
|
-
<% end %>
|
|
13
|
-
</tbody>
|
|
14
|
-
</table>
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html>
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="utf-8">
|
|
5
|
-
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
6
|
-
<title>RubyCritic</title>
|
|
7
|
-
<link href="<%= stylesheet_path(:application) %>" media="screen, projection, print" rel="stylesheet" type="text/css">
|
|
8
|
-
<link href="<%= stylesheet_path(:'prettify.custom_theme') %>" media="screen, projection, print" rel="stylesheet" type="text/css">
|
|
9
|
-
<meta name="description" content="">
|
|
10
|
-
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
11
|
-
</head>
|
|
12
|
-
<body>
|
|
13
|
-
<h1><a href="<%= index_path %>">RubyCritic</a></h1>
|
|
14
|
-
<%= yield %>
|
|
15
|
-
<script src="<%= javascript_path(:'jquery-2.1.0') %>"></script>
|
|
16
|
-
<script src="<%= javascript_path(:prettify) %>"></script>
|
|
17
|
-
<script src="<%= javascript_path(:application) %>"></script>
|
|
18
|
-
</body>
|
|
19
|
-
</html>
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
module Rubycritic
|
|
2
|
-
|
|
3
|
-
module ViewHelpers
|
|
4
|
-
def javascript_path(file)
|
|
5
|
-
asset_path(File.join("javascripts", "#{file}.js"))
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
def stylesheet_path(file)
|
|
9
|
-
asset_path(File.join("stylesheets", "#{file}.css"))
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def asset_path(file)
|
|
13
|
-
File.join(root_directory, "assets", file)
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def smell_location_path(location)
|
|
17
|
-
pathname = location.pathname
|
|
18
|
-
File.join(root_directory, File.dirname(pathname), "#{pathname.basename.sub_ext("")}.html#L#{location.line}")
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def index_path
|
|
22
|
-
File.join(root_directory, "index.html")
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
end
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
require "rubycritic/smell"
|
|
2
|
-
|
|
3
|
-
module Rubycritic
|
|
4
|
-
module SmellAdapter
|
|
5
|
-
|
|
6
|
-
class Flog
|
|
7
|
-
def initialize(flog)
|
|
8
|
-
@flog = flog
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
def smells
|
|
12
|
-
smells = []
|
|
13
|
-
@flog.each_by_score do |class_method, score|
|
|
14
|
-
smells << create_smell(class_method, score)
|
|
15
|
-
end
|
|
16
|
-
smells
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
private
|
|
20
|
-
|
|
21
|
-
def create_smell(context, score)
|
|
22
|
-
location = method_location(context)
|
|
23
|
-
message = "has a complexity of #{score.round}"
|
|
24
|
-
Smell.new(
|
|
25
|
-
:locations => [location],
|
|
26
|
-
:context => context,
|
|
27
|
-
:message => message,
|
|
28
|
-
:score => score,
|
|
29
|
-
:type => "Complexity"
|
|
30
|
-
)
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
def method_location(context)
|
|
34
|
-
line = @flog.method_locations[context]
|
|
35
|
-
file_path, file_line = line.split(":")
|
|
36
|
-
Location.new(file_path, file_line)
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
end
|
|
41
|
-
end
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
require "rubycritic/smell"
|
|
2
|
-
|
|
3
|
-
module Rubycritic
|
|
4
|
-
module SmellAdapter
|
|
5
|
-
|
|
6
|
-
class Reek
|
|
7
|
-
def initialize(reek)
|
|
8
|
-
@reek = reek
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
def smells
|
|
12
|
-
@reek.smells.map do |smell|
|
|
13
|
-
create_smell(smell)
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
private
|
|
18
|
-
|
|
19
|
-
def create_smell(smell)
|
|
20
|
-
locations = smell_locations(smell.source, smell.lines)
|
|
21
|
-
message = smell.message
|
|
22
|
-
context = smell.context
|
|
23
|
-
type = smell.subclass
|
|
24
|
-
Smell.new(:locations => locations, :context => context, :message => message, :type => type)
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def smell_locations(file_path, file_lines)
|
|
28
|
-
file_lines.uniq.sort.map do |file_line|
|
|
29
|
-
Location.new(file_path, file_line)
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
end
|
|
35
|
-
end
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
module Rubycritic
|
|
2
|
-
|
|
3
|
-
class SmellsAggregator
|
|
4
|
-
def initialize(smell_adapters)
|
|
5
|
-
@smell_adapters = smell_adapters
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
def smells
|
|
9
|
-
@smells ||= @smell_adapters.map(&:smells).flatten.sort
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def smelly_pathnames
|
|
13
|
-
@smelly_pathnames ||= pathnames_to_files_with_smells
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
private
|
|
17
|
-
|
|
18
|
-
def pathnames_to_files_with_smells
|
|
19
|
-
pathnames = Hash.new { |hash, key| hash[key] = [] }
|
|
20
|
-
smells.each do |smell|
|
|
21
|
-
smell.pathnames.each do |path|
|
|
22
|
-
pathnames[path] << smell
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
pathnames
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
end
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
require "fileutils"
|
|
2
|
-
|
|
3
|
-
module Rubycritic
|
|
4
|
-
|
|
5
|
-
class SmellyPathnamesSerializer
|
|
6
|
-
def initialize(file_name)
|
|
7
|
-
@file_name = file_name
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
def load
|
|
11
|
-
Marshal.load(File.read(@file_name))
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def dump(smelly_pathnames)
|
|
15
|
-
create_file_directory
|
|
16
|
-
# HACK It's not possible to Marshal procs or lambdas.
|
|
17
|
-
smelly_pathnames.default = []
|
|
18
|
-
File.open(@file_name, "w+") do |file|
|
|
19
|
-
Marshal.dump(smelly_pathnames, file)
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
private
|
|
24
|
-
|
|
25
|
-
def create_file_directory
|
|
26
|
-
FileUtils.mkdir_p(file_directory)
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
def file_directory
|
|
30
|
-
File.dirname(@file_name)
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
end
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
module Rubycritic
|
|
2
|
-
|
|
3
|
-
class SourceControlSystem
|
|
4
|
-
@@systems = []
|
|
5
|
-
|
|
6
|
-
def self.register_system
|
|
7
|
-
@@systems << self
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
def self.create
|
|
11
|
-
supported_system = systems.detect(&:supported?)
|
|
12
|
-
if supported_system
|
|
13
|
-
supported_system.new
|
|
14
|
-
else
|
|
15
|
-
raise "Rubycritic requires a #{system_names} repository."
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def self.systems
|
|
20
|
-
@@systems
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def self.system_names
|
|
24
|
-
systems.join(", ")
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def has_revision?
|
|
28
|
-
raise NotImplementedError.new("You must implement the has_revision? method.")
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def head_reference
|
|
32
|
-
raise NotImplementedError.new("You must implement the head_reference method.")
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def travel_to_head
|
|
36
|
-
raise NotImplementedError.new("You must implement the travel_to_head method.")
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
require "rubycritic/source_control_systems/git"
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
require "test_helper"
|
|
2
|
-
require "rubycritic/analysers/flog"
|
|
3
|
-
require "rubycritic/smell_adapters/flog"
|
|
4
|
-
|
|
5
|
-
describe Rubycritic::SmellAdapter::Flog do
|
|
6
|
-
before do
|
|
7
|
-
sample_path = "test/samples/flog/smelly.rb"
|
|
8
|
-
flog = Rubycritic::Analyser::Flog.new([sample_path])
|
|
9
|
-
@adapter = Rubycritic::SmellAdapter::Flog.new(flog)
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
it "detects smells" do
|
|
13
|
-
@adapter.smells.wont_be_empty
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
it "has smells with messages" do
|
|
17
|
-
smell = @adapter.smells.first
|
|
18
|
-
smell.message.must_equal "has a complexity of 8"
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
it "has smells with scores" do
|
|
22
|
-
smell = @adapter.smells.first
|
|
23
|
-
smell.score.must_be_kind_of Numeric
|
|
24
|
-
end
|
|
25
|
-
end
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
require "test_helper"
|
|
2
|
-
require "rubycritic/analysers/reek"
|
|
3
|
-
require "rubycritic/smell_adapters/reek"
|
|
4
|
-
|
|
5
|
-
describe Rubycritic::SmellAdapter::Reek do
|
|
6
|
-
context "when analysing a smelly file" do
|
|
7
|
-
before do
|
|
8
|
-
sample_path = "test/samples/reek/smelly.rb"
|
|
9
|
-
reek = Rubycritic::Analyser::Reek.new([sample_path])
|
|
10
|
-
@adapter = Rubycritic::SmellAdapter::Reek.new(reek)
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
it "detects smells" do
|
|
14
|
-
@adapter.smells.wont_be_empty
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
it "has smells with messages" do
|
|
18
|
-
smell = @adapter.smells.first
|
|
19
|
-
smell.message.must_equal "has boolean parameter 'reek'"
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
context "when analysing a file with smells ignored in config.reek" do
|
|
24
|
-
before do
|
|
25
|
-
sample_path = "test/samples/reek/not_smelly.rb"
|
|
26
|
-
reek = Rubycritic::Analyser::Reek.new([sample_path])
|
|
27
|
-
@adapter = Rubycritic::SmellAdapter::Reek.new(reek)
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
it "does not detect smells" do
|
|
31
|
-
@adapter.smells.must_be_empty
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
end
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
require "test_helper"
|
|
2
|
-
require "rubycritic/smell"
|
|
3
|
-
|
|
4
|
-
describe Rubycritic::Smell do
|
|
5
|
-
it "has a context reader" do
|
|
6
|
-
context = "#bar"
|
|
7
|
-
smell = Rubycritic::Smell.new(:context => context)
|
|
8
|
-
smell.context.must_equal context
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
it "has a locations reader" do
|
|
12
|
-
location = Rubycritic::Location.new("./foo", "42")
|
|
13
|
-
smell = Rubycritic::Smell.new(:locations => [location])
|
|
14
|
-
smell.locations.must_equal [location]
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
it "has a pathnames reader" do
|
|
18
|
-
path = Pathname.new("./foo")
|
|
19
|
-
location1 = Rubycritic::Location.new("./foo", "42")
|
|
20
|
-
location2 = Rubycritic::Location.new("./foo", "23")
|
|
21
|
-
smell = Rubycritic::Smell.new(:locations => [location1, location2])
|
|
22
|
-
smell.pathnames.must_equal [path]
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
it "has a message reader" do
|
|
26
|
-
message = "This smells"
|
|
27
|
-
smell = Rubycritic::Smell.new(:message => message)
|
|
28
|
-
smell.message.must_equal message
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
it "has a score reader" do
|
|
32
|
-
score = 0
|
|
33
|
-
smell = Rubycritic::Smell.new(:score => score)
|
|
34
|
-
smell.score.must_equal score
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
it "has a type reader" do
|
|
38
|
-
type = :complexity
|
|
39
|
-
smell = Rubycritic::Smell.new(:type => type)
|
|
40
|
-
smell.type.must_equal type
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
describe "#located_in?" do
|
|
44
|
-
it "returns true if the smell has a location that matches the location passed as argument" do
|
|
45
|
-
location = Rubycritic::Location.new("./foo", "42")
|
|
46
|
-
smell = Rubycritic::Smell.new(:locations => [location])
|
|
47
|
-
smell.located_in?(location).must_equal true
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
describe "#has_multiple_locations?" do
|
|
52
|
-
it "returns true if the smell has more than one location" do
|
|
53
|
-
location1 = Rubycritic::Location.new("./foo", "42")
|
|
54
|
-
location2 = Rubycritic::Location.new("./foo", "23")
|
|
55
|
-
smell = Rubycritic::Smell.new(:locations => [location1, location2])
|
|
56
|
-
smell.has_multiple_locations?.must_equal true
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
it "is comparable" do
|
|
61
|
-
attributes = {
|
|
62
|
-
:context => "#bar",
|
|
63
|
-
:message => "This smells",
|
|
64
|
-
:score => 0,
|
|
65
|
-
:type => :complexity
|
|
66
|
-
}
|
|
67
|
-
smell1 = Rubycritic::Smell.new(attributes)
|
|
68
|
-
smell2 = Rubycritic::Smell.new(attributes)
|
|
69
|
-
smell1.must_equal smell2
|
|
70
|
-
end
|
|
71
|
-
end
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
require "test_helper"
|
|
2
|
-
require "rubycritic/smells_aggregator"
|
|
3
|
-
|
|
4
|
-
describe Rubycritic::SmellsAggregator do
|
|
5
|
-
context "when when analysing smelly files" do
|
|
6
|
-
before do
|
|
7
|
-
@location1 = Rubycritic::Location.new("./foo", "42")
|
|
8
|
-
@location2 = Rubycritic::Location.new("./bar", "23")
|
|
9
|
-
@location3 = Rubycritic::Location.new("./bar", "16")
|
|
10
|
-
@smell1 = Rubycritic::Smell.new(:locations => [@location1])
|
|
11
|
-
@smell2 = Rubycritic::Smell.new(:locations => [@location2, @location3])
|
|
12
|
-
@smell_adapters = [stub(:smells => [@smell1]), stub(:smells => [@smell2])]
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
describe "#smells" do
|
|
16
|
-
it "returns the smells found in those files" do
|
|
17
|
-
smells = [@smell2, @smell1]
|
|
18
|
-
Rubycritic::SmellsAggregator.new(@smell_adapters).smells.must_equal smells
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
describe "#smelly_pathnames" do
|
|
23
|
-
it "returns the files where smells were found" do
|
|
24
|
-
smelly_pathnames = {@location1.pathname => [@smell1], @location2.pathname => [@smell2]}
|
|
25
|
-
Rubycritic::SmellsAggregator.new(@smell_adapters).smelly_pathnames.must_equal smelly_pathnames
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
context "when analysing files with no smells" do
|
|
31
|
-
before do
|
|
32
|
-
@smell_adapters = [stub(:smells => [])]
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
describe "#smells" do
|
|
36
|
-
it "returns an empty array" do
|
|
37
|
-
Rubycritic::SmellsAggregator.new(@smell_adapters).smells.must_equal []
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
describe "#smelly_pathnames" do
|
|
42
|
-
it "returns an empty hash" do
|
|
43
|
-
Rubycritic::SmellsAggregator.new(@smell_adapters).smelly_pathnames.must_equal({})
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
end
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
require "test_helper"
|
|
2
|
-
require "rubycritic/source_control_systems/source_control_system"
|
|
3
|
-
|
|
4
|
-
describe Rubycritic::SourceControlSystem do
|
|
5
|
-
before do
|
|
6
|
-
Rubycritic::SourceControlSystem.systems.each do |system|
|
|
7
|
-
system.stubs(:supported?).returns(false)
|
|
8
|
-
end
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
describe "::create" do
|
|
12
|
-
describe "when a source control system is found" do
|
|
13
|
-
it "creates an instance of that source control system" do
|
|
14
|
-
Rubycritic::Git.stubs(:supported?).returns(true)
|
|
15
|
-
system = Rubycritic::SourceControlSystem.create
|
|
16
|
-
system.must_be_instance_of Rubycritic::Git
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
describe "when no source control system is found" do
|
|
21
|
-
it "raises an error" do
|
|
22
|
-
proc { Rubycritic::SourceControlSystem.create }.must_raise RuntimeError
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
end
|
/data/lib/rubycritic/{report_generators → generators/html}/assets/javascripts/jquery-2.1.0.js
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|