rubycritic 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (26) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rubycritic.rb +4 -5
  3. data/lib/rubycritic/location.rb +4 -0
  4. data/lib/rubycritic/report_generators/assets/stylesheets/application.css +100 -1
  5. data/lib/rubycritic/report_generators/assets/stylesheets/prettify.custom_theme.css +1 -4
  6. data/lib/rubycritic/report_generators/base_generator.rb +5 -3
  7. data/lib/rubycritic/report_generators/{index_generator.rb → code_index_generator.rb} +4 -5
  8. data/lib/rubycritic/report_generators/file_generator.rb +6 -3
  9. data/lib/rubycritic/report_generators/reporter.rb +23 -7
  10. data/lib/rubycritic/report_generators/smells_index_generator.rb +27 -0
  11. data/lib/rubycritic/report_generators/templates/{index.html.erb → code_index.html.erb} +1 -1
  12. data/lib/rubycritic/report_generators/templates/file.html.erb +7 -1
  13. data/lib/rubycritic/report_generators/templates/layouts/application.html.erb +21 -16
  14. data/lib/rubycritic/report_generators/templates/smells_index.html.erb +20 -0
  15. data/lib/rubycritic/report_generators/view_helpers.rb +11 -2
  16. data/lib/rubycritic/revision_comparator.rb +12 -20
  17. data/lib/rubycritic/smells_aggregator.rb +0 -16
  18. data/lib/rubycritic/{smelly_pathnames_serializer.rb → smells_serializer.rb} +3 -5
  19. data/lib/rubycritic/smells_status_setter.rb +9 -12
  20. data/lib/rubycritic/source_control_systems/source_control_system.rb +7 -3
  21. data/lib/rubycritic/version.rb +1 -1
  22. data/test/lib/rubycritic/location_test.rb +5 -1
  23. data/test/lib/rubycritic/smells_aggregator_test.rb +8 -23
  24. data/test/lib/rubycritic/smells_status_setter_test.rb +4 -4
  25. data/test/lib/rubycritic/source_control_systems/source_control_system_test.rb +2 -1
  26. metadata +7 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a776a51f8d90b8d2b65bb2e81f6b4dea87cd63a4
4
- data.tar.gz: 4f35ecbef41031dd622513ef120ca1fab15e1e10
3
+ metadata.gz: cf087d756a9bf0d14b016b82d75b675870614854
4
+ data.tar.gz: 5c17c62548734bd39a5ca405f764473b96cdd24e
5
5
  SHA512:
6
- metadata.gz: 078000998ba31e7c53c637dfda9184e8dfcdc90e28750afd88a4c35949f86feb38b785be71a2038d7704d2acd12d9182b905f19cafa00329ae20f99db51f1592
7
- data.tar.gz: fff0b984ed7ebe0e120ceb0ed13947eacea027162312e80e84d7dbe9e96b1f998ecd8be4cd9dfd8e3fc659a50a252261a8ec63ba6310b323b42eda3885327d17
6
+ metadata.gz: d0cfeef76646512463c61140b93959f5de1bc6654bc505005f74f5d560c1e5518d5cda6af6cfbcc18b81285c594aad88ae15fce0cd9ef1c143d56ee49300dc81
7
+ data.tar.gz: 957ce873afee75b3c4ae67b43d4fd2402bdc3317f7c78f0f2d36d93a0e252eb3d47101a48b83b398df38e887169f1aeafc151231217d2dd580f14316bc6527f9
data/lib/rubycritic.rb CHANGED
@@ -14,13 +14,12 @@ module Rubycritic
14
14
 
15
15
  def critique(paths)
16
16
  source = SourceLocator.new(paths)
17
+ smell_adapters = AnalysersRunner.new(source.paths).run
18
+ smells = SmellsAggregator.new(smell_adapters).smells
17
19
  if @source_control_system.has_revision?
18
- smelly_pathnames = RevisionComparator.new(source.paths, @source_control_system).compare
19
- else
20
- smell_adapters = AnalysersRunner.new(source.paths).run
21
- smelly_pathnames = SmellsAggregator.new(smell_adapters).smelly_pathnames
20
+ smells = RevisionComparator.new(smells, @source_control_system).smells
22
21
  end
