rubycritic 2.6.0 → 2.7.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 +3 -585
- data/.rubocop_todo.yml +36 -0
- data/CHANGELOG.md +6 -0
- data/Gemfile +1 -1
- data/Rakefile +9 -9
- data/bin/rubycritic +2 -2
- data/features/command_line_interface/options.feature +1 -0
- data/features/step_definitions/rubycritic_steps.rb +1 -1
- data/features/step_definitions/sample_file_steps.rb +3 -3
- data/features/support/env.rb +6 -6
- data/lib/rubycritic.rb +1 -1
- data/lib/rubycritic/analysers/attributes.rb +6 -7
- data/lib/rubycritic/analysers/churn.rb +4 -6
- data/lib/rubycritic/analysers/complexity.rb +5 -7
- data/lib/rubycritic/analysers/helpers/ast_node.rb +4 -6
- data/lib/rubycritic/analysers/helpers/flay.rb +1 -3
- data/lib/rubycritic/analysers/helpers/flog.rb +5 -7
- data/lib/rubycritic/analysers/helpers/methods_counter.rb +1 -3
- data/lib/rubycritic/analysers/helpers/modules_locator.rb +3 -5
- data/lib/rubycritic/analysers/helpers/parser.rb +2 -2
- data/lib/rubycritic/analysers/helpers/reek.rb +1 -1
- data/lib/rubycritic/analysers/smells/flay.rb +14 -16
- data/lib/rubycritic/analysers/smells/flog.rb +15 -17
- data/lib/rubycritic/analysers/smells/reek.rb +11 -13
- data/lib/rubycritic/analysers_runner.rb +8 -10
- data/lib/rubycritic/browser.rb +17 -0
- data/lib/rubycritic/cli/application.rb +3 -3
- data/lib/rubycritic/cli/options.rb +29 -23
- data/lib/rubycritic/command_factory.rb +5 -5
- data/lib/rubycritic/commands/base.rb +2 -2
- data/lib/rubycritic/commands/ci.rb +4 -4
- data/lib/rubycritic/commands/default.rb +5 -5
- data/lib/rubycritic/commands/help.rb +1 -1
- data/lib/rubycritic/commands/status_reporter.rb +1 -1
- data/lib/rubycritic/commands/version.rb +2 -2
- data/lib/rubycritic/configuration.rb +4 -2
- data/lib/rubycritic/core/analysed_module.rb +15 -17
- data/lib/rubycritic/core/analysed_modules_collection.rb +3 -3
- data/lib/rubycritic/core/location.rb +4 -6
- data/lib/rubycritic/core/rating.rb +5 -7
- data/lib/rubycritic/core/smell.rb +11 -13
- data/lib/rubycritic/generators/console_report.rb +1 -1
- data/lib/rubycritic/generators/html/base.rb +9 -9
- data/lib/rubycritic/generators/html/code_file.rb +5 -7
- data/lib/rubycritic/generators/html/code_index.rb +3 -5
- data/lib/rubycritic/generators/html/line.rb +4 -6
- data/lib/rubycritic/generators/html/overview.rb +4 -6
- data/lib/rubycritic/generators/html/smells_index.rb +3 -5
- data/lib/rubycritic/generators/html/turbulence.rb +4 -6
- data/lib/rubycritic/generators/html/view_helpers.rb +4 -4
- data/lib/rubycritic/generators/html_report.rb +13 -9
- data/lib/rubycritic/generators/json/simple.rb +7 -9
- data/lib/rubycritic/generators/json_report.rb +1 -3
- data/lib/rubycritic/generators/text/list.rb +9 -9
- data/lib/rubycritic/reporter.rb +3 -5
- data/lib/rubycritic/revision_comparator.rb +6 -8
- data/lib/rubycritic/serializer.rb +2 -4
- data/lib/rubycritic/smells_status_setter.rb +2 -4
- data/lib/rubycritic/source_control_systems/base.rb +4 -6
- data/lib/rubycritic/source_control_systems/double.rb +1 -2
- data/lib/rubycritic/source_control_systems/git.rb +1 -3
- data/lib/rubycritic/source_control_systems/mercurial.rb +1 -3
- data/lib/rubycritic/source_locator.rb +5 -6
- data/lib/rubycritic/version.rb +1 -1
- data/rubycritic.gemspec +26 -25
- data/test/analysers_test_helper.rb +1 -1
- data/test/lib/rubycritic/analysers/churn_test.rb +9 -9
- data/test/lib/rubycritic/analysers/complexity_test.rb +5 -5
- data/test/lib/rubycritic/analysers/helpers/methods_counter_test.rb +12 -12
- data/test/lib/rubycritic/analysers/helpers/modules_locator_test.rb +25 -25
- data/test/lib/rubycritic/analysers/smells/flay_test.rb +12 -12
- data/test/lib/rubycritic/analysers/smells/flog_test.rb +7 -7
- data/test/lib/rubycritic/analysers/smells/reek_test.rb +8 -8
- data/test/lib/rubycritic/browser_test.rb +16 -0
- data/test/lib/rubycritic/commands/status_reporter_test.rb +31 -19
- data/test/lib/rubycritic/configuration_test.rb +10 -10
- data/test/lib/rubycritic/core/analysed_module_test.rb +37 -37
- data/test/lib/rubycritic/core/analysed_modules_collection_test.rb +32 -32
- data/test/lib/rubycritic/core/location_test.rb +16 -16
- data/test/lib/rubycritic/core/smell_test.rb +31 -31
- data/test/lib/rubycritic/core/smells_array_test.rb +18 -18
- data/test/lib/rubycritic/generators/console_report_test.rb +26 -26
- data/test/lib/rubycritic/generators/turbulence_test.rb +8 -8
- data/test/lib/rubycritic/generators/view_helpers_test.rb +36 -36
- data/test/lib/rubycritic/smells_status_setter_test.rb +7 -7
- data/test/lib/rubycritic/source_control_systems/base_test.rb +7 -7
- data/test/lib/rubycritic/source_control_systems/double_test.rb +3 -3
- data/test/lib/rubycritic/source_control_systems/git_test.rb +4 -4
- data/test/lib/rubycritic/source_control_systems/mercurial_test.rb +3 -3
- data/test/lib/rubycritic/source_locator_test.rb +30 -30
- data/test/lib/rubycritic/version_test.rb +4 -4
- data/test/test_helper.rb +4 -4
- metadata +30 -17
@@ -1,8 +1,7 @@
|
|
1
|
-
require
|
1
|
+
require 'rubycritic/generators/json/simple'
|
2
2
|
|
3
3
|
module Rubycritic
|
4
4
|
module Generator
|
5
|
-
|
6
5
|
class JsonReport
|
7
6
|
def initialize(analysed_modules)
|
8
7
|
@analysed_modules = analysed_modules
|
@@ -18,6 +17,5 @@ module Rubycritic
|
|
18
17
|
Json::Simple.new(@analysed_modules)
|
19
18
|
end
|
20
19
|
end
|
21
|
-
|
22
20
|
end
|
23
21
|
end
|
@@ -1,24 +1,24 @@
|
|
1
|
-
require
|
1
|
+
require 'colorize'
|
2
2
|
|
3
3
|
module Rubycritic
|
4
4
|
module Generator
|
5
5
|
module Text
|
6
6
|
class List
|
7
7
|
class << self
|
8
|
-
TEMPLATE_PATH = File.expand_path(
|
8
|
+
TEMPLATE_PATH = File.expand_path('../templates/list.erb', __FILE__)
|
9
9
|
|
10
10
|
def erb_template
|
11
|
-
@erb_template ||= ERB.new(File.read(TEMPLATE_PATH), nil,
|
11
|
+
@erb_template ||= ERB.new(File.read(TEMPLATE_PATH), nil, '-')
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
15
|
RATING_TO_COLOR = {
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
}
|
16
|
+
'A' => :green,
|
17
|
+
'B' => :green,
|
18
|
+
'C' => :yellow,
|
19
|
+
'D' => :light_red,
|
20
|
+
'F' => :red
|
21
|
+
}.freeze
|
22
22
|
|
23
23
|
def initialize(analysed_module)
|
24
24
|
@analysed_module = analysed_module
|
data/lib/rubycritic/reporter.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
module Rubycritic
|
2
|
-
|
3
2
|
module Reporter
|
4
3
|
def self.generate_report(analysed_modules)
|
5
4
|
report_generator_class.new(analysed_modules).generate_report
|
@@ -8,16 +7,15 @@ module Rubycritic
|
|
8
7
|
def self.report_generator_class
|
9
8
|
case Config.format
|
10
9
|
when :json
|
11
|
-
require
|
10
|
+
require 'rubycritic/generators/json_report'
|
12
11
|
Generator::JsonReport
|
13
12
|
when :console
|
14
|
-
require
|
13
|
+
require 'rubycritic/generators/console_report'
|
15
14
|
Generator::ConsoleReport
|
16
15
|
else
|
17
|
-
require
|
16
|
+
require 'rubycritic/generators/html_report'
|
18
17
|
Generator::HtmlReport
|
19
18
|
end
|
20
19
|
end
|
21
20
|
end
|
22
|
-
|
23
21
|
end
|
@@ -1,13 +1,12 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
1
|
+
require 'rubycritic/serializer'
|
2
|
+
require 'rubycritic/analysers_runner'
|
3
|
+
require 'rubycritic/smells_status_setter'
|
4
|
+
require 'rubycritic/version'
|
5
|
+
require 'digest/md5'
|
6
6
|
|
7
7
|
module Rubycritic
|
8
|
-
|
9
8
|
class RevisionComparator
|
10
|
-
SNAPSHOTS_DIR_NAME =
|
9
|
+
SNAPSHOTS_DIR_NAME = 'snapshots'.freeze
|
11
10
|
|
12
11
|
def initialize(paths)
|
13
12
|
@paths = paths
|
@@ -49,5 +48,4 @@ module Rubycritic
|
|
49
48
|
)
|
50
49
|
end
|
51
50
|
end
|
52
|
-
|
53
51
|
end
|
@@ -1,7 +1,6 @@
|
|
1
|
-
require
|
1
|
+
require 'fileutils'
|
2
2
|
|
3
3
|
module Rubycritic
|
4
|
-
|
5
4
|
class Serializer
|
6
5
|
def initialize(file)
|
7
6
|
@file = file
|
@@ -13,7 +12,7 @@ module Rubycritic
|
|
13
12
|
|
14
13
|
def dump(content)
|
15
14
|
create_file_directory
|
16
|
-
File.open(@file,
|
15
|
+
File.open(@file, 'w+') do |file|
|
17
16
|
Marshal.dump(content, file)
|
18
17
|
end
|
19
18
|
end
|
@@ -28,5 +27,4 @@ module Rubycritic
|
|
28
27
|
File.dirname(@file)
|
29
28
|
end
|
30
29
|
end
|
31
|
-
|
32
30
|
end
|
@@ -1,5 +1,4 @@
|
|
1
1
|
module Rubycritic
|
2
|
-
|
3
2
|
module SmellsStatusSetter
|
4
3
|
def self.set(smells_before, smells_now)
|
5
4
|
old_smells = smells_now & smells_before
|
@@ -8,11 +7,10 @@ module Rubycritic
|
|
8
7
|
set_status(new_smells, :new)
|
9
8
|
end
|
10
9
|
|
11
|
-
private
|
12
|
-
|
13
10
|
def self.set_status(smells, status)
|
14
11
|
smells.each { |smell| smell.status = status }
|
15
12
|
end
|
16
|
-
end
|
17
13
|
|
14
|
+
private_class_method :set_status
|
15
|
+
end
|
18
16
|
end
|
@@ -1,8 +1,7 @@
|
|
1
|
-
require
|
1
|
+
require 'shellwords'
|
2
2
|
|
3
3
|
module Rubycritic
|
4
4
|
module SourceControlSystem
|
5
|
-
|
6
5
|
class Base
|
7
6
|
@@systems = []
|
8
7
|
|
@@ -28,10 +27,9 @@ module Rubycritic
|
|
28
27
|
"#{systems[0...-1].join(', ')} or #{systems[-1]}"
|
29
28
|
end
|
30
29
|
end
|
31
|
-
|
32
30
|
end
|
33
31
|
end
|
34
32
|
|
35
|
-
require
|
36
|
-
require
|
37
|
-
require
|
33
|
+
require 'rubycritic/source_control_systems/double'
|
34
|
+
require 'rubycritic/source_control_systems/git'
|
35
|
+
require 'rubycritic/source_control_systems/mercurial'
|
@@ -1,6 +1,5 @@
|
|
1
1
|
module Rubycritic
|
2
2
|
module SourceControlSystem
|
3
|
-
|
4
3
|
class Git < Base
|
5
4
|
register_system
|
6
5
|
|
@@ -9,7 +8,7 @@ module Rubycritic
|
|
9
8
|
end
|
10
9
|
|
11
10
|
def self.to_s
|
12
|
-
|
11
|
+
'Git'
|
13
12
|
end
|
14
13
|
|
15
14
|
def revisions_count(path)
|
@@ -52,6 +51,5 @@ module Rubycritic
|
|
52
51
|
`git stash pop`
|
53
52
|
end
|
54
53
|
end
|
55
|
-
|
56
54
|
end
|
57
55
|
end
|
@@ -1,6 +1,5 @@
|
|
1
1
|
module Rubycritic
|
2
2
|
module SourceControlSystem
|
3
|
-
|
4
3
|
class Mercurial < Base
|
5
4
|
register_system
|
6
5
|
|
@@ -9,7 +8,7 @@ module Rubycritic
|
|
9
8
|
end
|
10
9
|
|
11
10
|
def self.to_s
|
12
|
-
|
11
|
+
'Mercurial'
|
13
12
|
end
|
14
13
|
|
15
14
|
def revisions_count(path)
|
@@ -24,6 +23,5 @@ module Rubycritic
|
|
24
23
|
false
|
25
24
|
end
|
26
25
|
end
|
27
|
-
|
28
26
|
end
|
29
27
|
end
|
@@ -1,10 +1,9 @@
|
|
1
|
-
require
|
1
|
+
require 'pathname'
|
2
2
|
|
3
3
|
module Rubycritic
|
4
|
-
|
5
4
|
class SourceLocator
|
6
|
-
RUBY_EXTENSION =
|
7
|
-
RUBY_FILES = File.join(
|
5
|
+
RUBY_EXTENSION = '.rb'.freeze
|
6
|
+
RUBY_FILES = File.join('**', "*#{RUBY_EXTENSION}")
|
8
7
|
|
9
8
|
def initialize(paths)
|
10
9
|
@initial_paths = Array(paths)
|
@@ -22,9 +21,9 @@ module Rubycritic
|
|
22
21
|
|
23
22
|
def deduplicate_symlinks(path_list)
|
24
23
|
# sort the symlinks to the end so files are preferred
|
25
|
-
path_list.sort_by! { |path| File.symlink?(path.cleanpath) ?
|
24
|
+
path_list.sort_by! { |path| File.symlink?(path.cleanpath) ? 'z' : 'a' }
|
26
25
|
if defined?(JRUBY_VERSION)
|
27
|
-
require
|
26
|
+
require 'java'
|
28
27
|
path_list.uniq! do |path|
|
29
28
|
java.io.File.new(path.realpath.to_s).canonical_path
|
30
29
|
end
|
data/lib/rubycritic/version.rb
CHANGED
data/rubycritic.gemspec
CHANGED
@@ -1,37 +1,38 @@
|
|
1
1
|
# coding: utf-8
|
2
|
-
lib = File.expand_path(
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require
|
4
|
+
require 'rubycritic/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
7
|
+
spec.name = 'rubycritic'
|
8
8
|
spec.version = Rubycritic::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
11
|
-
spec.description =
|
12
|
-
|
13
|
-
spec.summary =
|
14
|
-
spec.homepage =
|
15
|
-
spec.license =
|
16
|
-
spec.required_ruby_version =
|
9
|
+
spec.authors = ['Guilherme Simoes']
|
10
|
+
spec.email = ['guilherme.rdems@gmail.com']
|
11
|
+
spec.description = 'RubyCritic is a tool that wraps around various static analysis gems '\
|
12
|
+
'to provide a quality report of your Ruby code.'
|
13
|
+
spec.summary = 'RubyCritic is a Ruby code quality reporter'
|
14
|
+
spec.homepage = 'https://github.com/whitesmith/rubycritic'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
spec.required_ruby_version = '>= 2.0.0'
|
17
17
|
|
18
18
|
spec.files = `git ls-files`.split("\n")
|
19
19
|
spec.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
20
20
|
spec.test_files = `git ls-files -- test/*`.split("\n")
|
21
|
-
spec.require_path =
|
21
|
+
spec.require_path = 'lib'
|
22
22
|
|
23
|
-
spec.add_runtime_dependency
|
24
|
-
spec.add_runtime_dependency
|
25
|
-
spec.add_runtime_dependency
|
26
|
-
spec.add_runtime_dependency
|
27
|
-
spec.add_runtime_dependency
|
28
|
-
spec.add_runtime_dependency
|
23
|
+
spec.add_runtime_dependency 'virtus', '~> 1.0'
|
24
|
+
spec.add_runtime_dependency 'flay', '2.6.1'
|
25
|
+
spec.add_runtime_dependency 'flog', '4.3.2'
|
26
|
+
spec.add_runtime_dependency 'reek', '3.9.1'
|
27
|
+
spec.add_runtime_dependency 'parser', '~> 2.3'
|
28
|
+
spec.add_runtime_dependency 'colorize'
|
29
|
+
spec.add_runtime_dependency 'launchy', '2.4.3'
|
29
30
|
|
30
|
-
spec.add_development_dependency
|
31
|
-
spec.add_development_dependency
|
32
|
-
spec.add_development_dependency
|
33
|
-
spec.add_development_dependency
|
34
|
-
spec.add_development_dependency
|
35
|
-
spec.add_development_dependency
|
36
|
-
spec.add_development_dependency
|
31
|
+
spec.add_development_dependency 'aruba'
|
32
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
33
|
+
spec.add_development_dependency 'cucumber'
|
34
|
+
spec.add_development_dependency 'rake'
|
35
|
+
spec.add_development_dependency 'minitest', '~> 5.3'
|
36
|
+
spec.add_development_dependency 'mocha', '~> 1.0'
|
37
|
+
spec.add_development_dependency 'rubocop', '0.36.0'
|
37
38
|
end
|
@@ -1,23 +1,23 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require 'analysers_test_helper'
|
2
|
+
require 'rubycritic/analysers/churn'
|
3
|
+
require 'rubycritic/source_control_systems/base'
|
4
4
|
|
5
5
|
describe Rubycritic::Analyser::Churn do
|
6
|
-
context
|
6
|
+
context 'when analysing a file' do
|
7
7
|
before do
|
8
|
-
@analysed_module = AnalysedModuleDouble.new(:
|
8
|
+
@analysed_module = AnalysedModuleDouble.new(path: 'path_to_some_file.rb')
|
9
9
|
analysed_modules = [@analysed_module]
|
10
10
|
analyser = Rubycritic::Analyser::Churn.new(analysed_modules)
|
11
11
|
analyser.source_control_system = SourceControlSystemDouble.new
|
12
12
|
analyser.run
|
13
13
|
end
|
14
14
|
|
15
|
-
it
|
15
|
+
it 'calculates its churn' do
|
16
16
|
@analysed_module.churn.must_equal 1
|
17
17
|
end
|
18
18
|
|
19
|
-
it
|
20
|
-
@analysed_module.committed_at.must_equal
|
19
|
+
it 'determines the date of its last commit' do
|
20
|
+
@analysed_module.committed_at.must_equal '2013-10-09 12:52:49 +0100'
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
@@ -28,6 +28,6 @@ class SourceControlSystemDouble < Rubycritic::SourceControlSystem::Base
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def date_of_last_commit(_path)
|
31
|
-
|
31
|
+
'2013-10-09 12:52:49 +0100'
|
32
32
|
end
|
33
33
|
end
|
@@ -1,15 +1,15 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'analysers_test_helper'
|
2
|
+
require 'rubycritic/analysers/complexity'
|
3
3
|
|
4
4
|
describe Rubycritic::Analyser::Complexity do
|
5
|
-
context
|
5
|
+
context 'when analysing a file' do
|
6
6
|
before do
|
7
|
-
@analysed_module = AnalysedModuleDouble.new(:
|
7
|
+
@analysed_module = AnalysedModuleDouble.new(path: 'test/samples/flog/complex.rb', smells: [])
|
8
8
|
analysed_modules = [@analysed_module]
|
9
9
|
Rubycritic::Analyser::Complexity.new(analysed_modules).run
|
10
10
|
end
|
11
11
|
|
12
|
-
it
|
12
|
+
it 'calculates its complexity' do
|
13
13
|
@analysed_module.complexity.must_be :>, 0
|
14
14
|
end
|
15
15
|
end
|
@@ -1,25 +1,25 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'analysers_test_helper'
|
2
|
+
require 'rubycritic/analysers/helpers/methods_counter'
|
3
3
|
|
4
4
|
describe Rubycritic::MethodsCounter do
|
5
|
-
describe
|
6
|
-
context
|
7
|
-
it
|
8
|
-
analysed_module = AnalysedModuleDouble.new(:
|
5
|
+
describe '#count' do
|
6
|
+
context 'when a file contains Ruby code' do
|
7
|
+
it 'calculates the number of methods' do
|
8
|
+
analysed_module = AnalysedModuleDouble.new(path: 'test/samples/methods_count.rb')
|
9
9
|
Rubycritic::MethodsCounter.new(analysed_module).count.must_equal 2
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
context
|
14
|
-
it
|
15
|
-
analysed_module = AnalysedModuleDouble.new(:
|
13
|
+
context 'when a file is empty' do
|
14
|
+
it 'returns 0 as the number of methods' do
|
15
|
+
analysed_module = AnalysedModuleDouble.new(path: 'test/samples/empty.rb')
|
16
16
|
Rubycritic::MethodsCounter.new(analysed_module).count.must_equal 0
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
context
|
21
|
-
it
|
22
|
-
analysed_module = AnalysedModuleDouble.new(:
|
20
|
+
context 'when a file is unparsable' do
|
21
|
+
it 'does not blow up and returns 0 as the number of methods' do
|
22
|
+
analysed_module = AnalysedModuleDouble.new(path: 'test/samples/unparsable.rb')
|
23
23
|
capture_output_streams do
|
24
24
|
Rubycritic::MethodsCounter.new(analysed_module).count.must_equal 0
|
25
25
|
end
|
@@ -1,51 +1,51 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
1
|
+
require 'test_helper'
|
2
|
+
require 'rubycritic/analysers/helpers/modules_locator'
|
3
|
+
require 'rubycritic/core/analysed_module'
|
4
|
+
require 'pathname'
|
5
5
|
|
6
6
|
describe Rubycritic::ModulesLocator do
|
7
|
-
describe
|
8
|
-
context
|
9
|
-
it
|
7
|
+
describe '#names' do
|
8
|
+
context 'when a file contains Ruby code' do
|
9
|
+
it 'returns the names of all the classes and modules inside the file' do
|
10
10
|
analysed_module = Rubycritic::AnalysedModule.new(
|
11
|
-
:
|
12
|
-
:
|
11
|
+
pathname: Pathname.new('test/samples/module_names.rb'),
|
12
|
+
methods_count: 1
|
13
13
|
)
|
14
14
|
Rubycritic::ModulesLocator.new(analysed_module).names
|
15
|
-
|
15
|
+
.must_equal ['Foo', 'Foo::Bar', 'Foo::Baz', 'Foo::Qux', 'Foo::Quux::Corge']
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
context
|
20
|
-
it
|
19
|
+
context 'when a file is empty' do
|
20
|
+
it 'returns the name of the file titleized' do
|
21
21
|
analysed_module = Rubycritic::AnalysedModule.new(
|
22
|
-
:
|
23
|
-
:
|
22
|
+
pathname: Pathname.new('test/samples/empty.rb'),
|
23
|
+
methods_count: 1
|
24
24
|
)
|
25
|
-
Rubycritic::ModulesLocator.new(analysed_module).names.must_equal [
|
25
|
+
Rubycritic::ModulesLocator.new(analysed_module).names.must_equal ['Empty']
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
-
context
|
30
|
-
it
|
29
|
+
context 'when a file is unparsable' do
|
30
|
+
it 'does not blow up and returns the name of the file titleized' do
|
31
31
|
analysed_module = Rubycritic::AnalysedModule.new(
|
32
|
-
:
|
33
|
-
:
|
32
|
+
pathname: Pathname.new('test/samples/unparsable.rb'),
|
33
|
+
methods_count: 1
|
34
34
|
)
|
35
35
|
capture_output_streams do
|
36
|
-
Rubycritic::ModulesLocator.new(analysed_module).names.must_equal [
|
36
|
+
Rubycritic::ModulesLocator.new(analysed_module).names.must_equal ['Unparsable']
|
37
37
|
end
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
-
context
|
42
|
-
it
|
41
|
+
context 'when a file has no methods' do
|
42
|
+
it 'returns the names of all the classes and modules inside the file' do
|
43
43
|
analysed_module = Rubycritic::AnalysedModule.new(
|
44
|
-
:
|
45
|
-
:
|
44
|
+
pathname: Pathname.new('test/samples/no_methods.rb'),
|
45
|
+
methods_count: 0
|
46
46
|
)
|
47
47
|
capture_output_streams do
|
48
|
-
Rubycritic::ModulesLocator.new(analysed_module).names.must_equal [
|
48
|
+
Rubycritic::ModulesLocator.new(analysed_module).names.must_equal ['Foo::NoMethods']
|
49
49
|
end
|
50
50
|
end
|
51
51
|
end
|