reek 2.1.0 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +2 -21
- data/.travis.yml +1 -0
- data/.yardopts +3 -6
- data/CHANGELOG +6 -0
- data/CONTRIBUTING.md +8 -3
- data/README.md +94 -42
- data/config/defaults.reek +0 -1
- data/docs/API.md +50 -0
- data/docs/Attribute.md +43 -0
- data/docs/Basic-Smell-Options.md +44 -0
- data/docs/Boolean-Parameter.md +52 -0
- data/docs/Class-Variable.md +40 -0
- data/docs/Code-Smells.md +34 -0
- data/docs/Command-Line-Options.md +84 -0
- data/docs/Configuration-Files.md +38 -0
- data/docs/Control-Couple.md +22 -0
- data/docs/Control-Parameter.md +29 -0
- data/docs/Data-Clump.md +44 -0
- data/docs/Duplicate-Method-Call.md +49 -0
- data/docs/Feature-Envy.md +29 -0
- data/docs/How-reek-works-internally.md +44 -0
- data/docs/Irresponsible-Module.md +39 -0
- data/docs/Large-Class.md +20 -0
- data/docs/Long-Parameter-List.md +38 -0
- data/docs/Long-Yield-List.md +36 -0
- data/docs/Module-Initialize.md +62 -0
- data/docs/Nested-Iterators.md +38 -0
- data/docs/Nil-Check.md +39 -0
- data/docs/Prima-Donna-Method.md +53 -0
- data/docs/RSpec-matchers.md +133 -0
- data/docs/Rake-Task.md +58 -0
- data/docs/Reek-Driven-Development.md +45 -0
- data/docs/Repeated-Conditional.md +44 -0
- data/docs/Simulated-Polymorphism.md +16 -0
- data/docs/Smell-Suppression.md +32 -0
- data/docs/Too-Many-Instance-Variables.md +43 -0
- data/docs/Too-Many-Methods.md +55 -0
- data/docs/Too-Many-Statements.md +50 -0
- data/docs/Uncommunicative-Method-Name.md +24 -0
- data/docs/Uncommunicative-Module-Name.md +23 -0
- data/docs/Uncommunicative-Name.md +16 -0
- data/docs/Uncommunicative-Parameter-Name.md +24 -0
- data/docs/Uncommunicative-Variable-Name.md +24 -0
- data/docs/Unused-Parameters.md +27 -0
- data/docs/Utility-Function.md +46 -0
- data/docs/Versioning-Policy.md +7 -0
- data/docs/YAML-Reports.md +111 -0
- data/docs/yard_plugin.rb +14 -0
- data/features/command_line_interface/options.feature +1 -0
- data/features/programmatic_access.feature +1 -1
- data/features/samples.feature +3 -3
- data/lib/reek.rb +2 -2
- data/lib/reek/cli/input.rb +2 -2
- data/lib/reek/cli/option_interpreter.rb +2 -0
- data/lib/reek/cli/options.rb +10 -4
- data/lib/reek/cli/reek_command.rb +2 -2
- data/lib/reek/cli/report/report.rb +60 -0
- data/lib/reek/cli/silencer.rb +13 -0
- data/lib/reek/{source → core}/ast_node.rb +1 -1
- data/lib/reek/{source → core}/ast_node_class_map.rb +10 -11
- data/lib/reek/{source → core}/code_comment.rb +1 -1
- data/lib/reek/core/code_context.rb +1 -1
- data/lib/reek/core/examiner.rb +85 -0
- data/lib/reek/core/method_context.rb +1 -1
- data/lib/reek/core/module_context.rb +2 -2
- data/lib/reek/core/reference_collector.rb +31 -0
- data/lib/reek/core/singleton_method_context.rb +0 -4
- data/lib/reek/core/smell_repository.rb +4 -2
- data/lib/reek/{source → core}/tree_dresser.rb +1 -1
- data/lib/reek/{source → sexp}/sexp_extensions.rb +5 -5
- data/lib/reek/sexp/sexp_formatter.rb +29 -0
- data/lib/reek/sexp/sexp_node.rb +91 -0
- data/lib/reek/smells.rb +4 -2
- data/lib/reek/smells/attribute.rb +35 -7
- data/lib/reek/smells/boolean_parameter.rb +1 -1
- data/lib/reek/smells/class_variable.rb +1 -1
- data/lib/reek/smells/control_parameter.rb +1 -1
- data/lib/reek/smells/data_clump.rb +1 -1
- data/lib/reek/smells/duplicate_method_call.rb +12 -4
- data/lib/reek/smells/feature_envy.rb +1 -1
- data/lib/reek/smells/irresponsible_module.rb +3 -3
- data/lib/reek/smells/long_parameter_list.rb +1 -1
- data/lib/reek/smells/long_yield_list.rb +1 -1
- data/lib/reek/smells/module_initialize.rb +1 -1
- data/lib/reek/smells/nested_iterators.rb +1 -1
- data/lib/reek/smells/nil_check.rb +3 -2
- data/lib/reek/smells/prima_donna_method.rb +18 -11
- data/lib/reek/smells/repeated_conditional.rb +3 -3
- data/lib/reek/smells/smell_detector.rb +5 -1
- data/lib/reek/smells/smell_warning.rb +99 -0
- data/lib/reek/smells/too_many_instance_variables.rb +1 -1
- data/lib/reek/smells/too_many_methods.rb +1 -1
- data/lib/reek/smells/too_many_statements.rb +1 -1
- data/lib/reek/smells/uncommunicative_method_name.rb +1 -1
- data/lib/reek/smells/uncommunicative_module_name.rb +1 -1
- data/lib/reek/smells/uncommunicative_parameter_name.rb +1 -1
- data/lib/reek/smells/uncommunicative_variable_name.rb +1 -1
- data/lib/reek/smells/unused_parameters.rb +1 -1
- data/lib/reek/smells/utility_function.rb +3 -16
- data/lib/reek/source/source_code.rb +31 -13
- data/lib/reek/source/source_locator.rb +16 -17
- data/lib/reek/source/source_repository.rb +10 -11
- data/lib/reek/spec/should_reek.rb +2 -2
- data/lib/reek/spec/should_reek_of.rb +2 -2
- data/lib/reek/spec/should_reek_only_of.rb +2 -2
- data/lib/reek/version.rb +1 -1
- data/reek.gemspec +3 -4
- data/spec/factories/factories.rb +1 -1
- data/spec/gem/yard_spec.rb +1 -1
- data/spec/quality/reek_source_spec.rb +2 -2
- data/spec/reek/cli/html_report_spec.rb +3 -3
- data/spec/reek/cli/json_report_spec.rb +3 -3
- data/spec/reek/cli/{option_interperter_spec.rb → option_interpreter_spec.rb} +1 -1
- data/spec/reek/cli/options_spec.rb +19 -0
- data/spec/reek/cli/text_report_spec.rb +7 -7
- data/spec/reek/cli/xml_report_spec.rb +34 -0
- data/spec/reek/cli/yaml_report_spec.rb +3 -3
- data/spec/reek/configuration/app_configuration_spec.rb +1 -1
- data/spec/reek/configuration/configuration_file_finder_spec.rb +22 -1
- data/spec/reek/{source → core}/code_comment_spec.rb +14 -14
- data/spec/reek/core/code_context_spec.rb +1 -1
- data/spec/reek/{examiner_spec.rb → core/examiner_spec.rb} +12 -12
- data/spec/reek/core/method_context_spec.rb +27 -22
- data/spec/reek/core/module_context_spec.rb +2 -2
- data/spec/reek/core/object_refs_spec.rb +1 -1
- data/spec/reek/{source → core}/object_source_spec.rb +1 -1
- data/spec/reek/{source → core}/reference_collector_spec.rb +25 -16
- data/spec/reek/core/singleton_method_context_spec.rb +12 -2
- data/spec/reek/core/smell_configuration_spec.rb +1 -1
- data/spec/reek/core/smell_repository_spec.rb +12 -1
- data/spec/reek/core/stop_context_spec.rb +1 -1
- data/spec/reek/core/tree_dresser_spec.rb +16 -0
- data/spec/reek/core/tree_walker_spec.rb +3 -3
- data/spec/reek/core/warning_collector_spec.rb +6 -6
- data/spec/reek/{source → sexp}/sexp_extensions_spec.rb +8 -8
- data/spec/reek/{source → sexp}/sexp_formatter_spec.rb +11 -5
- data/spec/reek/{source → sexp}/sexp_node_spec.rb +3 -3
- data/spec/reek/smells/attribute_spec.rb +89 -85
- data/spec/reek/smells/behaves_like_variable_detector.rb +1 -1
- data/spec/reek/smells/boolean_parameter_spec.rb +1 -1
- data/spec/reek/smells/class_variable_spec.rb +1 -1
- data/spec/reek/smells/control_parameter_spec.rb +1 -1
- data/spec/reek/smells/data_clump_spec.rb +2 -2
- data/spec/reek/smells/duplicate_method_call_spec.rb +1 -1
- data/spec/reek/smells/feature_envy_spec.rb +2 -2
- data/spec/reek/smells/irresponsible_module_spec.rb +1 -1
- data/spec/reek/smells/long_parameter_list_spec.rb +2 -2
- data/spec/reek/smells/long_yield_list_spec.rb +1 -1
- data/spec/reek/smells/module_initialize_spec.rb +1 -1
- data/spec/reek/smells/nested_iterators_spec.rb +2 -2
- data/spec/reek/smells/nil_check_spec.rb +1 -1
- data/spec/reek/smells/prima_donna_method_spec.rb +1 -1
- data/spec/reek/smells/repeated_conditional_spec.rb +1 -1
- data/spec/reek/smells/smell_detector_shared.rb +2 -2
- data/spec/reek/{smell_warning_spec.rb → smells/smell_warning_spec.rb} +7 -7
- data/spec/reek/smells/too_many_instance_variables_spec.rb +1 -1
- data/spec/reek/smells/too_many_methods_spec.rb +1 -1
- data/spec/reek/smells/too_many_statements_spec.rb +4 -4
- data/spec/reek/smells/uncommunicative_method_name_spec.rb +1 -1
- data/spec/reek/smells/uncommunicative_module_name_spec.rb +1 -1
- data/spec/reek/smells/uncommunicative_parameter_name_spec.rb +1 -1
- data/spec/reek/smells/uncommunicative_variable_name_spec.rb +1 -1
- data/spec/reek/smells/unused_parameters_spec.rb +1 -1
- data/spec/reek/smells/utility_function_spec.rb +1 -1
- data/spec/reek/source/source_code_spec.rb +1 -1
- data/spec/reek/spec/should_reek_of_spec.rb +1 -1
- data/spec/reek/spec/should_reek_only_of_spec.rb +1 -1
- data/spec/reek/spec/should_reek_spec.rb +1 -1
- data/spec/samples/checkstyle.xml +2 -0
- data/spec/spec_helper.rb +15 -3
- metadata +68 -38
- data/.ruby-gemset +0 -1
- data/lib/reek/examiner.rb +0 -79
- data/lib/reek/smell_warning.rb +0 -87
- data/lib/reek/source/reference_collector.rb +0 -27
- data/lib/reek/source/sexp_formatter.rb +0 -22
- data/lib/reek/source/sexp_node.rb +0 -79
- data/spec/reek/source/tree_dresser_spec.rb +0 -16
@@ -1,13 +1,13 @@
|
|
1
1
|
require_relative '../../spec_helper'
|
2
|
-
require_relative '../../../lib/reek/examiner'
|
2
|
+
require_relative '../../../lib/reek/core/examiner'
|
3
3
|
require_relative '../../../lib/reek/cli/report/report'
|
4
4
|
require_relative '../../../lib/reek/cli/report/formatter'
|
5
5
|
|
6
|
-
describe Reek::CLI::Report::JSONReport do
|
6
|
+
RSpec.describe Reek::CLI::Report::JSONReport do
|
7
7
|
let(:instance) { Reek::CLI::Report::JSONReport.new }
|
8
8
|
|
9
9
|
context 'empty source' do
|
10
|
-
let(:examiner) { Reek::Examiner.new('') }
|
10
|
+
let(:examiner) { Reek::Core::Examiner.new('') }
|
11
11
|
|
12
12
|
before do
|
13
13
|
instance.add_examiner examiner
|
@@ -2,7 +2,7 @@ require_relative '../../spec_helper'
|
|
2
2
|
|
3
3
|
require_relative '../../../lib/reek/cli/options'
|
4
4
|
|
5
|
-
describe Reek::CLI::OptionInterpreter do
|
5
|
+
RSpec.describe Reek::CLI::OptionInterpreter do
|
6
6
|
let(:options) { OpenStruct.new }
|
7
7
|
let(:instance) { Reek::CLI::OptionInterpreter.new(options) }
|
8
8
|
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require_relative '../../spec_helper'
|
2
|
+
|
3
|
+
require_relative '../../../lib/reek/cli/options'
|
4
|
+
|
5
|
+
RSpec.describe Reek::CLI::Options do
|
6
|
+
describe '#initialize' do
|
7
|
+
it 'should enable colors when stdout is a TTY' do
|
8
|
+
allow($stdout).to receive_messages(tty?: false)
|
9
|
+
options = Reek::CLI::Options.new.parse
|
10
|
+
expect(options.colored).to be false
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should not enable colors when stdout is not a TTY' do
|
14
|
+
allow($stdout).to receive_messages(tty?: true)
|
15
|
+
options = Reek::CLI::Options.new.parse
|
16
|
+
expect(options.colored).to be true
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -1,11 +1,11 @@
|
|
1
1
|
require_relative '../../spec_helper'
|
2
|
-
require_relative '../../../lib/reek/examiner'
|
2
|
+
require_relative '../../../lib/reek/core/examiner'
|
3
3
|
require_relative '../../../lib/reek/cli/report/report'
|
4
4
|
require_relative '../../../lib/reek/cli/report/formatter'
|
5
5
|
require_relative '../../../lib/reek/cli/report/heading_formatter'
|
6
6
|
require 'rainbow'
|
7
7
|
|
8
|
-
describe Reek::CLI::Report::TextReport do
|
8
|
+
RSpec.describe Reek::CLI::Report::TextReport do
|
9
9
|
let(:report_options) do
|
10
10
|
{
|
11
11
|
warning_formatter: Reek::CLI::Report::SimpleWarningFormatter.new,
|
@@ -17,7 +17,7 @@ describe Reek::CLI::Report::TextReport do
|
|
17
17
|
|
18
18
|
context 'with a single empty source' do
|
19
19
|
before do
|
20
|
-
instance.add_examiner Reek::Examiner.new('')
|
20
|
+
instance.add_examiner Reek::Core::Examiner.new('')
|
21
21
|
end
|
22
22
|
|
23
23
|
it 'has an empty quiet_report' do
|
@@ -27,8 +27,8 @@ describe Reek::CLI::Report::TextReport do
|
|
27
27
|
|
28
28
|
context 'with non smelly files' do
|
29
29
|
before do
|
30
|
-
instance.add_examiner(Reek::Examiner.new('def simple() puts "a" end'))
|
31
|
-
instance.add_examiner(Reek::Examiner.new('def simple() puts "a" end'))
|
30
|
+
instance.add_examiner(Reek::Core::Examiner.new('def simple() puts "a" end'))
|
31
|
+
instance.add_examiner(Reek::Core::Examiner.new('def simple() puts "a" end'))
|
32
32
|
end
|
33
33
|
|
34
34
|
context 'with colors disabled' do
|
@@ -54,8 +54,8 @@ describe Reek::CLI::Report::TextReport do
|
|
54
54
|
|
55
55
|
context 'with a couple of smells' do
|
56
56
|
before do
|
57
|
-
instance.add_examiner(Reek::Examiner.new('def simple(a) a[3] end'))
|
58
|
-
instance.add_examiner(Reek::Examiner.new('def simple(a) a[3] end'))
|
57
|
+
instance.add_examiner(Reek::Core::Examiner.new('def simple(a) a[3] end'))
|
58
|
+
instance.add_examiner(Reek::Core::Examiner.new('def simple(a) a[3] end'))
|
59
59
|
end
|
60
60
|
|
61
61
|
context 'with colors disabled' do
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require_relative '../../spec_helper'
|
2
|
+
require_relative '../../../lib/reek/core/examiner'
|
3
|
+
require_relative '../../../lib/reek/cli/report/report'
|
4
|
+
require_relative '../../../lib/reek/cli/report/formatter'
|
5
|
+
|
6
|
+
RSpec.describe Reek::CLI::Report::XMLReport do
|
7
|
+
let(:instance) { Reek::CLI::Report::XMLReport.new }
|
8
|
+
|
9
|
+
context 'empty source' do
|
10
|
+
let(:examiner) { Reek::Core::Examiner.new('') }
|
11
|
+
|
12
|
+
before do
|
13
|
+
instance.add_examiner examiner
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'prints empty checkstyle xml' do
|
17
|
+
expect { instance.show }.to output("<?xml version='1.0'?>\n<checkstyle/>\n").to_stdout
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'source with voliations' do
|
22
|
+
let(:examiner) { Reek::Core::Examiner.new('def simple(a) a[0] end') }
|
23
|
+
|
24
|
+
before do
|
25
|
+
allow(File).to receive(:realpath).and_return('/some/path')
|
26
|
+
instance.add_examiner examiner
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'prints non-empty checkstyle xml' do
|
30
|
+
sample_path = File.expand_path 'checkstyle.xml', 'spec/samples'
|
31
|
+
expect { instance.show }.to output(File.read(sample_path)).to_stdout
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -1,13 +1,13 @@
|
|
1
1
|
require_relative '../../spec_helper'
|
2
|
-
require_relative '../../../lib/reek/examiner'
|
2
|
+
require_relative '../../../lib/reek/core/examiner'
|
3
3
|
require_relative '../../../lib/reek/cli/report/report'
|
4
4
|
require_relative '../../../lib/reek/cli/report/formatter'
|
5
5
|
|
6
|
-
describe Reek::CLI::Report::YAMLReport do
|
6
|
+
RSpec.describe Reek::CLI::Report::YAMLReport do
|
7
7
|
let(:instance) { Reek::CLI::Report::YAMLReport.new }
|
8
8
|
|
9
9
|
context 'empty source' do
|
10
|
-
let(:examiner) { Reek::Examiner.new('') }
|
10
|
+
let(:examiner) { Reek::Core::Examiner.new('') }
|
11
11
|
|
12
12
|
before do
|
13
13
|
instance.add_examiner examiner
|
@@ -2,7 +2,7 @@ require_relative '../../spec_helper'
|
|
2
2
|
require_relative '../../../lib/reek/configuration/app_configuration'
|
3
3
|
require_relative '../../../lib/reek/core/smell_repository'
|
4
4
|
|
5
|
-
describe Reek::Configuration::AppConfiguration do
|
5
|
+
RSpec.describe Reek::Configuration::AppConfiguration do
|
6
6
|
let(:sample_configuration_path) { 'spec/samples/simple_configuration.reek' }
|
7
7
|
let(:sample_configuration_loaded) do
|
8
8
|
{
|
@@ -1,10 +1,11 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
+
require 'fileutils'
|
3
4
|
require 'pathname'
|
4
5
|
require 'tmpdir'
|
5
6
|
require_relative '../../spec_helper'
|
6
7
|
|
7
|
-
describe Reek::Configuration::ConfigurationFileFinder do
|
8
|
+
RSpec.describe Reek::Configuration::ConfigurationFileFinder do
|
8
9
|
describe '.find' do
|
9
10
|
it 'returns the config_file if it’s set' do
|
10
11
|
config_file = double
|
@@ -39,6 +40,7 @@ describe Reek::Configuration::ConfigurationFileFinder do
|
|
39
40
|
end
|
40
41
|
|
41
42
|
it 'returns the file in home if traversing from the current dir fails' do
|
43
|
+
skip_if_a_config_in_tempdir
|
42
44
|
Dir.mktmpdir do |tempdir|
|
43
45
|
current = Pathname.new(tempdir)
|
44
46
|
home = Pathname.new('spec/samples')
|
@@ -48,6 +50,7 @@ describe Reek::Configuration::ConfigurationFileFinder do
|
|
48
50
|
end
|
49
51
|
|
50
52
|
it 'returns nil when there are no files to find' do
|
53
|
+
skip_if_a_config_in_tempdir
|
51
54
|
Dir.mktmpdir do |tempdir|
|
52
55
|
current = Pathname.new(tempdir)
|
53
56
|
home = Pathname.new(tempdir)
|
@@ -55,5 +58,23 @@ describe Reek::Configuration::ConfigurationFileFinder do
|
|
55
58
|
expect(found).to be_nil
|
56
59
|
end
|
57
60
|
end
|
61
|
+
|
62
|
+
it 'works with paths that need escaping' do
|
63
|
+
Dir.mktmpdir("ma\ngic d*r") do |tempdir|
|
64
|
+
config = Pathname.new("#{tempdir}/ma\ngic f*le.reek")
|
65
|
+
subdir = Pathname.new("#{tempdir}/ma\ngic subd*r")
|
66
|
+
FileUtils.touch config
|
67
|
+
FileUtils.mkdir subdir
|
68
|
+
found = described_class.find(current: subdir)
|
69
|
+
expect(found).to eq(config)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
private
|
74
|
+
|
75
|
+
def skip_if_a_config_in_tempdir
|
76
|
+
found = described_class.find(current: Pathname.new(Dir.tmpdir))
|
77
|
+
skip "skipped: #{found} exists and would fail this test" if found
|
78
|
+
end
|
58
79
|
end
|
59
80
|
end
|
@@ -1,10 +1,10 @@
|
|
1
1
|
require_relative '../../spec_helper'
|
2
|
-
require_relative '../../../lib/reek/
|
2
|
+
require_relative '../../../lib/reek/core/code_comment'
|
3
3
|
|
4
|
-
describe Reek::
|
4
|
+
RSpec.describe Reek::Core::CodeComment do
|
5
5
|
context 'with an empty comment' do
|
6
6
|
before :each do
|
7
|
-
@comment =
|
7
|
+
@comment = described_class.new('')
|
8
8
|
end
|
9
9
|
it 'is not descriptive' do
|
10
10
|
expect(@comment).not_to be_descriptive
|
@@ -16,37 +16,37 @@ describe Reek::Source::CodeComment do
|
|
16
16
|
|
17
17
|
context 'comment checks' do
|
18
18
|
it 'rejects an empty comment' do
|
19
|
-
expect(
|
19
|
+
expect(described_class.new('#')).not_to be_descriptive
|
20
20
|
end
|
21
21
|
it 'rejects a 1-word comment' do
|
22
|
-
expect(
|
22
|
+
expect(described_class.new("# fred\n# ")).not_to be_descriptive
|
23
23
|
end
|
24
24
|
it 'accepts a 2-word comment' do
|
25
|
-
expect(
|
25
|
+
expect(described_class.new('# fred here ')).to be_descriptive
|
26
26
|
end
|
27
27
|
it 'accepts a multi-word comment' do
|
28
28
|
comment = "# fred here \n# with \n # biscuits "
|
29
|
-
expect(
|
29
|
+
expect(described_class.new(comment)).to be_descriptive
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
33
|
context 'comment config' do
|
34
34
|
it 'parses hashed options' do
|
35
35
|
comment = '# :reek:Duplication: { enabled: false }'
|
36
|
-
config =
|
36
|
+
config = described_class.new(comment).config
|
37
37
|
expect(config).to include('Duplication')
|
38
38
|
expect(config['Duplication']).to include('enabled')
|
39
39
|
expect(config['Duplication']['enabled']).to be_falsey
|
40
40
|
end
|
41
41
|
it 'parses hashed options with ruby names' do
|
42
42
|
comment = '# :reek:nested_iterators: { enabled: true }'
|
43
|
-
config =
|
43
|
+
config = described_class.new(comment).config
|
44
44
|
expect(config).to include('NestedIterators')
|
45
45
|
expect(config['NestedIterators']).to include('enabled')
|
46
46
|
expect(config['NestedIterators']['enabled']).to be_truthy
|
47
47
|
end
|
48
48
|
it 'parses multiple hashed options' do
|
49
|
-
config =
|
49
|
+
config = described_class.new('
|
50
50
|
# :reek:Duplication: { enabled: false }
|
51
51
|
:reek:nested_iterators: { enabled: true }
|
52
52
|
').config
|
@@ -57,7 +57,7 @@ describe Reek::Source::CodeComment do
|
|
57
57
|
expect(config['NestedIterators']['enabled']).to be_truthy
|
58
58
|
end
|
59
59
|
it 'parses multiple hashed options on the same line' do
|
60
|
-
config =
|
60
|
+
config = described_class.new('
|
61
61
|
#:reek:Duplication: { enabled: false } and :reek:nested_iterators: { enabled: true }
|
62
62
|
').config
|
63
63
|
expect(config).to include('Duplication', 'NestedIterators')
|
@@ -68,7 +68,7 @@ describe Reek::Source::CodeComment do
|
|
68
68
|
end
|
69
69
|
it 'parses multiple unhashed options on the same line' do
|
70
70
|
comment = '# :reek:Duplication and :reek:nested_iterators'
|
71
|
-
config =
|
71
|
+
config = described_class.new(comment).config
|
72
72
|
expect(config).to include('Duplication', 'NestedIterators')
|
73
73
|
expect(config['Duplication']).to include('enabled')
|
74
74
|
expect(config['Duplication']['enabled']).to be_falsey
|
@@ -76,13 +76,13 @@ describe Reek::Source::CodeComment do
|
|
76
76
|
expect(config['NestedIterators']['enabled']).to be_falsey
|
77
77
|
end
|
78
78
|
it 'disables the smell if no options are specifed' do
|
79
|
-
config =
|
79
|
+
config = described_class.new('# :reek:Duplication').config
|
80
80
|
expect(config).to include('Duplication')
|
81
81
|
expect(config['Duplication']).to include('enabled')
|
82
82
|
expect(config['Duplication']['enabled']).to be_falsey
|
83
83
|
end
|
84
84
|
it 'ignores smells after a space' do
|
85
|
-
config =
|
85
|
+
config = described_class.new('# :reek: Duplication').config
|
86
86
|
expect(config).not_to include('Duplication')
|
87
87
|
end
|
88
88
|
end
|
@@ -3,7 +3,7 @@ require_relative '../../../lib/reek/core/method_context'
|
|
3
3
|
require_relative '../../../lib/reek/core/module_context'
|
4
4
|
require_relative '../../../lib/reek/core/stop_context'
|
5
5
|
|
6
|
-
describe Reek::Core::CodeContext do
|
6
|
+
RSpec.describe Reek::Core::CodeContext do
|
7
7
|
context 'name recognition' do
|
8
8
|
before :each do
|
9
9
|
@exp_name = 'random_name' # SMELL: could use a String.random here
|
@@ -1,7 +1,7 @@
|
|
1
|
-
require_relative '
|
2
|
-
require_relative '
|
1
|
+
require_relative '../../spec_helper'
|
2
|
+
require_relative '../../../lib/reek/core/examiner'
|
3
3
|
|
4
|
-
shared_examples_for 'no smells found' do
|
4
|
+
RSpec.shared_examples_for 'no smells found' do
|
5
5
|
it 'is not smelly' do
|
6
6
|
expect(@examiner).not_to be_smelly
|
7
7
|
end
|
@@ -10,7 +10,7 @@ shared_examples_for 'no smells found' do
|
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
shared_examples_for 'one smell found' do
|
13
|
+
RSpec.shared_examples_for 'one smell found' do
|
14
14
|
it 'is smelly' do
|
15
15
|
expect(@examiner).to be_smelly
|
16
16
|
end
|
@@ -22,14 +22,14 @@ shared_examples_for 'one smell found' do
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
describe Reek::Examiner do
|
25
|
+
RSpec.describe Reek::Core::Examiner do
|
26
26
|
before :each do
|
27
27
|
@expected_first_smell = 'NestedIterators'
|
28
28
|
end
|
29
29
|
|
30
30
|
context 'with a fragrant String' do
|
31
31
|
before :each do
|
32
|
-
@examiner =
|
32
|
+
@examiner = described_class.new('def good() true; end')
|
33
33
|
end
|
34
34
|
|
35
35
|
it_should_behave_like 'no smells found'
|
@@ -37,7 +37,7 @@ describe Reek::Examiner do
|
|
37
37
|
|
38
38
|
context 'with a smelly String' do
|
39
39
|
before :each do
|
40
|
-
@examiner =
|
40
|
+
@examiner = described_class.new('def fine() y = 4; end')
|
41
41
|
@expected_first_smell = 'UncommunicativeName'
|
42
42
|
end
|
43
43
|
|
@@ -53,7 +53,7 @@ describe Reek::Examiner do
|
|
53
53
|
|
54
54
|
before :each do
|
55
55
|
smelly_dir = Dir['spec/samples/all_but_one_masked/*.rb']
|
56
|
-
@examiner =
|
56
|
+
@examiner = described_class.new(smelly_dir)
|
57
57
|
end
|
58
58
|
|
59
59
|
it_should_behave_like 'one smell found'
|
@@ -62,7 +62,7 @@ describe Reek::Examiner do
|
|
62
62
|
context 'with a fragrant Dir' do
|
63
63
|
before :each do
|
64
64
|
clean_dir = Dir['spec/samples/three_clean_files/*.rb']
|
65
|
-
@examiner =
|
65
|
+
@examiner = described_class.new(clean_dir)
|
66
66
|
end
|
67
67
|
|
68
68
|
it_should_behave_like 'no smells found'
|
@@ -77,7 +77,7 @@ describe Reek::Examiner do
|
|
77
77
|
|
78
78
|
before :each do
|
79
79
|
smelly_dir = Dir['spec/samples/masked_by_dotfile/*.rb']
|
80
|
-
@examiner =
|
80
|
+
@examiner = described_class.new(smelly_dir)
|
81
81
|
end
|
82
82
|
|
83
83
|
it_should_behave_like 'one smell found'
|
@@ -92,7 +92,7 @@ describe Reek::Examiner do
|
|
92
92
|
|
93
93
|
before :each do
|
94
94
|
smelly_file = File.new(Dir['spec/samples/all_but_one_masked/d*.rb'][0])
|
95
|
-
@examiner =
|
95
|
+
@examiner = described_class.new(smelly_file)
|
96
96
|
end
|
97
97
|
|
98
98
|
it_should_behave_like 'one smell found'
|
@@ -101,7 +101,7 @@ describe Reek::Examiner do
|
|
101
101
|
context 'with a fragrant File' do
|
102
102
|
before :each do
|
103
103
|
clean_file = File.new(Dir['spec/samples/three_clean_files/*.rb'][0])
|
104
|
-
@examiner =
|
104
|
+
@examiner = described_class.new(clean_file)
|
105
105
|
end
|
106
106
|
|
107
107
|
it_should_behave_like 'no smells found'
|
@@ -2,7 +2,7 @@ require_relative '../../spec_helper'
|
|
2
2
|
require_relative '../../../lib/reek/core/method_context'
|
3
3
|
require_relative '../../../lib/reek/core/stop_context'
|
4
4
|
|
5
|
-
describe Reek::Core::MethodContext, 'matching' do
|
5
|
+
RSpec.describe Reek::Core::MethodContext, 'matching' do
|
6
6
|
before :each do
|
7
7
|
exp = double('exp').as_null_object
|
8
8
|
expect(exp).to receive(:full_name).at_least(:once).and_return('mod')
|
@@ -20,33 +20,38 @@ describe Reek::Core::MethodContext, 'matching' do
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
describe Reek::Core::MethodContext do
|
24
|
-
|
25
|
-
sexp = s(:def, :
|
26
|
-
|
27
|
-
expect(mctx.envious_receivers).to eq([])
|
28
|
-
mctx.record_call_to(s(:send, s(:ivar, :@cow), :feed_to))
|
29
|
-
expect(mctx.envious_receivers).to eq([])
|
23
|
+
RSpec.describe Reek::Core::MethodContext do
|
24
|
+
let(:mc) do
|
25
|
+
sexp = s(:def, :foo, s(:args, s(:arg, :bar)), nil)
|
26
|
+
Reek::Core::MethodContext.new(Reek::Core::StopContext.new, sexp)
|
30
27
|
end
|
31
28
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
29
|
+
describe '#envious_receivers' do
|
30
|
+
it 'should ignore ivars as refs to self' do
|
31
|
+
mc.record_call_to s(:send, s(:ivar, :@cow), :feed_to)
|
32
|
+
expect(mc.envious_receivers).to be_empty
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should ignore explicit calls to self' do
|
36
|
+
mc.refs.record_reference_to [:lvar, :other]
|
37
|
+
mc.record_call_to s(:send, s(:self), :thing)
|
38
|
+
expect(mc.envious_receivers).to be_empty
|
39
|
+
end
|
39
40
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
41
|
+
it 'should ignore implicit calls to self' do
|
42
|
+
mc.record_call_to s(:send, s(:lvar, :text), :each, s(:arglist))
|
43
|
+
mc.record_call_to s(:send, nil, :shelve, s(:arglist))
|
44
|
+
expect(mc.envious_receivers).to be_empty
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'should record envious calls' do
|
48
|
+
mc.record_call_to s(:send, s(:lvar, :bar), :baz)
|
49
|
+
expect(mc.envious_receivers).to eq(bar: 1)
|
50
|
+
end
|
46
51
|
end
|
47
52
|
end
|
48
53
|
|
49
|
-
describe Reek::Core::MethodParameters, 'default assignments' do
|
54
|
+
RSpec.describe Reek::Core::MethodParameters, 'default assignments' do
|
50
55
|
def assignments_from(src)
|
51
56
|
exp = Reek::Source::SourceCode.from(src).syntax_tree
|
52
57
|
ctx = Reek::Core::MethodContext.new(Reek::Core::StopContext.new, exp)
|