23
- Reporter.new(source.pathnames, smelly_pathnames).generate_report
22
+ Reporter.new(source.pathnames, smells).generate_report
24
23
  end
25
24
  end
26
25
 
@@ -10,6 +10,10 @@ module Rubycritic
10
10
  @line = line
11
11
  end
12
12
 
13
+ def file_name
14
+ @pathname.basename.sub_ext("").to_s
15
+ end
16
+
13
17
  def to_s
14
18
  "#{pathname}:#{line}"
15
19
  end
@@ -1,8 +1,107 @@
1
+ .group:after {
2
+ content: '';
3
+ display: table;
4
+ clear: both;
5
+ }
6
+
7
+ html {
8
+ overflow-y: scroll;
9
+ }
10
+
11
+ .project-header {
12
+ padding: 20px 0 20px 60px;
13
+ }
14
+
15
+ .logo {
16
+ float: left;
17
+ margin: 0;
18
+ }
19
+
20
+ .logo-link {
21
+ color: black;
22
+ text-decoration: none;
23
+ }
24
+
25
+ .project-nav {
26
+ float: left;
27
+ margin-left: 100px;
28
+ line-height: 2.5em;
29
+ }
30
+
31
+ .project-nav-item {
32
+ color: black;
33
+ margin-right: 40px;
34
+ text-decoration: none;
35
+ }
36
+
37
+ .code-table,
38
+ .smells-table {
39
+ width: 100%;
40
+ border-collapse: collapse;
41
+ }
42
+
43
+ .code-table th,
44
+ .smells-table th {
45
+ text-align: left;
46
+ padding-bottom: 8px;
47
+ border-bottom: 1px solid silver;
48
+ font-size: 1.55em;
49
+ font-weight: normal;
50
+ }
51
+
52
+ .code-table td,
53
+ .smells-table td {
54
+ padding-top: 12px;
55
+ padding-bottom: 12px;
56
+ }
57
+
58
+ .code-table tr td:first-child,
59
+ .code-table tr th:first-child,
60
+ .smells-table tr td:first-child,
61
+ .smells-table tr th:first-child {
62
+ padding-left: 60px;
63
+ }
64
+
65
+ .button {
66
+ margin: 0;
67
+ padding: 0.5em 1em;
68
+ border: 1px solid black;
69
+ font-size: 0.9em;
70
+ border-radius: 0.2em;
71
+ cursor: pointer;
72
+ transition-property: background-color;
73
+ -webkit-transition-duration: 0.5s;
74
+ transition-duration: 0.5s;
75
+ }
76
+
77
+ .file-header {
78
+ position: relative;
79
+ padding: 0 0 10px 60px;
80
+ border-bottom: 1px solid silver;
81
+ }
82
+
83
+ .file-name {
84
+ margin: 0;
85
+ font-weight: normal;
86
+ }
87
+
88
+ .smells-toggle-button {
89
+ position: absolute;
90
+ right: 64px;
91
+ top: 22px;
92
+ border-color: silver;
93
+ background-color: #EEEBE9;
94
+ }
95
+
96
+ .smells-toggle-button:hover {
97
+ background-color: #D1CFCD;
98
+ }
99
+
1
100
  .smells {
2
101
  margin: 2px 0 22px 0;
3
102
  padding-left: 0;
4
103
  border: 1px solid #000;
5
- background-color: #DDD;
104
+ background-color: #EEEBE9;
6
105
  white-space: normal;
7
106
  list-style-type: disc;
8
107
  }
@@ -57,10 +57,7 @@
57
57
 
58
58
  /* Specify class=linenums on a pre to get line numbering */
59
59
  .prettyprint ol.linenums {
60
- margin-top: 0;
61
- margin-bottom: 0;
62
- background-color: #EEEBE9;
63
- padding-left: 66px;
60
+ padding-left: 60px;
64
61
  }
65
62
 
