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
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
require "test_helper"
|
|
2
|
+
require "rubycritic/core/smell"
|
|
3
|
+
|
|
4
|
+
describe Rubycritic::Smell do
|
|
5
|
+
describe "attribute readers" do
|
|
6
|
+
before do
|
|
7
|
+
@locations = [Rubycritic::Location.new("./foo", "42")]
|
|
8
|
+
@context = "#bar"
|
|
9
|
+
@message = "This smells"
|
|
10
|
+
@score = 0
|
|
11
|
+
@type = :complexity
|
|
12
|
+
@smell = Rubycritic::Smell.new(
|
|
13
|
+
:locations => @locations,
|
|
14
|
+
:context => @context,
|
|
15
|
+
:message => @message,
|
|
16
|
+
:score => @score,
|
|
17
|
+
:type => @type
|
|
18
|
+
)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it "has a context reader" do
|
|
22
|
+
@smell.context.must_equal @context
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it "has a locations reader" do
|
|
26
|
+
@smell.locations.must_equal @locations
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it "has a message reader" do
|
|
30
|
+
@smell.message.must_equal @message
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it "has a score reader" do
|
|
34
|
+
@smell.score.must_equal @score
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it "has a type reader" do
|
|
38
|
+
@smell.type.must_equal @type
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
describe "#at_location?" do
|
|
43
|
+
it "returns true if the smell has a location that matches the location passed as argument" do
|
|
44
|
+
location = Rubycritic::Location.new("./foo", "42")
|
|
45
|
+
smell = Rubycritic::Smell.new(:locations => [location])
|
|
46
|
+
smell.at_location?(location).must_equal true
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
describe "#multiple_locations?" do
|
|
51
|
+
it "returns true if the smell has more than one location" do
|
|
52
|
+
location1 = Rubycritic::Location.new("./foo", "42")
|
|
53
|
+
location2 = Rubycritic::Location.new("./foo", "23")
|
|
54
|
+
smell = Rubycritic::Smell.new(:locations => [location1, location2])
|
|
55
|
+
smell.multiple_locations?.must_equal true
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
describe "#==" do
|
|
60
|
+
it "returns true if two smells have the same base attributes" 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
|
|
72
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require "test_helper"
|
|
2
|
+
require "rubycritic/generators/html/turbulence"
|
|
3
|
+
|
|
4
|
+
describe Rubycritic::Turbulence do
|
|
5
|
+
describe "::data" do
|
|
6
|
+
it "returns json data that maps pathname, churn and complexity to name, x and y" do
|
|
7
|
+
files = [AnalysedModuleDouble.new(:name => "Foo", :churn => 1, :complexity => 2)]
|
|
8
|
+
turbulence_data = Rubycritic::Turbulence.data(files)
|
|
9
|
+
instance_parsed_json = JSON.parse(turbulence_data).first
|
|
10
|
+
instance_parsed_json["name"].must_equal "Foo"
|
|
11
|
+
instance_parsed_json["x"].must_equal 1
|
|
12
|
+
instance_parsed_json["y"].must_equal 2
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
class AnalysedModuleDouble < OpenStruct; end
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
require "test_helper"
|
|
2
|
+
require "rubycritic/generators/html/view_helpers"
|
|
3
|
+
require "pathname"
|
|
4
|
+
|
|
5
|
+
describe Rubycritic::ViewHelpers do
|
|
6
|
+
context "when the file is in the root directory" do
|
|
7
|
+
let(:generator) { GeneratorDouble.new("foo.html") }
|
|
8
|
+
|
|
9
|
+
describe "#file_path" do
|
|
10
|
+
context "when the other file is in the same directory" do
|
|
11
|
+
it "creates a relative path to a file" do
|
|
12
|
+
generator.file_path("bar.html").to_s.must_equal "bar.html"
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
context "when the other file is in a subdirectory" do
|
|
17
|
+
it "creates a relative path to a file" do
|
|
18
|
+
generator.file_path("subdirectory/bar.html").to_s.must_equal "subdirectory/bar.html"
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
describe "#asset_path" do
|
|
24
|
+
it "creates a relative path to an asset" do
|
|
25
|
+
generator.asset_path("stylesheets/application.css").to_s
|
|
26
|
+
.must_equal "assets/stylesheets/application.css"
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
context "when the file is n directories deep" do
|
|
32
|
+
let(:generator) { GeneratorDouble.new("lets/go/crazy/foo.html") }
|
|
33
|
+
|
|
34
|
+
describe "#file_path" do
|
|
35
|
+
context "when the other file is in the same directory" do
|
|
36
|
+
it "creates a relative path to a file" do
|
|
37
|
+
generator.file_path("lets/go/crazy/bar.html").to_s.must_equal "bar.html"
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
context "when the other file is in the root directory" do
|
|
42
|
+
it "creates a relative path to a file" do
|
|
43
|
+
generator.file_path("bar.html").to_s.must_equal "../../../bar.html"
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
context "when the other file has n-1 directories in common" do
|
|
48
|
+
it "creates a relative path to a file" do
|
|
49
|
+
generator.file_path("lets/go/home/bar.html").to_s.must_equal "../home/bar.html"
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
context "when the other file is one directory deeper" do
|
|
54
|
+
it "creates a relative path to a file" do
|
|
55
|
+
generator.file_path("lets/go/crazy/everybody/bar.html").to_s.must_equal "everybody/bar.html"
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
describe "#asset_path" do
|
|
61
|
+
it "creates a relative path to an asset" do
|
|
62
|
+
generator.asset_path("stylesheets/application.css").to_s
|
|
63
|
+
.must_equal "../../../assets/stylesheets/application.css"
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
class GeneratorDouble
|
|
70
|
+
include Rubycritic::ViewHelpers
|
|
71
|
+
|
|
72
|
+
def initialize(file)
|
|
73
|
+
@file = Pathname.new(file)
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def file_directory
|
|
77
|
+
root_directory + @file.dirname
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def root_directory
|
|
81
|
+
Pathname.new("root_directory")
|
|
82
|
+
end
|
|
83
|
+
end
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
require "test_helper"
|
|
2
|
-
require "rubycritic/smell"
|
|
2
|
+
require "rubycritic/core/smell"
|
|
3
3
|
require "rubycritic/smells_status_setter"
|
|
4
4
|
|
|
5
5
|
describe Rubycritic::SmellsStatusSetter do
|
|
6
|
-
describe "
|
|
6
|
+
describe "::smells" do
|
|
7
7
|
before do
|
|
8
8
|
@smell = Rubycritic::Smell.new(:context => "#bar")
|
|
9
|
-
@
|
|
9
|
+
@smells = [@smell]
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
it "marks old smells" do
|
|
13
|
-
Rubycritic::SmellsStatusSetter.
|
|
13
|
+
Rubycritic::SmellsStatusSetter.set(@smells, @smells)
|
|
14
14
|
@smell.status.must_equal :old
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
it "marks new smells" do
|
|
18
|
-
Rubycritic::SmellsStatusSetter.
|
|
18
|
+
Rubycritic::SmellsStatusSetter.set([], @smells)
|
|
19
19
|
@smell.status.must_equal :new
|
|
20
20
|
end
|
|
21
21
|
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
require "test_helper"
|
|
2
|
+
require "rubycritic/source_control_systems/base"
|
|
3
|
+
|
|
4
|
+
describe Rubycritic::SourceControlSystem::Base do
|
|
5
|
+
before do
|
|
6
|
+
Rubycritic::SourceControlSystem::Base.systems.each do |system|
|
|
7
|
+
system.stubs(:supported?).returns(false)
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
describe "::create" do
|
|
12
|
+
context "when a source control system is found" do
|
|
13
|
+
it "creates an instance of that source control system" do
|
|
14
|
+
Rubycritic::SourceControlSystem::Git.stubs(:supported?).returns(true)
|
|
15
|
+
system = Rubycritic::SourceControlSystem::Base.create
|
|
16
|
+
system.must_be_instance_of Rubycritic::SourceControlSystem::Git
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
context "when no source control system is found" do
|
|
21
|
+
it "creates a source control system double" do
|
|
22
|
+
capture_output_streams do
|
|
23
|
+
system = Rubycritic::SourceControlSystem::Base.create
|
|
24
|
+
system.must_be_instance_of Rubycritic::SourceControlSystem::Double
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
require "test_helper"
|
|
2
|
+
require "rubycritic/source_control_systems/base"
|
|
3
|
+
require_relative "interfaces/basic"
|
|
4
|
+
require_relative "interfaces/time_travel"
|
|
5
|
+
|
|
6
|
+
class GitTest < Minitest::Test
|
|
7
|
+
include BasicInterface
|
|
8
|
+
include TimeTravelInterface
|
|
9
|
+
|
|
10
|
+
def setup
|
|
11
|
+
@system = Rubycritic::SourceControlSystem::Git.new
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
require "test_helper"
|
|
2
|
+
require "rubycritic/source_control_systems/base"
|
|
3
|
+
require_relative "interfaces/basic"
|
|
4
|
+
|
|
5
|
+
class MercurialTest < Minitest::Test
|
|
6
|
+
include BasicInterface
|
|
7
|
+
|
|
8
|
+
def setup
|
|
9
|
+
@system = Rubycritic::SourceControlSystem::Mercurial.new
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -3,48 +3,72 @@ require "rubycritic/source_locator"
|
|
|
3
3
|
|
|
4
4
|
describe Rubycritic::SourceLocator do
|
|
5
5
|
before do
|
|
6
|
-
@original_dir = Dir.
|
|
6
|
+
@original_dir = Dir.getwd
|
|
7
7
|
Dir.chdir("test/samples/location")
|
|
8
8
|
end
|
|
9
9
|
|
|
10
10
|
describe "#paths" do
|
|
11
|
-
it "finds a single
|
|
11
|
+
it "finds a single file" do
|
|
12
12
|
paths = ["file0.rb"]
|
|
13
13
|
Rubycritic::SourceLocator.new(paths).paths.must_equal paths
|
|
14
14
|
end
|
|
15
15
|
|
|
16
|
+
it "finds all the files inside a given directory" do
|
|
17
|
+
initial_paths = ["dir1"]
|
|
18
|
+
final_paths = ["dir1/file1.rb"]
|
|
19
|
+
Rubycritic::SourceLocator.new(initial_paths).paths.must_equal final_paths
|
|
20
|
+
end
|
|
21
|
+
|
|
16
22
|
it "finds files through multiple paths" do
|
|
17
23
|
paths = ["dir1/file1.rb", "file0.rb"]
|
|
18
|
-
Rubycritic::SourceLocator.new(paths).paths.
|
|
24
|
+
Rubycritic::SourceLocator.new(paths).paths.must_match_array paths
|
|
19
25
|
end
|
|
20
26
|
|
|
21
|
-
it "finds all the
|
|
22
|
-
|
|
23
|
-
|
|
27
|
+
it "finds all the files" do
|
|
28
|
+
initial_paths = ["."]
|
|
29
|
+
final_paths = ["dir1/file1.rb", "file0.rb", "file0_symlink.rb"]
|
|
30
|
+
Rubycritic::SourceLocator.new(initial_paths).paths.must_match_array final_paths
|
|
24
31
|
end
|
|
25
32
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
33
|
+
context "when configured to deduplicate symlinks" do
|
|
34
|
+
it "favors a file over a symlink if they both point to the same target" do
|
|
35
|
+
Rubycritic::Config.stubs(:deduplicate_symlinks).returns(true)
|
|
36
|
+
initial_paths = ["file0.rb", "file0_symlink.rb"]
|
|
37
|
+
final_paths = ["file0.rb"]
|
|
38
|
+
Rubycritic::SourceLocator.new(initial_paths).paths.must_match_array final_paths
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it "cleans paths of consecutive slashes and useless dots" do
|
|
43
|
+
initial_paths = [".//file0.rb"]
|
|
44
|
+
final_paths = ["file0.rb"]
|
|
45
|
+
Rubycritic::SourceLocator.new(initial_paths).paths.must_equal final_paths
|
|
29
46
|
end
|
|
30
47
|
|
|
31
48
|
it "ignores paths to non-existent files" do
|
|
32
|
-
|
|
33
|
-
|
|
49
|
+
initial_paths = ["non_existent_dir1/non_existent_file1.rb", "non_existent_file0.rb"]
|
|
50
|
+
final_paths = []
|
|
51
|
+
Rubycritic::SourceLocator.new(initial_paths).paths.must_equal final_paths
|
|
34
52
|
end
|
|
35
53
|
|
|
36
54
|
it "ignores paths to files that do not match the Ruby extension" do
|
|
37
|
-
|
|
38
|
-
|
|
55
|
+
initial_paths = ["file_with_no_extension", "file_with_different_extension.py"]
|
|
56
|
+
final_paths = []
|
|
57
|
+
Rubycritic::SourceLocator.new(initial_paths).paths.must_equal final_paths
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
it "can deal with nil paths" do
|
|
61
|
+
paths = nil
|
|
62
|
+
final_paths = []
|
|
63
|
+
Rubycritic::SourceLocator.new(paths).paths.must_equal final_paths
|
|
39
64
|
end
|
|
40
65
|
end
|
|
41
66
|
|
|
42
67
|
describe "#pathnames" do
|
|
43
|
-
it "finds a single
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
Rubycritic::SourceLocator.new(paths).pathnames.must_equal result
|
|
68
|
+
it "finds a single file" do
|
|
69
|
+
initial_paths = ["file0.rb"]
|
|
70
|
+
final_pathnames = [Pathname.new("file0.rb")]
|
|
71
|
+
Rubycritic::SourceLocator.new(initial_paths).pathnames.must_equal final_pathnames
|
|
48
72
|
end
|
|
49
73
|
end
|
|
50
74
|
|
|
File without changes
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
class AllTheMethods
|
|
2
|
+
def method_missing(method, *args, &block)
|
|
3
|
+
message = "I"
|
|
4
|
+
eval "message = ' did not'"
|
|
5
|
+
eval "message << ' exist,'"
|
|
6
|
+
eval "message << ' but now'"
|
|
7
|
+
eval "message << ' I do.'"
|
|
8
|
+
self.class.send(:define_method, method) { "I did not exist, but now I do." }
|
|
9
|
+
self.send(method)
|
|
10
|
+
end
|
|
11
|
+
end
|
data/test/samples/flog/smelly.rb
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
class AllTheMethods
|
|
2
2
|
def method_missing(method, *args, &block)
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
message = "I"
|
|
4
|
+
eval "message = ' did not'"
|
|
5
|
+
eval "message << ' exist,'"
|
|
6
|
+
eval "message << ' but now'"
|
|
7
|
+
eval "message << ' I do.'"
|
|
8
|
+
self.class.send(:define_method, method) { "I did not exist, but now I do." }
|
|
9
|
+
self.send(method)
|
|
5
10
|
end
|
|
6
11
|
end
|
|
File without changes
|
|
@@ -1,7 +1,35 @@
|
|
|
1
|
-
class
|
|
2
|
-
attr_reader :
|
|
1
|
+
class Perfume
|
|
2
|
+
attr_reader :perfumed
|
|
3
3
|
|
|
4
|
-
def
|
|
4
|
+
def ignoreRubyStyle(oneParameter)
|
|
5
5
|
oneVariable = oneParameter
|
|
6
6
|
end
|
|
7
|
+
|
|
8
|
+
def allow_nesting_iterators_two_levels_deep
|
|
9
|
+
loop do
|
|
10
|
+
loop do
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def allow_many_statements
|
|
16
|
+
do_something
|
|
17
|
+
do_something
|
|
18
|
+
do_something
|
|
19
|
+
do_something
|
|
20
|
+
do_something
|
|
21
|
+
do_something
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def allow_up_to_two_duplicate_method_calls
|
|
25
|
+
respond_to do |format|
|
|
26
|
+
if success
|
|
27
|
+
format.html { redirect_to some_path }
|
|
28
|
+
format.js { head :ok }
|
|
29
|
+
else
|
|
30
|
+
format.html { redirect_to :back, status: :bad_request }
|
|
31
|
+
format.js { render status: :bad_request }
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
7
35
|
end
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
unparsable :<%=
|
data/test/test_helper.rb
CHANGED
|
@@ -1,7 +1,46 @@
|
|
|
1
1
|
require "minitest/autorun"
|
|
2
2
|
require "minitest/pride"
|
|
3
3
|
require "mocha/setup"
|
|
4
|
+
require "ostruct"
|
|
4
5
|
|
|
5
6
|
def context(*args, &block)
|
|
6
7
|
describe(*args, &block)
|
|
7
8
|
end
|
|
9
|
+
|
|
10
|
+
def capture_output_streams
|
|
11
|
+
$stdout = StringIO.new
|
|
12
|
+
$stderr = StringIO.new
|
|
13
|
+
yield
|
|
14
|
+
ensure
|
|
15
|
+
$stdout = STDOUT
|
|
16
|
+
$stderr = STDERR
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
module MiniTest
|
|
20
|
+
module Assertions
|
|
21
|
+
##
|
|
22
|
+
# Fails unless <tt>exp</tt> and <tt>act</tt> are both arrays and
|
|
23
|
+
# contain the same elements.
|
|
24
|
+
#
|
|
25
|
+
# assert_matched_arrays [3,2,1], [1,2,3]
|
|
26
|
+
|
|
27
|
+
def assert_matched_arrays(exp, act)
|
|
28
|
+
exp_ary = exp.to_ary
|
|
29
|
+
assert_kind_of Array, exp_ary
|
|
30
|
+
act_ary = act.to_ary
|
|
31
|
+
assert_kind_of Array, act_ary
|
|
32
|
+
assert_equal exp_ary.sort, act_ary.sort
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
module Expectations
|
|
37
|
+
##
|
|
38
|
+
# See MiniTest::Assertions#assert_matched_arrays
|
|
39
|
+
#
|
|
40
|
+
# [1,2,3].must_match_array [3,2,1]
|
|
41
|
+
#
|
|
42
|
+
# :method: must_match_array
|
|
43
|
+
|
|
44
|
+
infect_an_assertion :assert_matched_arrays, :must_match_array
|
|
45
|
+
end
|
|
46
|
+
end
|