reek 1.3.8 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +11 -0
- data/README.md +22 -14
- data/Rakefile +2 -15
- data/assets/html_output.html.erb +103 -0
- data/features/command_line_interface/options.feature +3 -0
- data/features/command_line_interface/smell_selection.feature +19 -0
- data/features/rake_task/rake_task.feature +1 -1
- data/features/reports/reports.feature +16 -0
- data/features/reports/yaml.feature +26 -23
- data/features/samples.feature +2 -1
- data/features/step_definitions/reek_steps.rb +15 -15
- data/features/support/env.rb +7 -9
- data/lib/reek/cli/application.rb +2 -4
- data/lib/reek/cli/command.rb +12 -0
- data/lib/reek/cli/help_command.rb +3 -6
- data/lib/reek/cli/options.rb +147 -0
- data/lib/reek/cli/reek_command.rb +18 -14
- data/lib/reek/cli/report/formatter.rb +56 -0
- data/lib/reek/cli/report/report.rb +106 -0
- data/lib/reek/cli/report/strategy.rb +63 -0
- data/lib/reek/cli/version_command.rb +3 -6
- data/lib/reek/config_file_exception.rb +0 -1
- data/lib/reek/core/code_context.rb +1 -3
- data/lib/reek/core/code_parser.rb +13 -12
- data/lib/reek/core/method_context.rb +13 -2
- data/lib/reek/core/module_context.rb +0 -4
- data/lib/reek/core/object_refs.rb +2 -3
- data/lib/reek/core/singleton_method_context.rb +0 -2
- data/lib/reek/core/smell_configuration.rb +3 -5
- data/lib/reek/core/smell_repository.rb +7 -8
- data/lib/reek/core/sniffer.rb +4 -10
- data/lib/reek/core/stop_context.rb +2 -4
- data/lib/reek/core/warning_collector.rb +0 -1
- data/lib/reek/examiner.rb +19 -17
- data/lib/reek/rake/task.rb +7 -10
- data/lib/reek/smell_warning.rb +4 -8
- data/lib/reek/smells.rb +0 -1
- data/lib/reek/smells/attribute.rb +8 -11
- data/lib/reek/smells/boolean_parameter.rb +5 -7
- data/lib/reek/smells/class_variable.rb +6 -7
- data/lib/reek/smells/control_parameter.rb +78 -45
- data/lib/reek/smells/data_clump.rb +13 -16
- data/lib/reek/smells/duplicate_method_call.rb +13 -11
- data/lib/reek/smells/feature_envy.rb +6 -7
- data/lib/reek/smells/irresponsible_module.rb +4 -6
- data/lib/reek/smells/long_parameter_list.rb +5 -7
- data/lib/reek/smells/long_yield_list.rb +2 -4
- data/lib/reek/smells/nested_iterators.rb +12 -22
- data/lib/reek/smells/nil_check.rb +35 -46
- data/lib/reek/smells/prima_donna_method.rb +24 -16
- data/lib/reek/smells/repeated_conditional.rb +8 -10
- data/lib/reek/smells/smell_detector.rb +9 -7
- data/lib/reek/smells/too_many_instance_variables.rb +7 -9
- data/lib/reek/smells/too_many_methods.rb +6 -8
- data/lib/reek/smells/too_many_statements.rb +4 -6
- data/lib/reek/smells/uncommunicative_method_name.rb +5 -7
- data/lib/reek/smells/uncommunicative_module_name.rb +5 -7
- data/lib/reek/smells/uncommunicative_parameter_name.rb +7 -9
- data/lib/reek/smells/uncommunicative_variable_name.rb +15 -18
- data/lib/reek/smells/unused_parameters.rb +5 -45
- data/lib/reek/smells/utility_function.rb +9 -10
- data/lib/reek/source.rb +0 -1
- data/lib/reek/source/code_comment.rb +7 -8
- data/lib/reek/source/config_file.rb +2 -4
- data/lib/reek/source/core_extras.rb +1 -1
- data/lib/reek/source/reference_collector.rb +1 -2
- data/lib/reek/source/sexp_extensions.rb +93 -10
- data/lib/reek/source/sexp_formatter.rb +2 -3
- data/lib/reek/source/sexp_node.rb +19 -15
- data/lib/reek/source/source_code.rb +4 -14
- data/lib/reek/source/source_file.rb +3 -5
- data/lib/reek/source/source_locator.rb +5 -6
- data/lib/reek/source/source_repository.rb +3 -3
- data/lib/reek/source/tree_dresser.rb +2 -2
- data/lib/reek/spec.rb +1 -2
- data/lib/reek/spec/should_reek.rb +8 -5
- data/lib/reek/spec/should_reek_of.rb +6 -4
- data/lib/reek/spec/should_reek_only_of.rb +10 -6
- data/lib/reek/version.rb +1 -1
- data/reek.gemspec +34 -30
- data/spec/gem/updates_spec.rb +3 -4
- data/spec/gem/yard_spec.rb +1 -2
- data/spec/matchers/smell_of_matcher.rb +12 -14
- data/spec/quality/reek_source_spec.rb +42 -0
- data/spec/reek/cli/help_command_spec.rb +7 -5
- data/spec/reek/cli/report_spec.rb +89 -22
- data/spec/reek/cli/version_command_spec.rb +8 -6
- data/spec/reek/core/code_context_spec.rb +25 -26
- data/spec/reek/core/code_parser_spec.rb +6 -6
- data/spec/reek/core/method_context_spec.rb +18 -18
- data/spec/reek/core/module_context_spec.rb +5 -5
- data/spec/reek/core/object_refs_spec.rb +21 -22
- data/spec/reek/core/smell_configuration_spec.rb +22 -21
- data/spec/reek/core/stop_context_spec.rb +2 -2
- data/spec/reek/core/warning_collector_spec.rb +3 -3
- data/spec/reek/examiner_spec.rb +9 -9
- data/spec/reek/smell_warning_spec.rb +29 -29
- data/spec/reek/smells/attribute_spec.rb +6 -6
- data/spec/reek/smells/behaves_like_variable_detector.rb +6 -6
- data/spec/reek/smells/boolean_parameter_spec.rb +17 -17
- data/spec/reek/smells/class_variable_spec.rb +9 -9
- data/spec/reek/smells/control_parameter_spec.rb +161 -137
- data/spec/reek/smells/data_clump_spec.rb +22 -19
- data/spec/reek/smells/duplicate_method_call_spec.rb +71 -27
- data/spec/reek/smells/feature_envy_spec.rb +32 -32
- data/spec/reek/smells/irresponsible_module_spec.rb +21 -21
- data/spec/reek/smells/long_parameter_list_spec.rb +14 -14
- data/spec/reek/smells/long_yield_list_spec.rb +6 -6
- data/spec/reek/smells/nested_iterators_spec.rb +21 -21
- data/spec/reek/smells/nil_check_spec.rb +23 -15
- data/spec/reek/smells/prima_donna_method_spec.rb +5 -5
- data/spec/reek/smells/repeated_conditional_spec.rb +14 -14
- data/spec/reek/smells/smell_detector_shared.rb +9 -9
- data/spec/reek/smells/too_many_instance_variables_spec.rb +12 -12
- data/spec/reek/smells/too_many_methods_spec.rb +10 -10
- data/spec/reek/smells/too_many_statements_spec.rb +41 -41
- data/spec/reek/smells/uncommunicative_method_name_spec.rb +4 -4
- data/spec/reek/smells/uncommunicative_module_name_spec.rb +12 -12
- data/spec/reek/smells/uncommunicative_parameter_name_spec.rb +21 -21
- data/spec/reek/smells/uncommunicative_variable_name_spec.rb +49 -49
- data/spec/reek/smells/unused_parameters_spec.rb +26 -16
- data/spec/reek/smells/utility_function_spec.rb +20 -20
- data/spec/reek/source/code_comment_spec.rb +37 -37
- data/spec/reek/source/object_source_spec.rb +5 -5
- data/spec/reek/source/reference_collector_spec.rb +9 -9
- data/spec/reek/source/sexp_extensions_spec.rb +73 -52
- data/spec/reek/source/sexp_formatter_spec.rb +3 -4
- data/spec/reek/source/sexp_node_spec.rb +3 -3
- data/spec/reek/source/source_code_spec.rb +16 -15
- data/spec/reek/source/tree_dresser_spec.rb +2 -2
- data/spec/reek/spec/should_reek_of_spec.rb +11 -11
- data/spec/reek/spec/should_reek_only_of_spec.rb +11 -11
- data/spec/reek/spec/should_reek_spec.rb +11 -11
- data/spec/samples/one_smelly_file/dirty.rb +3 -0
- data/spec/spec_helper.rb +0 -6
- data/tasks/develop.rake +8 -16
- data/tasks/reek.rake +5 -13
- data/tasks/test.rake +5 -22
- metadata +56 -34
- data/lib/reek/cli/command_line.rb +0 -126
- data/lib/reek/cli/report.rb +0 -138
@@ -9,74 +9,74 @@ describe CodeComment do
|
|
9
9
|
@comment = CodeComment.new('')
|
10
10
|
end
|
11
11
|
it 'is not descriptive' do
|
12
|
-
@comment.
|
12
|
+
expect(@comment).not_to be_descriptive
|
13
13
|
end
|
14
14
|
it 'has an empty config' do
|
15
|
-
@comment.config.
|
15
|
+
expect(@comment.config).to be_empty
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
19
|
context 'comment checks' do
|
20
20
|
it 'rejects an empty comment' do
|
21
|
-
CodeComment.new('#').
|
21
|
+
expect(CodeComment.new('#')).not_to be_descriptive
|
22
22
|
end
|
23
23
|
it 'rejects a 1-word comment' do
|
24
|
-
CodeComment.new("# fred\n# ").
|
24
|
+
expect(CodeComment.new("# fred\n# ")).not_to be_descriptive
|
25
25
|
end
|
26
26
|
it 'accepts a 2-word comment' do
|
27
|
-
CodeComment.new('# fred here ').
|
27
|
+
expect(CodeComment.new('# fred here ')).to be_descriptive
|
28
28
|
end
|
29
29
|
it 'accepts a multi-word comment' do
|
30
|
-
CodeComment.new("# fred here \n# with \n # biscuits ").
|
30
|
+
expect(CodeComment.new("# fred here \n# with \n # biscuits ")).to be_descriptive
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
34
|
context 'comment config' do
|
35
35
|
it 'parses hashed options' do
|
36
|
-
config = CodeComment.new(
|
37
|
-
config.
|
38
|
-
config['Duplication'].
|
39
|
-
config['Duplication']['enabled'].
|
36
|
+
config = CodeComment.new('# :reek:Duplication: { enabled: false }').config
|
37
|
+
expect(config).to include('Duplication')
|
38
|
+
expect(config['Duplication']).to include('enabled')
|
39
|
+
expect(config['Duplication']['enabled']).to be_falsey
|
40
40
|
end
|
41
41
|
it 'parses hashed options with ruby names' do
|
42
|
-
config = CodeComment.new(
|
43
|
-
config.
|
44
|
-
config['NestedIterators'].
|
45
|
-
config['NestedIterators']['enabled'].
|
42
|
+
config = CodeComment.new('# :reek:nested_iterators: { enabled: true }').config
|
43
|
+
expect(config).to include('NestedIterators')
|
44
|
+
expect(config['NestedIterators']).to include('enabled')
|
45
|
+
expect(config['NestedIterators']['enabled']).to be_truthy
|
46
46
|
end
|
47
47
|
it 'parses multiple hashed options' do
|
48
48
|
config = CodeComment.new("# :reek:Duplication: { enabled: false }\n:reek:nested_iterators: { enabled: true }").config
|
49
|
-
config.
|
50
|
-
config['Duplication'].
|
51
|
-
config['Duplication']['enabled'].
|
52
|
-
config['NestedIterators'].
|
53
|
-
config['NestedIterators']['enabled'].
|
49
|
+
expect(config).to include('Duplication', 'NestedIterators')
|
50
|
+
expect(config['Duplication']).to include('enabled')
|
51
|
+
expect(config['Duplication']['enabled']).to be_falsey
|
52
|
+
expect(config['NestedIterators']).to include('enabled')
|
53
|
+
expect(config['NestedIterators']['enabled']).to be_truthy
|
54
54
|
end
|
55
55
|
it 'parses multiple hashed options on the same line' do
|
56
|
-
config = CodeComment.new(
|
57
|
-
config.
|
58
|
-
config['Duplication'].
|
59
|
-
config['Duplication']['enabled'].
|
60
|
-
config['NestedIterators'].
|
61
|
-
config['NestedIterators']['enabled'].
|
56
|
+
config = CodeComment.new('# :reek:Duplication: { enabled: false } and :reek:nested_iterators: { enabled: true }').config
|
57
|
+
expect(config).to include('Duplication', 'NestedIterators')
|
58
|
+
expect(config['Duplication']).to include('enabled')
|
59
|
+
expect(config['Duplication']['enabled']).to be_falsey
|
60
|
+
expect(config['NestedIterators']).to include('enabled')
|
61
|
+
expect(config['NestedIterators']['enabled']).to be_truthy
|
62
62
|
end
|
63
63
|
it 'parses multiple unhashed options on the same line' do
|
64
|
-
config = CodeComment.new(
|
65
|
-
config.
|
66
|
-
config['Duplication'].
|
67
|
-
config['Duplication']['enabled'].
|
68
|
-
config['NestedIterators'].
|
69
|
-
config['NestedIterators']['enabled'].
|
64
|
+
config = CodeComment.new('# :reek:Duplication and :reek:nested_iterators').config
|
65
|
+
expect(config).to include('Duplication', 'NestedIterators')
|
66
|
+
expect(config['Duplication']).to include('enabled')
|
67
|
+
expect(config['Duplication']['enabled']).to be_falsey
|
68
|
+
expect(config['NestedIterators']).to include('enabled')
|
69
|
+
expect(config['NestedIterators']['enabled']).to be_falsey
|
70
70
|
end
|
71
71
|
it 'disables the smell if no options are specifed' do
|
72
|
-
config = CodeComment.new(
|
73
|
-
config.
|
74
|
-
config['Duplication'].
|
75
|
-
config['Duplication']['enabled'].
|
72
|
+
config = CodeComment.new('# :reek:Duplication').config
|
73
|
+
expect(config).to include('Duplication')
|
74
|
+
expect(config['Duplication']).to include('enabled')
|
75
|
+
expect(config['Duplication']['enabled']).to be_falsey
|
76
76
|
end
|
77
77
|
it 'ignores smells after a space' do
|
78
|
-
config = CodeComment.new(
|
79
|
-
config.
|
78
|
+
config = CodeComment.new('# :reek: Duplication').config
|
79
|
+
expect(config).not_to include('Duplication')
|
80
80
|
end
|
81
81
|
end
|
82
82
|
end
|
@@ -5,16 +5,16 @@ include Reek
|
|
5
5
|
describe Dir do
|
6
6
|
it 'reports correct smells via the Dir matcher' do
|
7
7
|
files = Dir['spec/samples/two_smelly_files/*.rb']
|
8
|
-
files.
|
9
|
-
files.
|
10
|
-
files.
|
8
|
+
expect(files).to reek
|
9
|
+
expect(files).to reek_of(:UncommunicativeVariableName)
|
10
|
+
expect(files).not_to reek_of(:LargeClass)
|
11
11
|
end
|
12
12
|
|
13
13
|
it 'copes with daft file specs' do
|
14
|
-
Dir[
|
14
|
+
expect(Dir['spec/samples/two_smelly_files/*/.rb']).not_to reek
|
15
15
|
end
|
16
16
|
|
17
17
|
it 'copes with empty array' do
|
18
|
-
[].
|
18
|
+
expect([]).not_to reek
|
19
19
|
end
|
20
20
|
end
|
@@ -10,28 +10,28 @@ describe ReferenceCollector do
|
|
10
10
|
ReferenceCollector.new(src.to_reek_source.syntax_tree).num_refs_to_self
|
11
11
|
end
|
12
12
|
it 'with no refs to self' do
|
13
|
-
refs_to_self('def no_envy(arga) arga.barg end').
|
13
|
+
expect(refs_to_self('def no_envy(arga) arga.barg end')).to eq(0)
|
14
14
|
end
|
15
15
|
it 'counts a call to super' do
|
16
|
-
refs_to_self('def simple() super; end').
|
16
|
+
expect(refs_to_self('def simple() super; end')).to eq(1)
|
17
17
|
end
|
18
18
|
it 'counts a local call' do
|
19
|
-
refs_to_self('def simple() to_s; end').
|
19
|
+
expect(refs_to_self('def simple() to_s; end')).to eq(1)
|
20
20
|
end
|
21
21
|
it 'counts a use of self' do
|
22
|
-
refs_to_self('def simple() lv = self; end').
|
22
|
+
expect(refs_to_self('def simple() lv = self; end')).to eq(1)
|
23
23
|
end
|
24
24
|
it 'counts a call with self as receiver' do
|
25
|
-
refs_to_self('def simple() self.to_s; end').
|
25
|
+
expect(refs_to_self('def simple() self.to_s; end')).to eq(1)
|
26
26
|
end
|
27
27
|
it 'counts uses of an ivar' do
|
28
|
-
refs_to_self('def no_envy() @item.to_a; @item = 4; @item end').
|
28
|
+
expect(refs_to_self('def no_envy() @item.to_a; @item = 4; @item end')).to eq(3)
|
29
29
|
end
|
30
30
|
it 'counts an ivar passed to a method' do
|
31
|
-
refs_to_self('def no_envy(arga) arga.barg(@item); arga end').
|
31
|
+
expect(refs_to_self('def no_envy(arga) arga.barg(@item); arga end')).to eq(1)
|
32
32
|
end
|
33
33
|
it 'ignores global variables' do
|
34
|
-
refs_to_self('def no_envy(arga) $s2.to_a; $s2[arga] end').
|
34
|
+
expect(refs_to_self('def no_envy(arga) $s2.to_a; $s2[arga] end')).to eq(0)
|
35
35
|
end
|
36
36
|
it 'ignores global variables' do
|
37
37
|
src = <<EOS
|
@@ -47,7 +47,7 @@ describe ReferenceCollector do
|
|
47
47
|
@atype[t] = [pat, block]
|
48
48
|
end
|
49
49
|
EOS
|
50
|
-
refs_to_self(src).
|
50
|
+
expect(refs_to_self(src)).to eq(2)
|
51
51
|
end
|
52
52
|
end
|
53
53
|
end
|
@@ -10,16 +10,16 @@ describe SexpExtensions::DefnNode do
|
|
10
10
|
@node.extend(SexpExtensions::DefnNode)
|
11
11
|
end
|
12
12
|
it 'has no arg names' do
|
13
|
-
@node.arg_names.
|
13
|
+
expect(@node.arg_names).to eq(s())
|
14
14
|
end
|
15
15
|
it 'has no parameter names' do
|
16
|
-
@node.parameter_names.
|
16
|
+
expect(@node.parameter_names).to eq(s())
|
17
17
|
end
|
18
18
|
it 'includes outer scope in its full name' do
|
19
|
-
@node.full_name('Fred').
|
19
|
+
expect(@node.full_name('Fred')).to eq('Fred#hello')
|
20
20
|
end
|
21
21
|
it 'includes no marker in its full name with empty outer scope' do
|
22
|
-
@node.full_name('').
|
22
|
+
expect(@node.full_name('')).to eq('hello')
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
@@ -29,16 +29,16 @@ describe SexpExtensions::DefnNode do
|
|
29
29
|
@node.extend(SexpExtensions::DefnNode)
|
30
30
|
end
|
31
31
|
it 'has 1 arg name' do
|
32
|
-
@node.arg_names.
|
32
|
+
expect(@node.arg_names).to eq(s(:param))
|
33
33
|
end
|
34
34
|
it 'has 1 parameter name' do
|
35
|
-
@node.parameter_names.
|
35
|
+
expect(@node.parameter_names).to eq(s(:param))
|
36
36
|
end
|
37
37
|
it 'includes outer scope in its full name' do
|
38
|
-
@node.full_name('Fred').
|
38
|
+
expect(@node.full_name('Fred')).to eq('Fred#hello')
|
39
39
|
end
|
40
40
|
it 'includes no marker in its full name with empty outer scope' do
|
41
|
-
@node.full_name('').
|
41
|
+
expect(@node.full_name('')).to eq('hello')
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
@@ -48,16 +48,16 @@ describe SexpExtensions::DefnNode do
|
|
48
48
|
@node.extend(SexpExtensions::DefnNode)
|
49
49
|
end
|
50
50
|
it 'has 1 arg name' do
|
51
|
-
@node.arg_names.
|
51
|
+
expect(@node.arg_names).to eq(s(:param))
|
52
52
|
end
|
53
53
|
it 'has 2 parameter names' do
|
54
|
-
@node.parameter_names.
|
54
|
+
expect(@node.parameter_names).to eq(s(:param, :"&blk"))
|
55
55
|
end
|
56
56
|
it 'includes outer scope in its full name' do
|
57
|
-
@node.full_name('Fred').
|
57
|
+
expect(@node.full_name('Fred')).to eq('Fred#hello')
|
58
58
|
end
|
59
59
|
it 'includes no marker in its full name with empty outer scope' do
|
60
|
-
@node.full_name('').
|
60
|
+
expect(@node.full_name('')).to eq('hello')
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
@@ -67,16 +67,16 @@ describe SexpExtensions::DefnNode do
|
|
67
67
|
@node.extend(SexpExtensions::DefnNode)
|
68
68
|
end
|
69
69
|
it 'has 1 arg name' do
|
70
|
-
@node.arg_names.
|
70
|
+
expect(@node.arg_names).to eq(s(:param))
|
71
71
|
end
|
72
72
|
it 'has 1 parameter name' do
|
73
|
-
@node.parameter_names.
|
73
|
+
expect(@node.parameter_names).to eq(s(:param))
|
74
74
|
end
|
75
75
|
it 'includes outer scope in its full name' do
|
76
|
-
@node.full_name('Fred').
|
76
|
+
expect(@node.full_name('Fred')).to eq('Fred#hello')
|
77
77
|
end
|
78
78
|
it 'includes no marker in its full name with empty outer scope' do
|
79
|
-
@node.full_name('').
|
79
|
+
expect(@node.full_name('')).to eq('hello')
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
@@ -87,12 +87,12 @@ describe SexpExtensions::DefnNode do
|
|
87
87
|
end
|
88
88
|
|
89
89
|
it 'has 2 body statements' do
|
90
|
-
@node.body.
|
90
|
+
expect(@node.body).to eq(s(s(:first), s(:second)))
|
91
91
|
end
|
92
92
|
|
93
93
|
it 'has a body extended with SexpNode' do
|
94
94
|
b = @node.body
|
95
|
-
(class << b; self; end).included_modules.first.
|
95
|
+
expect((class << b; self; end).included_modules.first).to eq(SexpNode)
|
96
96
|
end
|
97
97
|
end
|
98
98
|
end
|
@@ -104,16 +104,16 @@ describe SexpExtensions::DefsNode do
|
|
104
104
|
@node.extend(SexpExtensions::DefsNode)
|
105
105
|
end
|
106
106
|
it 'has no arg names' do
|
107
|
-
@node.arg_names.
|
107
|
+
expect(@node.arg_names).to eq(s())
|
108
108
|
end
|
109
109
|
it 'has no parameter names' do
|
110
|
-
@node.parameter_names.
|
110
|
+
expect(@node.parameter_names).to eq(s())
|
111
111
|
end
|
112
112
|
it 'includes outer scope in its full name' do
|
113
|
-
@node.full_name('Fred').
|
113
|
+
expect(@node.full_name('Fred')).to eq('Fred#obj.hello')
|
114
114
|
end
|
115
115
|
it 'includes no marker in its full name with empty outer scope' do
|
116
|
-
@node.full_name('').
|
116
|
+
expect(@node.full_name('')).to eq('obj.hello')
|
117
117
|
end
|
118
118
|
end
|
119
119
|
|
@@ -123,16 +123,16 @@ describe SexpExtensions::DefsNode do
|
|
123
123
|
@node.extend(SexpExtensions::DefsNode)
|
124
124
|
end
|
125
125
|
it 'has 1 arg name' do
|
126
|
-
@node.arg_names.
|
126
|
+
expect(@node.arg_names).to eq(s(:param))
|
127
127
|
end
|
128
128
|
it 'has 1 parameter name' do
|
129
|
-
@node.parameter_names.
|
129
|
+
expect(@node.parameter_names).to eq(s(:param))
|
130
130
|
end
|
131
131
|
it 'includes outer scope in its full name' do
|
132
|
-
@node.full_name('Fred').
|
132
|
+
expect(@node.full_name('Fred')).to eq('Fred#obj.hello')
|
133
133
|
end
|
134
134
|
it 'includes no marker in its full name with empty outer scope' do
|
135
|
-
@node.full_name('').
|
135
|
+
expect(@node.full_name('')).to eq('obj.hello')
|
136
136
|
end
|
137
137
|
end
|
138
138
|
|
@@ -142,16 +142,16 @@ describe SexpExtensions::DefsNode do
|
|
142
142
|
@node.extend(SexpExtensions::DefsNode)
|
143
143
|
end
|
144
144
|
it 'has 1 arg name' do
|
145
|
-
@node.arg_names.
|
145
|
+
expect(@node.arg_names).to eq(s(:param))
|
146
146
|
end
|
147
147
|
it 'has 2 parameter names' do
|
148
|
-
@node.parameter_names.
|
148
|
+
expect(@node.parameter_names).to eq(s(:param, :"&blk"))
|
149
149
|
end
|
150
150
|
it 'includes outer scope in its full name' do
|
151
|
-
@node.full_name('Fred').
|
151
|
+
expect(@node.full_name('Fred')).to eq('Fred#obj.hello')
|
152
152
|
end
|
153
153
|
it 'includes no marker in its full name with empty outer scope' do
|
154
|
-
@node.full_name('').
|
154
|
+
expect(@node.full_name('')).to eq('obj.hello')
|
155
155
|
end
|
156
156
|
end
|
157
157
|
|
@@ -161,16 +161,16 @@ describe SexpExtensions::DefsNode do
|
|
161
161
|
@node.extend(SexpExtensions::DefsNode)
|
162
162
|
end
|
163
163
|
it 'has 1 arg name' do
|
164
|
-
@node.arg_names.
|
164
|
+
expect(@node.arg_names).to eq(s(:param))
|
165
165
|
end
|
166
166
|
it 'has 1 parameter name' do
|
167
|
-
@node.parameter_names.
|
167
|
+
expect(@node.parameter_names).to eq(s(:param))
|
168
168
|
end
|
169
169
|
it 'includes outer scope in its full name' do
|
170
|
-
@node.full_name('Fred').
|
170
|
+
expect(@node.full_name('Fred')).to eq('Fred#obj.hello')
|
171
171
|
end
|
172
172
|
it 'includes no marker in its full name with empty outer scope' do
|
173
|
-
@node.full_name('').
|
173
|
+
expect(@node.full_name('')).to eq('obj.hello')
|
174
174
|
end
|
175
175
|
end
|
176
176
|
|
@@ -181,12 +181,12 @@ describe SexpExtensions::DefsNode do
|
|
181
181
|
end
|
182
182
|
|
183
183
|
it 'has 2 body statements' do
|
184
|
-
@node.body.
|
184
|
+
expect(@node.body).to eq(s(s(:first), s(:second)))
|
185
185
|
end
|
186
186
|
|
187
187
|
it 'has a body extended with SexpNode' do
|
188
188
|
b = @node.body
|
189
|
-
(class << b; self; end).included_modules.first.
|
189
|
+
expect((class << b; self; end).included_modules.first).to eq(SexpNode)
|
190
190
|
end
|
191
191
|
end
|
192
192
|
end
|
@@ -198,7 +198,7 @@ describe SexpExtensions::CallNode do
|
|
198
198
|
@node.extend(SexpExtensions::CallNode)
|
199
199
|
end
|
200
200
|
it 'has no parameter names' do
|
201
|
-
@node.parameter_names.
|
201
|
+
expect(@node.parameter_names).to eq(nil)
|
202
202
|
end
|
203
203
|
end
|
204
204
|
|
@@ -208,7 +208,7 @@ describe SexpExtensions::CallNode do
|
|
208
208
|
@node.extend(SexpExtensions::CallNode)
|
209
209
|
end
|
210
210
|
it 'has 1 argument name' do
|
211
|
-
@node.arg_names.
|
211
|
+
expect(@node.arg_names).to eq([:param])
|
212
212
|
end
|
213
213
|
end
|
214
214
|
|
@@ -218,7 +218,7 @@ describe SexpExtensions::CallNode do
|
|
218
218
|
@node.extend(SexpExtensions::CallNode)
|
219
219
|
end
|
220
220
|
it 'has 2 argument names' do
|
221
|
-
@node.arg_names.
|
221
|
+
expect(@node.arg_names).to eq([:x, :y])
|
222
222
|
end
|
223
223
|
end
|
224
224
|
end
|
@@ -230,7 +230,7 @@ describe SexpExtensions::IterNode do
|
|
230
230
|
@node.extend(SexpExtensions::IterNode)
|
231
231
|
end
|
232
232
|
it 'has no parameter names' do
|
233
|
-
@node.parameter_names.
|
233
|
+
expect(@node.parameter_names).to eq([])
|
234
234
|
end
|
235
235
|
end
|
236
236
|
|
@@ -240,7 +240,7 @@ describe SexpExtensions::IterNode do
|
|
240
240
|
@node.extend(SexpExtensions::IterNode)
|
241
241
|
end
|
242
242
|
it 'has 1 parameter name' do
|
243
|
-
@node.parameter_names.
|
243
|
+
expect(@node.parameter_names).to eq(s(:param))
|
244
244
|
end
|
245
245
|
end
|
246
246
|
|
@@ -250,7 +250,7 @@ describe SexpExtensions::IterNode do
|
|
250
250
|
@node.extend(SexpExtensions::IterNode)
|
251
251
|
end
|
252
252
|
it 'has 2 parameter names' do
|
253
|
-
@node.parameter_names.
|
253
|
+
expect(@node.parameter_names).to eq([:x, :y])
|
254
254
|
end
|
255
255
|
end
|
256
256
|
end
|
@@ -261,14 +261,24 @@ describe SexpExtensions::ModuleNode do
|
|
261
261
|
mod = ast(:module, :Fred, nil)
|
262
262
|
mod
|
263
263
|
end
|
264
|
-
|
265
|
-
|
266
|
-
|
264
|
+
|
265
|
+
it 'has the correct #name' do
|
266
|
+
expect(subject.name).to eq(:Fred)
|
267
|
+
end
|
268
|
+
|
269
|
+
it 'has the correct #simple_name' do
|
270
|
+
expect(subject.simple_name).to eq(:Fred)
|
271
|
+
end
|
272
|
+
|
273
|
+
it 'has the correct #text_name' do
|
274
|
+
expect(subject.text_name).to eq('Fred')
|
275
|
+
end
|
276
|
+
|
267
277
|
it 'has a simple full_name' do
|
268
|
-
subject.full_name('').
|
278
|
+
expect(subject.full_name('')).to eq('Fred')
|
269
279
|
end
|
270
280
|
it 'has a fq full_name' do
|
271
|
-
subject.full_name('Blimey::O::Reilly').
|
281
|
+
expect(subject.full_name('Blimey::O::Reilly')).to eq('Blimey::O::Reilly::Fred')
|
272
282
|
end
|
273
283
|
end
|
274
284
|
|
@@ -277,14 +287,25 @@ describe SexpExtensions::ModuleNode do
|
|
277
287
|
mod = ast(:module, s(:colon2, s(:const, :Foo), :Bar), nil)
|
278
288
|
mod
|
279
289
|
end
|
280
|
-
|
281
|
-
|
282
|
-
|
290
|
+
|
291
|
+
it 'has the correct #name' do
|
292
|
+
expect(subject.name).to eq(s(:colon2, s(:const, :Foo), :Bar))
|
293
|
+
end
|
294
|
+
|
295
|
+
it 'has the correct #simple_name' do
|
296
|
+
expect(subject.simple_name).to eq(:Bar)
|
297
|
+
end
|
298
|
+
|
299
|
+
it 'has the correct #text_name' do
|
300
|
+
expect(subject.text_name).to eq('Foo::Bar')
|
301
|
+
end
|
302
|
+
|
283
303
|
it 'has a simple full_name' do
|
284
|
-
subject.full_name('').
|
304
|
+
expect(subject.full_name('')).to eq('Foo::Bar')
|
285
305
|
end
|
306
|
+
|
286
307
|
it 'has a fq full_name' do
|
287
|
-
subject.full_name('Blimey::O::Reilly').
|
308
|
+
expect(subject.full_name('Blimey::O::Reilly')).to eq('Blimey::O::Reilly::Foo::Bar')
|
288
309
|
end
|
289
310
|
end
|
290
311
|
end
|