66
63
  .prettyprint li {
@@ -1,3 +1,4 @@
1
+ require "erb"
1
2
  require "rubycritic/report_generators/view_helpers"
2
3
 
3
4
  module Rubycritic
@@ -5,6 +6,7 @@ module Rubycritic
5
6
  class BaseGenerator
6
7
  REPORT_DIR = File.expand_path("tmp/rubycritic", Dir.getwd)
7
8
  TEMPLATES_DIR = File.expand_path("../templates", __FILE__)
9
+ LAYOUT_TEMPLATE = ERB.new(File.read(File.join(TEMPLATES_DIR, "layouts", "application.html.erb")))
8
10
 
9
11
  include ViewHelpers
10
12
 
@@ -17,15 +19,15 @@ module Rubycritic
17
19
  end
18
20
 
19
21
  def file_directory
20
- raise NotImplementedError.new("You must implement the file_directory method.")
22
+ raise NotImplementedError.new("The #{self.class} class must implement the #{__method__} method.")
21
23
  end
22
24
 
23
25
  def file_name
24
- raise NotImplementedError.new("You must implement the file_name method.")
26
+ raise NotImplementedError.new("The #{self.class} class must implement the #{__method__} method.")
25
27
  end
26
28
 
27
29
  def render
28
- raise NotImplementedError.new("You must implement the render method.")
30
+ raise NotImplementedError.new("The #{self.class} class must implement the #{__method__} method.")
29
31
  end
30
32
 
31
33
  def get_binding
@@ -3,9 +3,8 @@ require "rubycritic/report_generators/base_generator"
3
3
 
4
4
  module Rubycritic
5
5
 
6
- class IndexGenerator < BaseGenerator
7
- INDEX_TEMPLATE = ERB.new(File.read(File.join(TEMPLATES_DIR, "index.html.erb")))
8
- LAYOUT_TEMPLATE = ERB.new(File.read(File.join(TEMPLATES_DIR, "layouts", "application.html.erb")))
6
+ class CodeIndexGenerator < BaseGenerator
7
+ TEMPLATE = ERB.new(File.read(File.join(TEMPLATES_DIR, "code_index.html.erb")))
9
8
 
10
9
  def initialize(file_generators)
11
10
  @file_generators = file_generators.sort { |a, b| a.analysed_file_name <=> b.analysed_file_name }
@@ -16,11 +15,11 @@ module Rubycritic
16
15
  end
17
16
 
18
17
  def file_name
19
- "index.html"
18
+ "code_index.html"
20
19
  end
21
20
 
22
21
  def render
23
- index_body = INDEX_TEMPLATE.result(get_binding)
22
+ index_body = TEMPLATE.result(get_binding)
24
23
  LAYOUT_TEMPLATE.result(get_binding { index_body })
25
24
  end
26
25
  end
@@ -6,8 +6,7 @@ module Rubycritic
6
6
 
7
7
  class FileGenerator < BaseGenerator
8
8
  LINE_NUMBER_OFFSET = 1
9
- FILE_TEMPLATE = ERB.new(File.read(File.join(TEMPLATES_DIR, "file.html.erb")))
10
- LAYOUT_TEMPLATE = ERB.new(File.read(File.join(TEMPLATES_DIR, "layouts", "application.html.erb")))
9
+ TEMPLATE = ERB.new(File.read(File.join(TEMPLATES_DIR, "file.html.erb")))
11
10
 
12
11
  def initialize(pathname, smells)
13
12
  @pathname = pathname
@@ -34,9 +33,13 @@ module Rubycritic
34
33
  file_code << LineGenerator.new(line_text, line_smells).render
35
34
  end
36
35
 
37
- file_body = FILE_TEMPLATE.result(get_binding { file_code })
36
+ file_body = TEMPLATE.result(get_binding { file_code })
38
37
  LAYOUT_TEMPLATE.result(get_binding { file_body })
39
38
  end
39
+
40
+ def file_has_smells?
41
+ !@smells.empty?
42
+ end
40
43
  end
41
44
 
42
45
  end
@@ -1,6 +1,7 @@
1
1
  require "rubycritic/report_generators/base_generator"
2
2
  require "rubycritic/report_generators/file_generator"
3
- require "rubycritic/report_generators/index_generator"
3
+ require "rubycritic/report_generators/code_index_generator"
4
+ require "rubycritic/report_generators/smells_index_generator"
4
5
  require "fileutils"
5
6
 
6
7
  module Rubycritic
@@ -8,9 +9,10 @@ module Rubycritic
8
9
  class Reporter
9
10
  ASSETS_DIR = File.expand_path("../assets", __FILE__)
10
11
 
11
- def initialize(source_pathnames, smelly_pathnames)
12
+ def initialize(source_pathnames, smells)
12
13
  @source_pathnames = source_pathnames
13
- @smelly_pathnames = smelly_pathnames
14
+ @smells = smells
15
+ @smelly_pathnames = pathnames_to_files_with_smells
14
16
  end
15
17
 
16
18
  def generate_report
@@ -21,17 +23,21 @@ module Rubycritic
21
23
  end
22
24
  end
23
25
  FileUtils.cp_r(ASSETS_DIR, BaseGenerator::REPORT_DIR)
24
- index_generator.file_href
26
+ code_index_generator.file_href
25
27
  end
26
28
 
27
29
  private
28
30
 
29
31
  def generators
30
- file_generators + [index_generator]
32
+ [code_index_generator, smells_index_generator] + file_generators
31
33
  end
32
34
 
33
- def index_generator
34
- @index_generator ||= IndexGenerator.new(file_generators)
35
+ def code_index_generator
36
+ @code_index_generator ||= CodeIndexGenerator.new(file_generators)
37
+ end
38
+
39
+ def smells_index_generator
40
+ @smells_index_generator ||= SmellsIndexGenerator.new(@smells)
35
41
  end
36
42
 
37
43
  def file_generators
@@ -40,6 +46,16 @@ module Rubycritic
40
46
  FileGenerator.new(file_pathname, file_smells)
41
47
  end
42
48
  end
49
+
50
+ def pathnames_to_files_with_smells
51
+ pathnames = Hash.new { |hash, key| hash[key] = [] }
52
+ @smells.each do |smell|
53
+ smell.pathnames.each do |path|
54
+ pathnames[path] << smell
55
+ end
56
+ end
57
+ pathnames
58
+ end
43
59
  end
44
60
 
45
61
  end
@@ -0,0 +1,27 @@
1
+ require "erb"
2
+ require "rubycritic/report_generators/base_generator"
3
+
4
+ module Rubycritic
5
+
6
+ class SmellsIndexGenerator < BaseGenerator
7
+ TEMPLATE = ERB.new(File.read(File.join(TEMPLATES_DIR, "smells_index.html.erb")))
8
+
9
+ def initialize(smells)
10
+ @smells = smells.sort { |a, b| a.type <=> b.type }
11
+ end
12
+
13
+ def file_directory
14
+ REPORT_DIR
15
+ end
16
+
17
+ def file_name
18
+ "smells_index.html"
19
+ end
20
+
21
+ def render
22
+ index_body = TEMPLATE.result(get_binding)
23
+ LAYOUT_TEMPLATE.result(get_binding { index_body })
24
+ end
25
+ end
26
+
27
+ end
@@ -1,4 +1,4 @@
1
- <table>
1
+ <table class="code-table">
2
2
  <thead>
3
3
  <tr>
4
4
  <th>Name</th>
@@ -1,3 +1,9 @@
1
- <button id="js-toggle-smells">Toggle Smells</button>
1
+ <div class="file-header">
2
+ <h2 class="file-name"><%= analysed_file_name %></h2>
3
+
4
+ <% if file_has_smells? %>
5
+ <button id="js-toggle-smells" class="smells-toggle-button button">Toggle Smells</button>
6
+ <% end %>
7
+ </div>
2
8
 
3
9
  <code class="prettyprint linenums lang-ruby file-code js-file-code"><%= yield %></code>
@@ -1,19 +1,24 @@
1
1
  <!DOCTYPE html>
2
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>
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta http-equiv="X-UA-Compatible" content="IE=edge">
6
+ <title>Ruby Critic</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="viewport" content="width=device-width, initial-scale=1">
10
+ </head>
11
+ <body>
12
+ <header class="project-header group">
13
+ <h1 class="logo"><a href="<%= code_index_path %>" class="logo-link">Ruby Critic</a></h1>
14
+ <nav class="project-nav">
15
+ <a href="<%= code_index_path %>" class="project-nav-item">Code</a>
16
+ <a href="<%= smells_index_path %>" class="project-nav-item">Smells</a>
17
+ </nav>
18
+ </header>
19
+ <%= yield %>
20
+ <script src="<%= javascript_path(:'jquery-2.1.0') %>"></script>
21
+ <script src="<%= javascript_path(:prettify) %>"></script>
22
+ <script src="<%= javascript_path(:application) %>"></script>
23
+ </body>
19
24
  </html>
@@ -0,0 +1,20 @@
1
+ <table class="smells-table">
2
+ <thead>
3
+ <tr>
4
+ <th>Smell</th>
5
+ <th>Locations</th>
6
+ </tr>
7
+ </thead>
8
+ <tbody>
9
+ <% @smells.each do |smell| %>
10
+ <tr>
11
+ <td><%= smell.type %></td>
12
+ <td>
13
+ <% smell.locations.each do |location| %>
14
+ <a href="<%= smell_location_path(location) %>"><%= location.file_name %></a>
15
+ <% end %>
16
+ </td>
17
+ </tr>
18
+ <% end %>
19
+ </tbody>
20
+ </table>
@@ -18,8 +18,17 @@ module Rubycritic
18
18
  File.join(root_directory, "#{pathname.sub_ext('.html')}#L#{location.line}")
19
19
  end
20
20
 
21
- def index_path
22
- File.join(root_directory, "index.html")
21
+ def code_index_path
22
+ File.join(root_directory, "code_index.html")
23
+ end
24
+
25
+ def smells_index_path
26
+ File.join(root_directory, "smells_index.html")
27
+ end
28
+
29
+ # Includers must override
30
+ def root_directory
31
+ raise NotImplementedError.new("The #{self.class} class must implement the #{__method__} method.")
23
32
  end
24
33
  end
25
34
 
@@ -1,4 +1,4 @@
1
- require "rubycritic/smelly_pathnames_serializer"
1
+ require "rubycritic/smells_serializer"
2
2
  require "rubycritic/source_locator"
3
3
  require "rubycritic/analysers_runner"
4
4
  require "rubycritic/smells_aggregator"
@@ -9,40 +9,32 @@ module Rubycritic
9
9
  class RevisionComparator
10
10
  SNAPSHOTS_DIR = File.expand_path("tmp/rubycritic/snapshots", Dir.getwd)
11
11
 
12
- def initialize(paths, source_control_system)
13
- @paths = paths
12
+ def initialize(smells, source_control_system)
13
+ @smells_now = smells
14
14
  @source_control_system = source_control_system
15
15
  end
16
16
 
17
- def compare
18
- SmellsStatusSetter.new(smelly_pathnames_before, smelly_pathnames_now).smelly_pathnames
17
+ def smells
18
+ SmellsStatusSetter.new(smells_before, @smells_now).smells
19
19
  end
20
20
 
21
21
  private
22
22
 
23
- def smelly_pathnames_before
24
- serializer = SmellyPathnamesSerializer.new(revision_file)
23
+ def smells_before
24
+ serializer = SmellsSerializer.new(revision_file)
25
25
  if File.file?(revision_file)
26
26
  serializer.load
27
27
  else
28
- smelly_pathnames = nil
28
+ smells = nil
29
29
  @source_control_system.travel_to_head do
30
- smelly_pathnames = smelly_pathnames(paths_of_tracked_files)
30
+ smell_adapters = AnalysersRunner.new(paths_of_tracked_files).run
31
+ smells = SmellsAggregator.new(smell_adapters).smells
31
32
  end
32
- serializer.dump(smelly_pathnames)
33
- smelly_pathnames
33
+ serializer.dump(smells)
34
+ smells
34
35
  end
35
36
  end
36
37
 
37
- def smelly_pathnames_now
38
- smelly_pathnames(@paths)
39
- end
40
-
41
- def smelly_pathnames(paths)
42
- smell_adapters = AnalysersRunner.new(paths).run
43
- SmellsAggregator.new(smell_adapters).smelly_pathnames
44
- end
45
-
46
38
  def revision_file
47
39
  @revision_file ||= File.join(SNAPSHOTS_DIR, @source_control_system.head_reference)
48
40
  end
@@ -8,22 +8,6 @@ module Rubycritic
8
8
  def smells
9
9
  @smells ||= @smell_adapters.map(&:smells).flatten.sort
10
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
11
  end
28
12
 
29
13
  end
@@ -2,7 +2,7 @@ require "fileutils"
2
2
 
3
3
  module Rubycritic
4
4
 
5
- class SmellyPathnamesSerializer
5
+ class SmellsSerializer
6
6
  def initialize(file_name)
7
7
  @file_name = file_name
8
8
  end
@@ -11,12 +11,10 @@ module Rubycritic
11
11
  Marshal.load(File.binread(@file_name))
12
12
  end
13
13
 
14
- def dump(smelly_pathnames)
14
+ def dump(smells)
15
15
  create_file_directory
16
- # HACK It's not possible to Marshal procs or lambdas.
17
- smelly_pathnames.default = []
18
16
  File.open(@file_name, "w+") do |file|
19
- Marshal.dump(smelly_pathnames, file)
17
+ Marshal.dump(smells, file)
20
18
  end
21
19
  end
22
20
 
@@ -1,20 +1,17 @@
1
1
  module Rubycritic
2
2
 
3
3
  class SmellsStatusSetter
4
- def initialize(smelly_pathnames_before, smelly_pathnames_now)
5
- @smelly_pathnames_before = smelly_pathnames_before
6
- @smelly_pathnames_now = smelly_pathnames_now
4
+ def initialize(smells_before, smells_now)
5
+ @smells_before = smells_before || []
6
+ @smells_now = smells_now
7
7
  end
8
8
 
9
- def smelly_pathnames
10
- @smelly_pathnames_now.each do |pathname, smells_now|
11
- smells_before = @smelly_pathnames_before[pathname] || []
12
- old_smells = smells_now & smells_before
13
- set_status(old_smells, :old)
14
- new_smells = smells_now - smells_before
15
- set_status(new_smells, :new)
16
- end
17
- @smelly_pathnames_now
9
+ def smells
10
+ old_smells = @smells_now & @smells_before
11
+ set_status(old_smells, :old)
12
+ new_smells = @smells_now - @smells_before
13
+ set_status(new_smells, :new)
14
+ @smells_now
18
15
  end
19
16
 
20
17
  private
@@ -24,16 +24,20 @@ module Rubycritic
24
24
  systems.join(", ")
25
25
  end
26
26
 
27
+ def self.supported?
28
+ raise NotImplementedError.new("The #{self.class} class must implement the #{__method__} method.")
29
+ end
30
+
27
31
  def has_revision?
28
- raise NotImplementedError.new("You must implement the has_revision? method.")
32
+ raise NotImplementedError.new("The #{self.class} class must implement the #{__method__} method.")
29
33
  end
30
34
 
31
35
  def head_reference
32
- raise NotImplementedError.new("You must implement the head_reference method.")
36
+ raise NotImplementedError.new("The #{self.class} class must implement the #{__method__} method.")
33
37
  end
34
38
 
35
39
  def travel_to_head
36
- raise NotImplementedError.new("You must implement the travel_to_head method.")
40
+ raise NotImplementedError.new("The #{self.class} class must implement the #{__method__} method.")
37
41
  end
38
42
  end
39
43
 
@@ -1,3 +1,3 @@
1
1
  module Rubycritic
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
@@ -4,7 +4,7 @@ require "rubycritic/location"
4
4
  describe Rubycritic::Location do
5
5
  describe "attribute readers" do
6
6
  before do
7
- @path = "./foo"
7
+ @path = "./foo.rb"
8
8
  @line = 42
9
9
  @location = Rubycritic::Location.new(@path, @line)
10
10
  end
@@ -16,6 +16,10 @@ describe Rubycritic::Location do
16
16
  it "has a line number" do
17
17
  @location.line.must_equal @line
18
18
  end
19
+
20
+ it "has a file name" do
21
+ @location.file_name.must_equal "foo"
22
+ end
19
23
  end
20
24
 
21
25
  it "is comparable" do
@@ -4,43 +4,28 @@ require "rubycritic/smells_aggregator"
4
4
  describe Rubycritic::SmellsAggregator do
5
5
  context "when analysing smelly files" do
6
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])]
7
+ smell1 = Rubycritic::Smell.new
8
+ smell2 = Rubycritic::Smell.new
9
+ @smells = [smell2, smell1]
10
+ @smell_adapters = [stub(:smells => [smell1]), stub(:smells => [smell2])]
13
11
  end
