rubycritic 2.9.2 → 2.9.3
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/.gitignore +1 -0
- data/.rubocop_todo.yml +6 -0
- data/.todo.reek +111 -108
- data/CHANGELOG.md +5 -0
- data/README.md +1 -1
- data/Rakefile +1 -1
- data/bin/rubycritic +1 -1
- data/features/command_line_interface/minimum_score.feature +1 -1
- data/features/command_line_interface/options.feature +2 -2
- data/features/rake_task.feature +5 -5
- data/features/step_definitions/rubycritic_steps.rb +4 -4
- data/features/support/env.rb +2 -2
- data/lib/rubycritic/analysers/attributes.rb +1 -1
- data/lib/rubycritic/analysers/churn.rb +1 -1
- data/lib/rubycritic/analysers/complexity.rb +1 -1
- data/lib/rubycritic/analysers/helpers/ast_node.rb +1 -1
- data/lib/rubycritic/analysers/helpers/flay.rb +1 -1
- data/lib/rubycritic/analysers/helpers/flog.rb +1 -1
- data/lib/rubycritic/analysers/helpers/methods_counter.rb +1 -1
- data/lib/rubycritic/analysers/helpers/modules_locator.rb +1 -1
- data/lib/rubycritic/analysers/helpers/parser.rb +1 -1
- data/lib/rubycritic/analysers/helpers/reek.rb +1 -1
- data/lib/rubycritic/analysers/smells/flay.rb +1 -1
- data/lib/rubycritic/analysers/smells/flog.rb +1 -1
- data/lib/rubycritic/analysers/smells/reek.rb +1 -1
- data/lib/rubycritic/analysers_runner.rb +1 -1
- data/lib/rubycritic/browser.rb +1 -1
- data/lib/rubycritic/cli/application.rb +2 -2
- data/lib/rubycritic/cli/options.rb +1 -1
- data/lib/rubycritic/colorize.rb +1 -1
- data/lib/rubycritic/command_factory.rb +1 -1
- data/lib/rubycritic/commands/base.rb +2 -2
- data/lib/rubycritic/commands/ci.rb +1 -1
- data/lib/rubycritic/commands/default.rb +1 -1
- data/lib/rubycritic/commands/help.rb +1 -1
- data/lib/rubycritic/commands/status_reporter.rb +1 -1
- data/lib/rubycritic/commands/version.rb +1 -1
- data/lib/rubycritic/configuration.rb +5 -1
- data/lib/rubycritic/core/analysed_module.rb +2 -2
- data/lib/rubycritic/core/analysed_modules_collection.rb +1 -1
- data/lib/rubycritic/core/location.rb +1 -1
- data/lib/rubycritic/core/rating.rb +1 -1
- data/lib/rubycritic/core/smell.rb +1 -1
- data/lib/rubycritic/generators/console_report.rb +1 -1
- data/lib/rubycritic/generators/html/assets/javascripts/jquery-2.1.0.js +1 -1
- data/lib/rubycritic/generators/html/base.rb +1 -1
- data/lib/rubycritic/generators/html/code_file.rb +1 -1
- data/lib/rubycritic/generators/html/code_index.rb +1 -1
- data/lib/rubycritic/generators/html/line.rb +1 -1
- data/lib/rubycritic/generators/html/overview.rb +1 -1
- data/lib/rubycritic/generators/html/smells_index.rb +1 -1
- data/lib/rubycritic/generators/html/turbulence.rb +1 -1
- data/lib/rubycritic/generators/html/view_helpers.rb +1 -1
- data/lib/rubycritic/generators/html_report.rb +2 -2
- data/lib/rubycritic/generators/json/simple.rb +13 -2
- data/lib/rubycritic/generators/json_report.rb +5 -2
- data/lib/rubycritic/generators/text/list.rb +1 -1
- data/lib/rubycritic/rake_task.rb +2 -2
- data/lib/rubycritic/reporter.rb +1 -1
- data/lib/rubycritic/revision_comparator.rb +1 -1
- data/lib/rubycritic/serializer.rb +1 -1
- data/lib/rubycritic/smells_status_setter.rb +1 -1
- data/lib/rubycritic/source_control_systems/base.rb +1 -1
- data/lib/rubycritic/source_control_systems/double.rb +1 -1
- data/lib/rubycritic/source_control_systems/git.rb +1 -1
- data/lib/rubycritic/source_control_systems/mercurial.rb +1 -1
- data/lib/rubycritic/source_locator.rb +1 -1
- data/lib/rubycritic/version.rb +2 -2
- data/lib/rubycritic.rb +1 -1
- data/rubycritic.gemspec +2 -1
- data/test/lib/rubycritic/analysers/churn_test.rb +3 -3
- data/test/lib/rubycritic/analysers/complexity_test.rb +2 -2
- data/test/lib/rubycritic/analysers/helpers/methods_counter_test.rb +4 -4
- data/test/lib/rubycritic/analysers/helpers/modules_locator_test.rb +9 -9
- data/test/lib/rubycritic/analysers/smells/flay_test.rb +4 -4
- data/test/lib/rubycritic/analysers/smells/flog_test.rb +2 -2
- data/test/lib/rubycritic/analysers/smells/reek_test.rb +2 -2
- data/test/lib/rubycritic/browser_test.rb +2 -2
- data/test/lib/rubycritic/commands/status_reporter_test.rb +7 -7
- data/test/lib/rubycritic/configuration_test.rb +9 -9
- data/test/lib/rubycritic/core/analysed_module_test.rb +9 -9
- data/test/lib/rubycritic/core/analysed_modules_collection_test.rb +3 -3
- data/test/lib/rubycritic/core/location_test.rb +7 -7
- data/test/lib/rubycritic/core/smell_test.rb +15 -15
- data/test/lib/rubycritic/core/smells_array_test.rb +12 -12
- data/test/lib/rubycritic/generators/console_report_test.rb +5 -5
- data/test/lib/rubycritic/generators/json_report_test.rb +36 -0
- data/test/lib/rubycritic/generators/turbulence_test.rb +2 -2
- data/test/lib/rubycritic/generators/view_helpers_test.rb +2 -2
- data/test/lib/rubycritic/revision_comparator_test.rb +10 -10
- data/test/lib/rubycritic/smells_status_setter_test.rb +4 -4
- data/test/lib/rubycritic/source_control_systems/base_test.rb +7 -7
- data/test/lib/rubycritic/source_control_systems/double_test.rb +1 -1
- data/test/lib/rubycritic/source_control_systems/git_test.rb +1 -1
- data/test/lib/rubycritic/source_control_systems/mercurial_test.rb +1 -1
- data/test/lib/rubycritic/source_locator_test.rb +12 -12
- data/test/lib/rubycritic/version_test.rb +2 -2
- metadata +18 -2
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
require 'test_helper'
|
|
2
2
|
require 'rubycritic/configuration'
|
|
3
3
|
|
|
4
|
-
describe
|
|
4
|
+
describe RubyCritic::Configuration do
|
|
5
5
|
describe '#root' do
|
|
6
6
|
before do
|
|
7
|
-
|
|
8
|
-
@default =
|
|
7
|
+
RubyCritic::Config.set
|
|
8
|
+
@default = RubyCritic::Config.root
|
|
9
9
|
end
|
|
10
10
|
|
|
11
11
|
it 'has a default' do
|
|
12
|
-
|
|
12
|
+
RubyCritic::Config.root.must_be_instance_of String
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
it 'can be set to a relative path' do
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
RubyCritic::Config.root = 'foo'
|
|
17
|
+
RubyCritic::Config.root.must_equal File.expand_path('foo')
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
it 'can be set to an absolute path' do
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
RubyCritic::Config.root = '/foo'
|
|
22
|
+
RubyCritic::Config.root.must_equal '/foo'
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
after do
|
|
26
|
-
|
|
26
|
+
RubyCritic::Config.root = @default
|
|
27
27
|
end
|
|
28
28
|
end
|
|
29
29
|
end
|
|
@@ -2,7 +2,7 @@ require 'test_helper'
|
|
|
2
2
|
require 'rubycritic/core/analysed_module'
|
|
3
3
|
require 'rubycritic/core/smell'
|
|
4
4
|
|
|
5
|
-
describe
|
|
5
|
+
describe RubyCritic::AnalysedModule do
|
|
6
6
|
describe 'attribute readers' do
|
|
7
7
|
before do
|
|
8
8
|
@name = 'Foo'
|
|
@@ -10,7 +10,7 @@ describe Rubycritic::AnalysedModule do
|
|
|
10
10
|
@smells = []
|
|
11
11
|
@churn = 1
|
|
12
12
|
@complexity = 2
|
|
13
|
-
@analysed_module =
|
|
13
|
+
@analysed_module = RubyCritic::AnalysedModule.new(
|
|
14
14
|
name: @name,
|
|
15
15
|
pathname: @pathname,
|
|
16
16
|
smells: @smells,
|
|
@@ -47,7 +47,7 @@ describe Rubycritic::AnalysedModule do
|
|
|
47
47
|
describe '#cost' do
|
|
48
48
|
it 'returns the remediation cost of fixing the analysed_module' do
|
|
49
49
|
smells = [SmellDouble.new(cost: 1), SmellDouble.new(cost: 2)]
|
|
50
|
-
analysed_module =
|
|
50
|
+
analysed_module = RubyCritic::AnalysedModule.new(smells: smells, complexity: 0)
|
|
51
51
|
analysed_module.cost.must_equal 3
|
|
52
52
|
end
|
|
53
53
|
end
|
|
@@ -55,14 +55,14 @@ describe Rubycritic::AnalysedModule do
|
|
|
55
55
|
describe '#complexity_per_method' do
|
|
56
56
|
context 'when the file has no methods' do
|
|
57
57
|
it 'returns a placeholder' do
|
|
58
|
-
analysed_module =
|
|
58
|
+
analysed_module = RubyCritic::AnalysedModule.new(complexity: 0, methods_count: 0)
|
|
59
59
|
analysed_module.complexity_per_method.must_equal 'N/A'
|
|
60
60
|
end
|
|
61
61
|
end
|
|
62
62
|
|
|
63
63
|
context 'when the file has at least one method' do
|
|
64
64
|
it 'returns the average complexity per method' do
|
|
65
|
-
analysed_module =
|
|
65
|
+
analysed_module = RubyCritic::AnalysedModule.new(complexity: 10, methods_count: 2)
|
|
66
66
|
analysed_module.complexity_per_method.must_equal 5
|
|
67
67
|
end
|
|
68
68
|
end
|
|
@@ -70,16 +70,16 @@ describe Rubycritic::AnalysedModule do
|
|
|
70
70
|
|
|
71
71
|
describe '#smells?' do
|
|
72
72
|
it 'returns true if the analysed_module has at least one smell' do
|
|
73
|
-
analysed_module =
|
|
73
|
+
analysed_module = RubyCritic::AnalysedModule.new(smells: [SmellDouble.new])
|
|
74
74
|
analysed_module.smells?.must_equal true
|
|
75
75
|
end
|
|
76
76
|
end
|
|
77
77
|
|
|
78
78
|
describe '#smells_at_location' do
|
|
79
79
|
it 'returns the smells of an analysed_module at a certain location' do
|
|
80
|
-
location =
|
|
81
|
-
smells = [
|
|
82
|
-
analysed_module =
|
|
80
|
+
location = RubyCritic::Location.new('./foo', '42')
|
|
81
|
+
smells = [RubyCritic::Smell.new(locations: [location])]
|
|
82
|
+
analysed_module = RubyCritic::AnalysedModule.new(smells: smells)
|
|
83
83
|
analysed_module.smells_at_location(location).must_equal smells
|
|
84
84
|
end
|
|
85
85
|
end
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
require 'test_helper'
|
|
2
2
|
require 'rubycritic/core/analysed_modules_collection'
|
|
3
3
|
|
|
4
|
-
describe
|
|
5
|
-
subject {
|
|
4
|
+
describe RubyCritic::AnalysedModulesCollection do
|
|
5
|
+
subject { RubyCritic::AnalysedModulesCollection.new(paths) }
|
|
6
6
|
|
|
7
7
|
describe '.new' do
|
|
8
8
|
context 'with an empty path' do
|
|
@@ -18,7 +18,7 @@ describe Rubycritic::AnalysedModulesCollection do
|
|
|
18
18
|
|
|
19
19
|
it 'registers one AnalysedModule element per existent file' do
|
|
20
20
|
subject.count.must_equal 2
|
|
21
|
-
subject.all? { |a| a.is_a?(
|
|
21
|
+
subject.all? { |a| a.is_a?(RubyCritic::AnalysedModule) }.must_equal true
|
|
22
22
|
end
|
|
23
23
|
end
|
|
24
24
|
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
require 'test_helper'
|
|
2
2
|
require 'rubycritic/core/location'
|
|
3
3
|
|
|
4
|
-
describe
|
|
4
|
+
describe RubyCritic::Location do
|
|
5
5
|
describe 'attribute readers' do
|
|
6
6
|
before do
|
|
7
7
|
@path = './foo.rb'
|
|
8
8
|
@line = '42'
|
|
9
|
-
@location =
|
|
9
|
+
@location = RubyCritic::Location.new(@path, @line)
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
it 'has a pathname' do
|
|
@@ -23,15 +23,15 @@ describe Rubycritic::Location do
|
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
it 'is comparable' do
|
|
26
|
-
location1 =
|
|
27
|
-
location2 =
|
|
26
|
+
location1 = RubyCritic::Location.new('./foo', 42)
|
|
27
|
+
location2 = RubyCritic::Location.new('./foo', 42)
|
|
28
28
|
location1.must_equal location2
|
|
29
29
|
end
|
|
30
30
|
|
|
31
31
|
it 'is sortable' do
|
|
32
|
-
location1 =
|
|
33
|
-
location2 =
|
|
34
|
-
location3 =
|
|
32
|
+
location1 = RubyCritic::Location.new('./foo', 42)
|
|
33
|
+
location2 = RubyCritic::Location.new('./bar', 23)
|
|
34
|
+
location3 = RubyCritic::Location.new('./bar', 16)
|
|
35
35
|
[location1, location2, location3].sort.must_equal [location3, location2, location1]
|
|
36
36
|
end
|
|
37
37
|
end
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
require 'test_helper'
|
|
2
2
|
require 'rubycritic/core/smell'
|
|
3
3
|
|
|
4
|
-
describe
|
|
4
|
+
describe RubyCritic::Smell do
|
|
5
5
|
describe 'attribute readers' do
|
|
6
6
|
before do
|
|
7
|
-
@locations = [
|
|
7
|
+
@locations = [RubyCritic::Location.new('./foo', '42')]
|
|
8
8
|
@context = '#bar'
|
|
9
9
|
@message = 'This smells'
|
|
10
10
|
@score = 0
|
|
11
11
|
@type = :complexity
|
|
12
|
-
@smell =
|
|
12
|
+
@smell = RubyCritic::Smell.new(
|
|
13
13
|
locations: @locations,
|
|
14
14
|
context: @context,
|
|
15
15
|
message: @message,
|
|
@@ -41,17 +41,17 @@ describe Rubycritic::Smell do
|
|
|
41
41
|
|
|
42
42
|
describe '#at_location?' do
|
|
43
43
|
it 'returns true if the smell has a location that matches the location passed as argument' do
|
|
44
|
-
location =
|
|
45
|
-
smell =
|
|
44
|
+
location = RubyCritic::Location.new('./foo', '42')
|
|
45
|
+
smell = RubyCritic::Smell.new(locations: [location])
|
|
46
46
|
smell.at_location?(location).must_equal true
|
|
47
47
|
end
|
|
48
48
|
end
|
|
49
49
|
|
|
50
50
|
describe '#multiple_locations?' do
|
|
51
51
|
it 'returns true if the smell has more than one location' do
|
|
52
|
-
location1 =
|
|
53
|
-
location2 =
|
|
54
|
-
smell =
|
|
52
|
+
location1 = RubyCritic::Location.new('./foo', '42')
|
|
53
|
+
location2 = RubyCritic::Location.new('./foo', '23')
|
|
54
|
+
smell = RubyCritic::Smell.new(locations: [location1, location2])
|
|
55
55
|
smell.multiple_locations?.must_equal true
|
|
56
56
|
end
|
|
57
57
|
end
|
|
@@ -64,39 +64,39 @@ describe Rubycritic::Smell do
|
|
|
64
64
|
score: 0,
|
|
65
65
|
type: :complexity
|
|
66
66
|
}
|
|
67
|
-
smell1 =
|
|
68
|
-
smell2 =
|
|
67
|
+
smell1 = RubyCritic::Smell.new(attributes)
|
|
68
|
+
smell2 = RubyCritic::Smell.new(attributes)
|
|
69
69
|
smell1.must_equal smell2
|
|
70
70
|
end
|
|
71
71
|
end
|
|
72
72
|
|
|
73
73
|
describe '#doc_url' do
|
|
74
74
|
it 'handles one word type names for reek smells' do
|
|
75
|
-
smell =
|
|
75
|
+
smell = RubyCritic::Smell.new(type: 'Complexity', analyser: 'reek')
|
|
76
76
|
|
|
77
77
|
smell.doc_url.must_equal('https://github.com/troessner/reek/blob/master/docs/Complexity.md')
|
|
78
78
|
end
|
|
79
79
|
|
|
80
80
|
it 'handles multiple word type names for reek smells' do
|
|
81
|
-
smell =
|
|
81
|
+
smell = RubyCritic::Smell.new(type: 'TooManyStatements', analyser: 'reek')
|
|
82
82
|
|
|
83
83
|
smell.doc_url.must_equal('https://github.com/troessner/reek/blob/master/docs/Too-Many-Statements.md')
|
|
84
84
|
end
|
|
85
85
|
|
|
86
86
|
it 'handles flay smells' do
|
|
87
|
-
smell =
|
|
87
|
+
smell = RubyCritic::Smell.new(type: 'DuplicateCode', analyser: 'flay')
|
|
88
88
|
|
|
89
89
|
smell.doc_url.must_equal('http://docs.seattlerb.org/flay/')
|
|
90
90
|
end
|
|
91
91
|
|
|
92
92
|
it 'handles flog smells' do
|
|
93
|
-
smell =
|
|
93
|
+
smell = RubyCritic::Smell.new(type: 'VeryHighComplexity', analyser: 'flog')
|
|
94
94
|
|
|
95
95
|
smell.doc_url.must_equal('http://docs.seattlerb.org/flog/')
|
|
96
96
|
end
|
|
97
97
|
|
|
98
98
|
it 'raises an error for unknown analysers' do
|
|
99
|
-
smell =
|
|
99
|
+
smell = RubyCritic::Smell.new(type: 'FooSmell', analyser: 'foo')
|
|
100
100
|
assert_raises { smell.doc_url }
|
|
101
101
|
end
|
|
102
102
|
end
|
|
@@ -3,26 +3,26 @@ require 'rubycritic/core/smell'
|
|
|
3
3
|
|
|
4
4
|
describe 'Array of Smells' do
|
|
5
5
|
it 'is sortable' do
|
|
6
|
-
location1 =
|
|
7
|
-
location2 =
|
|
8
|
-
location3 =
|
|
9
|
-
smell1 =
|
|
10
|
-
smell2 =
|
|
11
|
-
smell3 =
|
|
6
|
+
location1 = RubyCritic::Location.new('./foo', 42)
|
|
7
|
+
location2 = RubyCritic::Location.new('./bar', 23)
|
|
8
|
+
location3 = RubyCritic::Location.new('./bar', 16)
|
|
9
|
+
smell1 = RubyCritic::Smell.new(locations: [location1])
|
|
10
|
+
smell2 = RubyCritic::Smell.new(locations: [location2])
|
|
11
|
+
smell3 = RubyCritic::Smell.new(locations: [location3])
|
|
12
12
|
[smell1, smell2, smell3].sort.must_equal [smell3, smell2, smell1]
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
it 'implements set intersection' do
|
|
16
|
-
smell1 =
|
|
17
|
-
smell2 =
|
|
18
|
-
smell3 =
|
|
16
|
+
smell1 = RubyCritic::Smell.new(context: '#bar')
|
|
17
|
+
smell2 = RubyCritic::Smell.new(context: '#bar')
|
|
18
|
+
smell3 = RubyCritic::Smell.new(context: '#foo')
|
|
19
19
|
([smell1, smell3] & [smell2]).must_equal [smell1]
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
it 'implements set union' do
|
|
23
|
-
smell1 =
|
|
24
|
-
smell2 =
|
|
25
|
-
smell3 =
|
|
23
|
+
smell1 = RubyCritic::Smell.new(context: '#bar')
|
|
24
|
+
smell2 = RubyCritic::Smell.new(context: '#bar')
|
|
25
|
+
smell3 = RubyCritic::Smell.new(context: '#foo')
|
|
26
26
|
([smell1, smell3] | [smell2]).must_equal [smell1, smell3]
|
|
27
27
|
end
|
|
28
28
|
end
|
|
@@ -3,12 +3,12 @@ require 'rubycritic/generators/console_report'
|
|
|
3
3
|
require 'rubycritic/core/rating'
|
|
4
4
|
require 'rubycritic/core/smell'
|
|
5
5
|
|
|
6
|
-
describe
|
|
6
|
+
describe RubyCritic::Generator::ConsoleReport do
|
|
7
7
|
describe '#generate_report' do
|
|
8
8
|
before do
|
|
9
9
|
@mock_analysed_module = mock_analysed_module
|
|
10
10
|
capture_output_streams do
|
|
11
|
-
report =
|
|
11
|
+
report = RubyCritic::Generator::ConsoleReport.new([@mock_analysed_module])
|
|
12
12
|
report.generate_report
|
|
13
13
|
@output = $stdout.tap(&:rewind).read
|
|
14
14
|
end
|
|
@@ -61,7 +61,7 @@ describe Rubycritic::Generator::ConsoleReport do
|
|
|
61
61
|
def mock_analysed_module
|
|
62
62
|
OpenStruct.new(
|
|
63
63
|
name: 'TestModule',
|
|
64
|
-
rating:
|
|
64
|
+
rating: RubyCritic::Rating.from_cost(3),
|
|
65
65
|
churn: 10,
|
|
66
66
|
complexity: 0,
|
|
67
67
|
duplication: 20,
|
|
@@ -70,8 +70,8 @@ describe Rubycritic::Generator::ConsoleReport do
|
|
|
70
70
|
end
|
|
71
71
|
|
|
72
72
|
def mock_smell
|
|
73
|
-
smell =
|
|
74
|
-
smell.locations <<
|
|
73
|
+
smell = RubyCritic::Smell.new
|
|
74
|
+
smell.locations << RubyCritic::Location.new(__FILE__, 3)
|
|
75
75
|
smell.type = 'SmellySmell'
|
|
76
76
|
smell.context = 'You'
|
|
77
77
|
smell.message = 'Seriously, take a shower or something'
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
require 'rubycritic/core/analysed_modules_collection'
|
|
3
|
+
require 'rubycritic/generators/json_report'
|
|
4
|
+
require 'json'
|
|
5
|
+
require 'fakefs/safe'
|
|
6
|
+
|
|
7
|
+
describe RubyCritic::Generator::JsonReport do
|
|
8
|
+
describe '#generate_report' do
|
|
9
|
+
before(:each) do
|
|
10
|
+
FakeFS.activate!
|
|
11
|
+
create_analysed_modules_collection
|
|
12
|
+
generate_report
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
after(:each) { FakeFS.deactivate! }
|
|
16
|
+
|
|
17
|
+
it 'creates a report.json file' do
|
|
18
|
+
assert File.file?('test/samples/report.json'), 'expected report.json file to be created'
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it 'report file has data inside' do
|
|
22
|
+
data = File.read('test/samples/report.json')
|
|
23
|
+
assert data != '', 'expected report file not to be empty'
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def create_analysed_modules_collection
|
|
28
|
+
@analysed_modules_collection = RubyCritic::AnalysedModulesCollection.new('test/samples/')
|
|
29
|
+
RubyCritic::Config.root = 'test/samples'
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def generate_report
|
|
33
|
+
report = RubyCritic::Generator::JsonReport.new(@analysed_modules_collection)
|
|
34
|
+
report.generate_report
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
require 'test_helper'
|
|
2
2
|
require 'rubycritic/generators/html/turbulence'
|
|
3
3
|
|
|
4
|
-
describe
|
|
4
|
+
describe RubyCritic::Turbulence do
|
|
5
5
|
describe '::data' do
|
|
6
6
|
it 'returns json data that maps pathname, churn and complexity to name, x and y' do
|
|
7
7
|
files = [AnalysedModuleDouble.new(name: 'Foo', churn: 1, complexity: 2)]
|
|
8
|
-
turbulence_data =
|
|
8
|
+
turbulence_data = RubyCritic::Turbulence.data(files)
|
|
9
9
|
instance_parsed_json = JSON.parse(turbulence_data).first
|
|
10
10
|
instance_parsed_json['name'].must_equal 'Foo'
|
|
11
11
|
instance_parsed_json['x'].must_equal 1
|
|
@@ -2,7 +2,7 @@ require 'test_helper'
|
|
|
2
2
|
require 'rubycritic/generators/html/view_helpers'
|
|
3
3
|
require 'pathname'
|
|
4
4
|
|
|
5
|
-
describe
|
|
5
|
+
describe RubyCritic::ViewHelpers do
|
|
6
6
|
context 'when the file is in the root directory' do
|
|
7
7
|
let(:generator) { GeneratorDouble.new('foo.html') }
|
|
8
8
|
|
|
@@ -67,7 +67,7 @@ describe Rubycritic::ViewHelpers do
|
|
|
67
67
|
end
|
|
68
68
|
|
|
69
69
|
class GeneratorDouble
|
|
70
|
-
include
|
|
70
|
+
include RubyCritic::ViewHelpers
|
|
71
71
|
|
|
72
72
|
def initialize(file)
|
|
73
73
|
@file = Pathname.new(file)
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
require 'test_helper'
|
|
2
2
|
require 'rubycritic/revision_comparator'
|
|
3
3
|
|
|
4
|
-
describe
|
|
5
|
-
subject {
|
|
4
|
+
describe RubyCritic::RevisionComparator do
|
|
5
|
+
subject { RubyCritic::RevisionComparator.new([]) }
|
|
6
6
|
|
|
7
7
|
describe '#set_statuses' do
|
|
8
8
|
context 'in a SCS with :revision? == false' do
|
|
9
9
|
before do
|
|
10
|
-
|
|
10
|
+
RubyCritic::Config.expects(:source_control_system)
|
|
11
11
|
.at_least_once
|
|
12
12
|
.returns(stub(revision?: false))
|
|
13
13
|
end
|
|
@@ -21,7 +21,7 @@ describe Rubycritic::RevisionComparator do
|
|
|
21
21
|
|
|
22
22
|
context 'in a SCS with :revision? == true' do
|
|
23
23
|
before do
|
|
24
|
-
|
|
24
|
+
RubyCritic::Config.expects(:source_control_system)
|
|
25
25
|
.at_least_once
|
|
26
26
|
.returns(stub(revision?: true))
|
|
27
27
|
end
|
|
@@ -33,12 +33,12 @@ describe Rubycritic::RevisionComparator do
|
|
|
33
33
|
end
|
|
34
34
|
|
|
35
35
|
it 'does not load them' do
|
|
36
|
-
|
|
36
|
+
RubyCritic::Serializer.expects(:new).never
|
|
37
37
|
subject.set_statuses([])
|
|
38
38
|
end
|
|
39
39
|
|
|
40
|
-
it 'does not invoke
|
|
41
|
-
|
|
40
|
+
it 'does not invoke RubyCritic::SmellsStatusSetter' do
|
|
41
|
+
RubyCritic::SmellsStatusSetter.expects(:set).never
|
|
42
42
|
subject.set_statuses([])
|
|
43
43
|
end
|
|
44
44
|
end
|
|
@@ -47,15 +47,15 @@ describe Rubycritic::RevisionComparator do
|
|
|
47
47
|
before do
|
|
48
48
|
subject.expects(:revision_file).twice.returns('foo')
|
|
49
49
|
File.expects(:file?).with('foo').returns(true)
|
|
50
|
-
|
|
50
|
+
RubyCritic::Serializer.expects(:new).with('foo').returns(stub(load: []))
|
|
51
51
|
end
|
|
52
52
|
|
|
53
53
|
it 'loads them' do
|
|
54
54
|
subject.set_statuses([])
|
|
55
55
|
end
|
|
56
56
|
|
|
57
|
-
it 'invokes
|
|
58
|
-
|
|
57
|
+
it 'invokes RubyCritic::SmellsStatusSetter' do
|
|
58
|
+
RubyCritic::SmellsStatusSetter.expects(:set).once
|
|
59
59
|
subject.set_statuses([])
|
|
60
60
|
end
|
|
61
61
|
end
|
|
@@ -2,20 +2,20 @@ require 'test_helper'
|
|
|
2
2
|
require 'rubycritic/core/smell'
|
|
3
3
|
require 'rubycritic/smells_status_setter'
|
|
4
4
|
|
|
5
|
-
describe
|
|
5
|
+
describe RubyCritic::SmellsStatusSetter do
|
|
6
6
|
describe '::smells' do
|
|
7
7
|
before do
|
|
8
|
-
@smell =
|
|
8
|
+
@smell = RubyCritic::Smell.new(context: '#bar')
|
|
9
9
|
@smells = [@smell]
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
it 'marks old smells' do
|
|
13
|
-
|
|
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
|
-
|
|
18
|
+
RubyCritic::SmellsStatusSetter.set([], @smells)
|
|
19
19
|
@smell.status.must_equal :new
|
|
20
20
|
end
|
|
21
21
|
end
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
require 'test_helper'
|
|
2
2
|
require 'rubycritic/source_control_systems/base'
|
|
3
3
|
|
|
4
|
-
describe
|
|
4
|
+
describe RubyCritic::SourceControlSystem::Base do
|
|
5
5
|
before do
|
|
6
|
-
|
|
6
|
+
RubyCritic::SourceControlSystem::Base.systems.each do |system|
|
|
7
7
|
system.stubs(:supported?).returns(false)
|
|
8
8
|
end
|
|
9
9
|
end
|
|
@@ -11,17 +11,17 @@ describe Rubycritic::SourceControlSystem::Base do
|
|
|
11
11
|
describe '::create' do
|
|
12
12
|
context 'when a source control system is found' do
|
|
13
13
|
it 'creates an instance of that source control system' do
|
|
14
|
-
|
|
15
|
-
system =
|
|
16
|
-
system.must_be_instance_of
|
|
14
|
+
RubyCritic::SourceControlSystem::Git.stubs(:supported?).returns(true)
|
|
15
|
+
system = RubyCritic::SourceControlSystem::Base.create
|
|
16
|
+
system.must_be_instance_of RubyCritic::SourceControlSystem::Git
|
|
17
17
|
end
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
context 'when no source control system is found' do
|
|
21
21
|
it 'creates a source control system double' do
|
|
22
22
|
capture_output_streams do
|
|
23
|
-
system =
|
|
24
|
-
system.must_be_instance_of
|
|
23
|
+
system = RubyCritic::SourceControlSystem::Base.create
|
|
24
|
+
system.must_be_instance_of RubyCritic::SourceControlSystem::Double
|
|
25
25
|
end
|
|
26
26
|
end
|
|
27
27
|
end
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
require 'test_helper'
|
|
2
2
|
require 'rubycritic/source_locator'
|
|
3
3
|
|
|
4
|
-
describe
|
|
4
|
+
describe RubyCritic::SourceLocator do
|
|
5
5
|
before do
|
|
6
6
|
@original_dir = Dir.getwd
|
|
7
7
|
Dir.chdir('test/samples/location')
|
|
@@ -10,57 +10,57 @@ describe Rubycritic::SourceLocator do
|
|
|
10
10
|
describe '#paths' do
|
|
11
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
16
|
it 'finds all the files inside a given directory' do
|
|
17
17
|
initial_paths = ['dir1']
|
|
18
18
|
final_paths = ['dir1/file1.rb']
|
|
19
|
-
|
|
19
|
+
RubyCritic::SourceLocator.new(initial_paths).paths.must_equal final_paths
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
it 'finds files through multiple paths' do
|
|
23
23
|
paths = ['dir1/file1.rb', 'file0.rb']
|
|
24
|
-
|
|
24
|
+
RubyCritic::SourceLocator.new(paths).paths.must_match_array paths
|
|
25
25
|
end
|
|
26
26
|
|
|
27
27
|
it 'finds all the files' do
|
|
28
28
|
initial_paths = ['.']
|
|
29
29
|
final_paths = ['dir1/file1.rb', 'file0.rb', 'file0_symlink.rb']
|
|
30
|
-
|
|
30
|
+
RubyCritic::SourceLocator.new(initial_paths).paths.must_match_array final_paths
|
|
31
31
|
end
|
|
32
32
|
|
|
33
33
|
context 'when configured to deduplicate symlinks' do
|
|
34
34
|
it 'favors a file over a symlink if they both point to the same target' do
|
|
35
|
-
|
|
35
|
+
RubyCritic::Config.stubs(:deduplicate_symlinks).returns(true)
|
|
36
36
|
initial_paths = ['file0.rb', 'file0_symlink.rb']
|
|
37
37
|
final_paths = ['file0.rb']
|
|
38
|
-
|
|
38
|
+
RubyCritic::SourceLocator.new(initial_paths).paths.must_match_array final_paths
|
|
39
39
|
end
|
|
40
40
|
end
|
|
41
41
|
|
|
42
42
|
it 'cleans paths of consecutive slashes and useless dots' do
|
|
43
43
|
initial_paths = ['.//file0.rb']
|
|
44
44
|
final_paths = ['file0.rb']
|
|
45
|
-
|
|
45
|
+
RubyCritic::SourceLocator.new(initial_paths).paths.must_equal final_paths
|
|
46
46
|
end
|
|
47
47
|
|
|
48
48
|
it 'ignores paths to non-existent files' do
|
|
49
49
|
initial_paths = ['non_existent_dir1/non_existent_file1.rb', 'non_existent_file0.rb']
|
|
50
50
|
final_paths = []
|
|
51
|
-
|
|
51
|
+
RubyCritic::SourceLocator.new(initial_paths).paths.must_equal final_paths
|
|
52
52
|
end
|
|
53
53
|
|
|
54
54
|
it 'ignores paths to files that do not match the Ruby extension' do
|
|
55
55
|
initial_paths = ['file_with_no_extension', 'file_with_different_extension.py']
|
|
56
56
|
final_paths = []
|
|
57
|
-
|
|
57
|
+
RubyCritic::SourceLocator.new(initial_paths).paths.must_equal final_paths
|
|
58
58
|
end
|
|
59
59
|
|
|
60
60
|
it 'can deal with nil paths' do
|
|
61
61
|
paths = nil
|
|
62
62
|
final_paths = []
|
|
63
|
-
|
|
63
|
+
RubyCritic::SourceLocator.new(paths).paths.must_equal final_paths
|
|
64
64
|
end
|
|
65
65
|
end
|
|
66
66
|
|
|
@@ -68,7 +68,7 @@ describe Rubycritic::SourceLocator do
|
|
|
68
68
|
it 'finds a single file' do
|
|
69
69
|
initial_paths = ['file0.rb']
|
|
70
70
|
final_pathnames = [Pathname.new('file0.rb')]
|
|
71
|
-
|
|
71
|
+
RubyCritic::SourceLocator.new(initial_paths).pathnames.must_equal final_pathnames
|
|
72
72
|
end
|
|
73
73
|
end
|
|
74
74
|
|