rubycritic 0.0.14 → 0.0.15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +16 -4
- data/bin/rubycritic +2 -0
- data/lib/rubycritic/adapters/complexity/flog.rb +8 -6
- data/lib/rubycritic/adapters/smell/flay.rb +31 -9
- data/lib/rubycritic/adapters/smell/flog.rb +18 -9
- data/lib/rubycritic/adapters/smell/reek.rb +12 -5
- data/lib/rubycritic/analysers/churn.rb +6 -3
- data/lib/rubycritic/analysers/stats.rb +31 -0
- data/lib/rubycritic/analysers_runner.rb +13 -19
- data/lib/rubycritic/cli.rb +34 -18
- data/lib/rubycritic/configuration.rb +7 -1
- data/lib/rubycritic/core/analysed_file.rb +27 -1
- data/lib/rubycritic/core/location.rb +1 -1
- data/lib/rubycritic/core/rating.rb +22 -0
- data/lib/rubycritic/core/smell.rb +3 -12
- data/lib/rubycritic/files_initializer.rb +15 -0
- data/lib/rubycritic/orchestrator.rb +23 -0
- data/lib/rubycritic/report_generators/assets/javascripts/application.js +5 -3
- data/lib/rubycritic/report_generators/assets/javascripts/jquery.timeago-v1.4.1.js +214 -0
- data/lib/rubycritic/report_generators/assets/stylesheets/application.css +87 -2
- data/lib/rubycritic/report_generators/code_file.rb +1 -3
- data/lib/rubycritic/report_generators/code_index.rb +0 -1
- data/lib/rubycritic/report_generators/current_code_file.rb +17 -0
- data/lib/rubycritic/report_generators/line.rb +0 -1
- data/lib/rubycritic/report_generators/overview.rb +1 -2
- data/lib/rubycritic/report_generators/smells_index.rb +0 -1
- data/lib/rubycritic/report_generators/templates/code_file.html.erb +28 -1
- data/lib/rubycritic/report_generators/templates/code_index.html.erb +6 -2
- data/lib/rubycritic/report_generators/templates/layouts/application.html.erb +8 -7
- data/lib/rubycritic/report_generators/templates/overview.html.erb +1 -1
- data/lib/rubycritic/report_generators/view_helpers.rb +6 -2
- data/lib/rubycritic/reporters/main.rb +7 -3
- data/lib/rubycritic/reporters/mini.rb +13 -4
- data/lib/rubycritic/revision_comparator.rb +15 -16
- data/lib/rubycritic/serializer.rb +32 -0
- data/lib/rubycritic/smells_status_setter.rb +5 -11
- data/lib/rubycritic/source_control_systems/base.rb +60 -0
- data/lib/rubycritic/source_control_systems/double.rb +19 -0
- data/lib/rubycritic/source_control_systems/git.rb +46 -40
- data/lib/rubycritic/turbulence.rb +3 -7
- data/lib/rubycritic/version.rb +1 -1
- data/lib/rubycritic.rb +1 -7
- data/rubycritic.gemspec +1 -0
- data/test/lib/rubycritic/adapters/complexity/flog_test.rb +5 -5
- data/test/lib/rubycritic/adapters/smell/flay_test.rb +19 -8
- data/test/lib/rubycritic/adapters/smell/flog_test.rb +11 -8
- data/test/lib/rubycritic/adapters/smell/reek_test.rb +14 -10
- data/test/lib/rubycritic/analysers/churn_test.rb +23 -8
- data/test/lib/rubycritic/core/analysed_file_test.rb +31 -11
- data/test/lib/rubycritic/core/smell_test.rb +13 -20
- data/test/lib/rubycritic/smells_status_setter_test.rb +2 -2
- data/test/lib/rubycritic/source_control_systems/source_control_system_test.rb +5 -12
- data/test/lib/rubycritic/turbulence_test.rb +1 -2
- data/test/lib/rubycritic/version_test.rb +1 -0
- data/test/samples/flog/{smelly2.rb → complex.rb} +0 -0
- data/test/test_helper.rb +1 -0
- metadata +27 -17
- data/lib/rubycritic/active_support/methods.rb +0 -36
- data/lib/rubycritic/analysed_files_builder.rb +0 -36
- data/lib/rubycritic/orchestrators/base.rb +0 -27
- data/lib/rubycritic/orchestrators/main.rb +0 -14
- data/lib/rubycritic/orchestrators/mini.rb +0 -14
- data/lib/rubycritic/smells_serializer.rb +0 -32
- data/lib/rubycritic/source_control_systems/source_control_system.rb +0 -50
- data/test/lib/rubycritic/analysed_files_builder_test.rb +0 -36
- data/test/lib/rubycritic/analysers_runner_test.rb +0 -11
- data/test/samples/analysers_runner/empty.rb +0 -0
@@ -1,22 +1,16 @@
|
|
1
1
|
module Rubycritic
|
2
2
|
|
3
|
-
|
4
|
-
def
|
5
|
-
|
6
|
-
@smells_now = smells_now || []
|
7
|
-
end
|
8
|
-
|
9
|
-
def smells
|
10
|
-
old_smells = @smells_now & @smells_before
|
3
|
+
module SmellsStatusSetter
|
4
|
+
def self.set(smells_before, smells_now)
|
5
|
+
old_smells = smells_now & smells_before
|
11
6
|
set_status(old_smells, :old)
|
12
|
-
new_smells =
|
7
|
+
new_smells = smells_now - smells_before
|
13
8
|
set_status(new_smells, :new)
|
14
|
-
@smells_now
|
15
9
|
end
|
16
10
|
|
17
11
|
private
|
18
12
|
|
19
|
-
def set_status(smells, status)
|
13
|
+
def self.set_status(smells, status)
|
20
14
|
smells.each { |smell| smell.status = status }
|
21
15
|
end
|
22
16
|
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require "shellwords"
|
2
|
+
|
3
|
+
module Rubycritic
|
4
|
+
module SourceControlSystem
|
5
|
+
|
6
|
+
class Base
|
7
|
+
@@systems = []
|
8
|
+
|
9
|
+
def self.register_system
|
10
|
+
@@systems << self
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.create
|
14
|
+
supported_system = systems.detect(&:supported?)
|
15
|
+
if supported_system
|
16
|
+
supported_system.new
|
17
|
+
else
|
18
|
+
puts "Rubycritic requires a #{system_names} repository."
|
19
|
+
Double.new
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.systems
|
24
|
+
@@systems
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.system_names
|
28
|
+
systems.join(", ")
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.supported?
|
32
|
+
raise NotImplementedError.new("The #{self.class} class must implement the #{__method__} method.")
|
33
|
+
end
|
34
|
+
|
35
|
+
def has_revision?
|
36
|
+
raise NotImplementedError.new("The #{self.class} class must implement the #{__method__} method.")
|
37
|
+
end
|
38
|
+
|
39
|
+
def head_reference
|
40
|
+
raise NotImplementedError.new("The #{self.class} class must implement the #{__method__} method.")
|
41
|
+
end
|
42
|
+
|
43
|
+
def travel_to_head
|
44
|
+
raise NotImplementedError.new("The #{self.class} class must implement the #{__method__} method.")
|
45
|
+
end
|
46
|
+
|
47
|
+
def revisions_count(path)
|
48
|
+
raise NotImplementedError.new("The #{self.class} class must implement the #{__method__} method.")
|
49
|
+
end
|
50
|
+
|
51
|
+
def date_of_last_commit(path)
|
52
|
+
raise NotImplementedError.new("The #{self.class} class must implement the #{__method__} method.")
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
require "rubycritic/source_control_systems/double"
|
60
|
+
require "rubycritic/source_control_systems/git"
|
@@ -1,57 +1,63 @@
|
|
1
1
|
module Rubycritic
|
2
|
+
module SourceControlSystem
|
2
3
|
|
3
|
-
|
4
|
-
|
4
|
+
class Git < Base
|
5
|
+
register_system
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
7
|
+
def self.supported?
|
8
|
+
`git branch 2>&1` && $?.success?
|
9
|
+
end
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
11
|
+
def self.to_s
|
12
|
+
"Git"
|
13
|
+
end
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
15
|
+
def has_revision?
|
16
|
+
head_reference && $?.success?
|
17
|
+
end
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
19
|
+
def head_reference
|
20
|
+
`git rev-parse --verify HEAD`.chomp!
|
21
|
+
end
|
21
22
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
23
|
+
def travel_to_head
|
24
|
+
stash_successful = stash_changes
|
25
|
+
yield
|
26
|
+
ensure
|
27
|
+
travel_to_original_state if stash_successful
|
28
|
+
end
|
28
29
|
|
29
|
-
|
30
|
-
|
31
|
-
|
30
|
+
def revisions_count(path)
|
31
|
+
`git log --follow --format=oneline #{path.shellescape}`.count("\n")
|
32
|
+
end
|
32
33
|
|
33
|
-
|
34
|
+
def date_of_last_commit(path)
|
35
|
+
`git log -1 --date=iso --format=%ad #{path.shellescape}`.chomp!
|
36
|
+
end
|
34
37
|
|
35
|
-
|
36
|
-
return false if everything_commmited?
|
38
|
+
private
|
37
39
|
|
38
|
-
|
39
|
-
|
40
|
-
stashes_count_after = stashes_count
|
41
|
-
stashes_count_after > stashes_count_before
|
42
|
-
end
|
40
|
+
def stash_changes
|
41
|
+
return false if everything_commmited?
|
43
42
|
|
44
|
-
|
45
|
-
|
46
|
-
|
43
|
+
stashes_count_before = stashes_count
|
44
|
+
`git stash`
|
45
|
+
stashes_count_after = stashes_count
|
46
|
+
stashes_count_after > stashes_count_before
|
47
|
+
end
|
47
48
|
|
48
|
-
|
49
|
-
|
50
|
-
|
49
|
+
def everything_commmited?
|
50
|
+
`git status --porcelain`.empty?
|
51
|
+
end
|
51
52
|
|
52
|
-
|
53
|
-
|
53
|
+
def stashes_count
|
54
|
+
`git stash list`.count("\n")
|
55
|
+
end
|
56
|
+
|
57
|
+
def travel_to_original_state
|
58
|
+
`git stash pop`
|
59
|
+
end
|
54
60
|
end
|
55
|
-
end
|
56
61
|
|
62
|
+
end
|
57
63
|
end
|
@@ -2,13 +2,9 @@ require "json"
|
|
2
2
|
|
3
3
|
module Rubycritic
|
4
4
|
|
5
|
-
|
6
|
-
def
|
7
|
-
|
8
|
-
end
|
9
|
-
|
10
|
-
def data
|
11
|
-
@analysed_files.map do |analysed_file|
|
5
|
+
module Turbulence
|
6
|
+
def self.data(analysed_files)
|
7
|
+
analysed_files.map do |analysed_file|
|
12
8
|
{
|
13
9
|
:name => analysed_file.pathname,
|
14
10
|
:x => analysed_file.churn,
|
data/lib/rubycritic/version.rb
CHANGED
data/lib/rubycritic.rb
CHANGED
@@ -1,8 +1,2 @@
|
|
1
1
|
require "rubycritic/configuration"
|
2
|
-
require "rubycritic/
|
3
|
-
require "rubycritic/analysers_runner"
|
4
|
-
require "rubycritic/source_control_systems/source_control_system"
|
5
|
-
require "rubycritic/revision_comparator"
|
6
|
-
require "rubycritic/analysers/churn"
|
7
|
-
require "rubycritic/adapters/complexity/flog"
|
8
|
-
require "rubycritic/analysed_files_builder"
|
2
|
+
require "rubycritic/orchestrator"
|
data/rubycritic.gemspec
CHANGED
@@ -25,6 +25,7 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.add_runtime_dependency "flay", "2.4.0"
|
26
26
|
spec.add_runtime_dependency "flog", "4.2.0"
|
27
27
|
spec.add_runtime_dependency "reek", "1.3.6"
|
28
|
+
spec.add_runtime_dependency "code_analyzer", "0.4.5"
|
28
29
|
|
29
30
|
spec.add_development_dependency "bundler", "~> 1.3"
|
30
31
|
spec.add_development_dependency "rake"
|
@@ -4,14 +4,14 @@ require "rubycritic/adapters/complexity/flog"
|
|
4
4
|
|
5
5
|
describe Rubycritic::ComplexityAdapter::Flog do
|
6
6
|
before do
|
7
|
-
|
8
|
-
|
7
|
+
@analysed_files = [AnalysedFileDouble.new(:path => "test/samples/flog/complex.rb")]
|
8
|
+
Rubycritic::ComplexityAdapter::Flog.new(@analysed_files).complexity
|
9
9
|
end
|
10
10
|
|
11
11
|
describe "#complexity" do
|
12
|
-
it "
|
13
|
-
@
|
14
|
-
|
12
|
+
it "calculates the complexity of each file and adds it to analysed_files" do
|
13
|
+
@analysed_files.each do |analysed_file|
|
14
|
+
analysed_file.complexity.must_be_kind_of Numeric
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
@@ -1,23 +1,34 @@
|
|
1
1
|
require "test_helper"
|
2
2
|
require "rubycritic/adapters/smell/flay"
|
3
|
+
require "rubycritic/core/analysed_file"
|
4
|
+
require "pathname"
|
3
5
|
|
4
6
|
describe Rubycritic::SmellAdapter::Flay do
|
5
7
|
before do
|
6
|
-
|
7
|
-
|
8
|
+
@analysed_file = Rubycritic::AnalysedFile.new(
|
9
|
+
:pathname => Pathname.new("test/samples/flay/smelly.rb"),
|
10
|
+
:smells => [],
|
11
|
+
:duplication => 0
|
12
|
+
)
|
13
|
+
analysed_files = [@analysed_file]
|
14
|
+
Rubycritic::SmellAdapter::Flay.new(analysed_files).smells
|
8
15
|
end
|
9
16
|
|
10
|
-
it "detects smells" do
|
11
|
-
@
|
17
|
+
it "detects smells and adds them to analysed_files" do
|
18
|
+
@analysed_file.smells.length.must_equal 1
|
12
19
|
end
|
13
20
|
|
14
|
-
it "
|
15
|
-
smell = @
|
21
|
+
it "creates smells with messages" do
|
22
|
+
smell = @analysed_file.smells.first
|
16
23
|
smell.message.must_be_instance_of String
|
17
24
|
end
|
18
25
|
|
19
|
-
it "
|
20
|
-
smell = @
|
26
|
+
it "creates smells with scores" do
|
27
|
+
smell = @analysed_file.smells.first
|
21
28
|
smell.score.must_be_kind_of Numeric
|
22
29
|
end
|
30
|
+
|
31
|
+
it "calculates the mass of duplicate code and adds it to analysed_files" do
|
32
|
+
@analysed_file.duplication.must_be(:>, 0)
|
33
|
+
end
|
23
34
|
end
|
@@ -3,21 +3,24 @@ require "rubycritic/adapters/smell/flog"
|
|
3
3
|
|
4
4
|
describe Rubycritic::SmellAdapter::Flog do
|
5
5
|
before do
|
6
|
-
|
7
|
-
|
6
|
+
@analysed_file = AnalysedFileDouble.new(:path => "test/samples/flog/smelly.rb", :smells => [])
|
7
|
+
analysed_files = [@analysed_file]
|
8
|
+
Rubycritic::SmellAdapter::Flog.new(analysed_files).smells
|
8
9
|
end
|
9
10
|
|
10
|
-
it "detects smells" do
|
11
|
-
@
|
11
|
+
it "detects smells and adds them to analysed_files" do
|
12
|
+
@analysed_file.smells.length.must_equal 1
|
12
13
|
end
|
13
14
|
|
14
|
-
it "
|
15
|
-
smell = @
|
15
|
+
it "creates smells with messages" do
|
16
|
+
smell = @analysed_file.smells.first
|
16
17
|
smell.message.must_be_instance_of String
|
17
18
|
end
|
18
19
|
|
19
|
-
it "
|
20
|
-
smell = @
|
20
|
+
it "creates smells with scores" do
|
21
|
+
smell = @analysed_file.smells.first
|
21
22
|
smell.score.must_be_kind_of Numeric
|
22
23
|
end
|
23
24
|
end
|
25
|
+
|
26
|
+
class AnalysedFileDouble < OpenStruct; end
|
@@ -4,28 +4,32 @@ require "rubycritic/adapters/smell/reek"
|
|
4
4
|
describe Rubycritic::SmellAdapter::Reek do
|
5
5
|
context "when analysing a smelly file" do
|
6
6
|
before do
|
7
|
-
|
8
|
-
|
7
|
+
@analysed_file = AnalysedFileDouble.new(:path => "test/samples/reek/smelly.rb", :smells => [])
|
8
|
+
analysed_files = [@analysed_file]
|
9
|
+
Rubycritic::SmellAdapter::Reek.new(analysed_files).smells
|
9
10
|
end
|
10
11
|
|
11
|
-
it "detects smells" do
|
12
|
-
@
|
12
|
+
it "detects smells and adds them to analysed_files" do
|
13
|
+
@analysed_file.smells.length.must_equal 1
|
13
14
|
end
|
14
15
|
|
15
|
-
it "
|
16
|
-
smell = @
|
16
|
+
it "creates smells with messages" do
|
17
|
+
smell = @analysed_file.smells.first
|
17
18
|
smell.message.must_equal "has boolean parameter 'reek'"
|
18
19
|
end
|
19
20
|
end
|
20
21
|
|
21
22
|
context "when analysing a file with smells ignored in config.reek" do
|
22
23
|
before do
|
23
|
-
|
24
|
-
|
24
|
+
@analysed_file = AnalysedFileDouble.new(:path => "test/samples/reek/not_smelly.rb", :smells => [])
|
25
|
+
analysed_files = [@analysed_file]
|
26
|
+
Rubycritic::SmellAdapter::Reek.new(analysed_files)
|
25
27
|
end
|
26
28
|
|
27
|
-
it "does not detect smells" do
|
28
|
-
@
|
29
|
+
it "does not detect smells and does not add them to analysed files" do
|
30
|
+
@analysed_file.smells.must_be_empty
|
29
31
|
end
|
30
32
|
end
|
31
33
|
end
|
34
|
+
|
35
|
+
class AnalysedFileDouble < OpenStruct; end
|
@@ -1,23 +1,38 @@
|
|
1
1
|
require "test_helper"
|
2
2
|
require "rubycritic/analysers/churn"
|
3
|
-
require "rubycritic/source_control_systems/
|
3
|
+
require "rubycritic/source_control_systems/base"
|
4
4
|
|
5
5
|
describe Rubycritic::Analyser::Churn do
|
6
6
|
before do
|
7
|
-
|
8
|
-
source_control_system = SourceControlSystemDouble.new
|
9
|
-
@churn = Rubycritic::Analyser::Churn.new(sample_paths, source_control_system)
|
7
|
+
@analysed_files = [AnalysedFileDouble.new(:path => "path_to_some_file.rb")]
|
8
|
+
@source_control_system = SourceControlSystemDouble.new
|
10
9
|
end
|
11
10
|
|
12
11
|
describe "#churn" do
|
13
|
-
it "
|
14
|
-
@
|
12
|
+
it "calculates the churn of each file and adds it to analysed_files" do
|
13
|
+
Rubycritic::Analyser::Churn.new(@analysed_files, @source_control_system).churn
|
14
|
+
@analysed_files.each do |analysed_file|
|
15
|
+
analysed_file.churn.must_equal 1
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
it "calculates the date of the last commit of each file and adds it to analysed_files" do
|
20
|
+
Rubycritic::Analyser::Churn.new(@analysed_files, @source_control_system).churn
|
21
|
+
@analysed_files.each do |analysed_file|
|
22
|
+
analysed_file.committed_at.must_equal "2013-10-09 12:52:49 +0100"
|
23
|
+
end
|
15
24
|
end
|
16
25
|
end
|
17
26
|
end
|
18
27
|
|
19
|
-
class
|
20
|
-
|
28
|
+
class AnalysedFileDouble < OpenStruct; end
|
29
|
+
|
30
|
+
class SourceControlSystemDouble < Rubycritic::SourceControlSystem::Base
|
31
|
+
def revisions_count(path)
|
21
32
|
1 # churn
|
22
33
|
end
|
34
|
+
|
35
|
+
def date_of_last_commit(path)
|
36
|
+
"2013-10-09 12:52:49 +0100"
|
37
|
+
end
|
23
38
|
end
|
@@ -1,14 +1,16 @@
|
|
1
1
|
require "test_helper"
|
2
2
|
require "rubycritic/core/analysed_file"
|
3
|
+
require "rubycritic/core/smell"
|
4
|
+
require "rubycritic/core/location"
|
3
5
|
|
4
6
|
describe Rubycritic::AnalysedFile do
|
5
7
|
describe "attribute readers" do
|
6
8
|
before do
|
7
|
-
@pathname = Pathname.new("
|
9
|
+
@pathname = Pathname.new("foo/bar.rb")
|
8
10
|
@smells = []
|
9
11
|
@churn = 1
|
10
12
|
@complexity = 2
|
11
|
-
@
|
13
|
+
@analysed_file = Rubycritic::AnalysedFile.new(
|
12
14
|
:pathname => @pathname,
|
13
15
|
:smells => @smells,
|
14
16
|
:churn => @churn,
|
@@ -17,26 +19,35 @@ describe Rubycritic::AnalysedFile do
|
|
17
19
|
end
|
18
20
|
|
19
21
|
it "has a pathname reader" do
|
20
|
-
@
|
22
|
+
@analysed_file.pathname.must_equal @pathname
|
21
23
|
end
|
22
24
|
|
23
25
|
it "has a smells reader" do
|
24
|
-
@
|
26
|
+
@analysed_file.smells.must_equal @smells
|
25
27
|
end
|
26
28
|
|
27
29
|
it "has a churn reader" do
|
28
|
-
@
|
30
|
+
@analysed_file.churn.must_equal @churn
|
29
31
|
end
|
30
32
|
|
31
33
|
it "has a complexity reader" do
|
32
|
-
@
|
34
|
+
@analysed_file.complexity.must_equal @complexity
|
35
|
+
end
|
36
|
+
|
37
|
+
it "has a name reader" do
|
38
|
+
@analysed_file.name.must_equal "bar"
|
39
|
+
end
|
40
|
+
|
41
|
+
it "has a path reader" do
|
42
|
+
@analysed_file.path.must_equal @pathname.to_s
|
33
43
|
end
|
34
44
|
end
|
35
45
|
|
36
|
-
describe "#
|
37
|
-
it "returns the
|
38
|
-
|
39
|
-
analysed_file.
|
46
|
+
describe "#cost" do
|
47
|
+
it "returns the remediation cost of fixing the analysed_file" do
|
48
|
+
smells = [SmellDouble.new(:cost => 1), SmellDouble.new(:cost => 2)]
|
49
|
+
analysed_file = Rubycritic::AnalysedFile.new(:smells => smells, :complexity => 0)
|
50
|
+
analysed_file.cost.must_equal 3
|
40
51
|
end
|
41
52
|
end
|
42
53
|
|
@@ -46,6 +57,15 @@ describe Rubycritic::AnalysedFile do
|
|
46
57
|
analysed_file.has_smells?.must_equal true
|
47
58
|
end
|
48
59
|
end
|
60
|
+
|
61
|
+
describe "#smells_at_location" do
|
62
|
+
it "returns the smells of an analysed_file at a certain location" do
|
63
|
+
location = Rubycritic::Location.new("./foo", "42")
|
64
|
+
smells = [Rubycritic::Smell.new(:locations => [location])]
|
65
|
+
analysed_file = Rubycritic::AnalysedFile.new(:smells => smells)
|
66
|
+
analysed_file.smells_at_location(location).must_equal smells
|
67
|
+
end
|
68
|
+
end
|
49
69
|
end
|
50
70
|
|
51
|
-
class SmellDouble; end
|
71
|
+
class SmellDouble < OpenStruct; end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require "test_helper"
|
2
2
|
require "rubycritic/core/smell"
|
3
|
+
require "rubycritic/core/location"
|
3
4
|
|
4
5
|
describe Rubycritic::Smell do
|
5
6
|
describe "attribute readers" do
|
@@ -47,16 +48,6 @@ describe Rubycritic::Smell do
|
|
47
48
|
end
|
48
49
|
end
|
49
50
|
|
50
|
-
describe "#at_pathname?" do
|
51
|
-
it "returns true if the smell has a pathname that matches the pathname passed as argument" do
|
52
|
-
path = "./foo"
|
53
|
-
pathname = Pathname.new(path)
|
54
|
-
location = Rubycritic::Location.new(path, "42")
|
55
|
-
smell = Rubycritic::Smell.new(:locations => [location])
|
56
|
-
smell.at_pathname?(pathname).must_equal true
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
51
|
describe "#has_multiple_locations?" do
|
61
52
|
it "returns true if the smell has more than one location" do
|
62
53
|
location1 = Rubycritic::Location.new("./foo", "42")
|
@@ -66,15 +57,17 @@ describe Rubycritic::Smell do
|
|
66
57
|
end
|
67
58
|
end
|
68
59
|
|
69
|
-
|
70
|
-
attributes
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
60
|
+
describe "#==" do
|
61
|
+
it "returns true if two smells have the same base attributes" do
|
62
|
+
attributes = {
|
63
|
+
:context => "#bar",
|
64
|
+
:message => "This smells",
|
65
|
+
:score => 0,
|
66
|
+
:type => :complexity
|
67
|
+
}
|
68
|
+
smell1 = Rubycritic::Smell.new(attributes)
|
69
|
+
smell2 = Rubycritic::Smell.new(attributes)
|
70
|
+
smell1.must_equal smell2
|
71
|
+
end
|
79
72
|
end
|
80
73
|
end
|
@@ -10,12 +10,12 @@ describe Rubycritic::SmellsStatusSetter do
|
|
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
|
@@ -1,9 +1,9 @@
|
|
1
1
|
require "test_helper"
|
2
|
-
require "rubycritic/source_control_systems/
|
2
|
+
require "rubycritic/source_control_systems/base"
|
3
3
|
|
4
4
|
describe Rubycritic::SourceControlSystem do
|
5
5
|
before do
|
6
|
-
Rubycritic::SourceControlSystem.systems.each do |system|
|
6
|
+
Rubycritic::SourceControlSystem::Base.systems.each do |system|
|
7
7
|
system.stubs(:supported?).returns(false)
|
8
8
|
end
|
9
9
|
end
|
@@ -11,16 +11,9 @@ describe Rubycritic::SourceControlSystem do
|
|
11
11
|
describe "::create" do
|
12
12
|
describe "when a source control system is found" do
|
13
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
|
-
error = proc { Rubycritic::SourceControlSystem.create }.must_raise RuntimeError
|
23
|
-
error.message.must_match "Rubycritic requires a Git repository."
|
14
|
+
Rubycritic::SourceControlSystem::Git.stubs(:supported?).returns(true)
|
15
|
+
system = Rubycritic::SourceControlSystem::Base.create
|
16
|
+
system.must_be_instance_of Rubycritic::SourceControlSystem::Git
|
24
17
|
end
|
25
18
|
end
|
26
19
|
end
|
@@ -1,12 +1,11 @@
|
|
1
1
|
require "test_helper"
|
2
2
|
require "rubycritic/turbulence"
|
3
|
-
require "ostruct"
|
4
3
|
|
5
4
|
describe Rubycritic::Turbulence do
|
6
5
|
describe "#data" do
|
7
6
|
it "returns json data that maps pathname, churn and complexity to name, x and y" do
|
8
7
|
files = [AnalysedFileDouble.new(:pathname => "./foo.rb", :churn => 1, :complexity => 2)]
|
9
|
-
turbulence_data = Rubycritic::Turbulence.
|
8
|
+
turbulence_data = Rubycritic::Turbulence.data(files)
|
10
9
|
instance_parsed_json = JSON.parse(turbulence_data).first
|
11
10
|
instance_parsed_json["name"].must_equal "./foo.rb"
|
12
11
|
instance_parsed_json["x"].must_equal 1
|
File without changes
|