14
12
 
15
13
  describe "#smells" do
16
14
  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
15
+ Rubycritic::SmellsAggregator.new(@smell_adapters).smells.must_equal @smells
26
16
  end
27
17
  end
28
18
  end
29
19
 
30
20
  context "when analysing files with no smells" do
31
21
  before do
32
- @smell_adapters = [stub(:smells => [])]
22
+ @smells = []
23
+ @smell_adapters = [stub(:smells => @smells)]
33
24
  end
34
25
 
35
26
  describe "#smells" do
36
27
  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({})
28
+ Rubycritic::SmellsAggregator.new(@smell_adapters).smells.must_equal @smells
44
29
  end
45
30
  end
46
31
  end
@@ -3,19 +3,19 @@ require "rubycritic/smell"
3
3
  require "rubycritic/smells_status_setter"
4
4
 
5
5
  describe Rubycritic::SmellsStatusSetter do
6
- describe "#smelly_pathnames" do
6
+ describe "#smells" do
7
7
  before do
8
8
  @smell = Rubycritic::Smell.new(:context => "#bar")
9
- @smelly_pathnames = { "file0.rb" => [@smell] }
9
+ @smells = [@smell]
10
10
  end
11
11
 
12
12
  it "marks old smells" do
13
- Rubycritic::SmellsStatusSetter.new(@smelly_pathnames, @smelly_pathnames).smelly_pathnames
13
+ Rubycritic::SmellsStatusSetter.new(@smells, @smells).smells
14
14
  @smell.status.must_equal :old
15
15
  end
16
16
 
17
17
  it "marks new smells" do
18
- Rubycritic::SmellsStatusSetter.new({}, @smelly_pathnames).smelly_pathnames
18
+ Rubycritic::SmellsStatusSetter.new([], @smells).smells
19
19
  @smell.status.must_equal :new
20
20
  end
21
21
  end
@@ -19,7 +19,8 @@ describe Rubycritic::SourceControlSystem do
19
19
 
20
20
  describe "when no source control system is found" do
21
21
  it "raises an error" do
22
- proc { Rubycritic::SourceControlSystem.create }.must_raise RuntimeError
22
+ error = proc { Rubycritic::SourceControlSystem.create }.must_raise RuntimeError
23
+ error.message.must_match "Rubycritic requires a Git repository."
23
24
  end
24
25
  end
25
26
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubycritic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Guilherme Simoes
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-25 00:00:00.000000000 Z
11
+ date: 2014-04-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: virtus
@@ -154,14 +154,16 @@ files:
154
154
  - lib/rubycritic/report_generators/assets/stylesheets/application.css
155
155
  - lib/rubycritic/report_generators/assets/stylesheets/prettify.custom_theme.css
156
156
  - lib/rubycritic/report_generators/base_generator.rb
157
+ - lib/rubycritic/report_generators/code_index_generator.rb
157
158
  - lib/rubycritic/report_generators/file_generator.rb
158
- - lib/rubycritic/report_generators/index_generator.rb
159
159
  - lib/rubycritic/report_generators/line_generator.rb
160
160
  - lib/rubycritic/report_generators/reporter.rb
161
+ - lib/rubycritic/report_generators/smells_index_generator.rb
162
+ - lib/rubycritic/report_generators/templates/code_index.html.erb
161
163
  - lib/rubycritic/report_generators/templates/file.html.erb
162
- - lib/rubycritic/report_generators/templates/index.html.erb
163
164
  - lib/rubycritic/report_generators/templates/layouts/application.html.erb
164
165
  - lib/rubycritic/report_generators/templates/line.html.erb
166
+ - lib/rubycritic/report_generators/templates/smells_index.html.erb
165
167
  - lib/rubycritic/report_generators/templates/smelly_line.html.erb
166
168
  - lib/rubycritic/report_generators/view_helpers.rb
167
169
  - lib/rubycritic/revision_comparator.rb
@@ -170,8 +172,8 @@ files:
170
172
  - lib/rubycritic/smell_adapters/flog.rb
171
173
  - lib/rubycritic/smell_adapters/reek.rb
172
174
  - lib/rubycritic/smells_aggregator.rb
175
+ - lib/rubycritic/smells_serializer.rb
173
176
  - lib/rubycritic/smells_status_setter.rb
174
- - lib/rubycritic/smelly_pathnames_serializer.rb
175
177
  - lib/rubycritic/source_control_systems/git.rb
176
178
  - lib/rubycritic/source_control_systems/source_control_system.rb
177
179
  - lib/rubycritic/source_locator.rb