reek 1.3.8 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (142) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +11 -0
  3. data/README.md +22 -14
  4. data/Rakefile +2 -15
  5. data/assets/html_output.html.erb +103 -0
  6. data/features/command_line_interface/options.feature +3 -0
  7. data/features/command_line_interface/smell_selection.feature +19 -0
  8. data/features/rake_task/rake_task.feature +1 -1
  9. data/features/reports/reports.feature +16 -0
  10. data/features/reports/yaml.feature +26 -23
  11. data/features/samples.feature +2 -1
  12. data/features/step_definitions/reek_steps.rb +15 -15
  13. data/features/support/env.rb +7 -9
  14. data/lib/reek/cli/application.rb +2 -4
  15. data/lib/reek/cli/command.rb +12 -0
  16. data/lib/reek/cli/help_command.rb +3 -6
  17. data/lib/reek/cli/options.rb +147 -0
  18. data/lib/reek/cli/reek_command.rb +18 -14
  19. data/lib/reek/cli/report/formatter.rb +56 -0
  20. data/lib/reek/cli/report/report.rb +106 -0
  21. data/lib/reek/cli/report/strategy.rb +63 -0
  22. data/lib/reek/cli/version_command.rb +3 -6
  23. data/lib/reek/config_file_exception.rb +0 -1
  24. data/lib/reek/core/code_context.rb +1 -3
  25. data/lib/reek/core/code_parser.rb +13 -12
  26. data/lib/reek/core/method_context.rb +13 -2
  27. data/lib/reek/core/module_context.rb +0 -4
  28. data/lib/reek/core/object_refs.rb +2 -3
  29. data/lib/reek/core/singleton_method_context.rb +0 -2
  30. data/lib/reek/core/smell_configuration.rb +3 -5
  31. data/lib/reek/core/smell_repository.rb +7 -8
  32. data/lib/reek/core/sniffer.rb +4 -10
  33. data/lib/reek/core/stop_context.rb +2 -4
  34. data/lib/reek/core/warning_collector.rb +0 -1
  35. data/lib/reek/examiner.rb +19 -17
  36. data/lib/reek/rake/task.rb +7 -10
  37. data/lib/reek/smell_warning.rb +4 -8
  38. data/lib/reek/smells.rb +0 -1
  39. data/lib/reek/smells/attribute.rb +8 -11
  40. data/lib/reek/smells/boolean_parameter.rb +5 -7
  41. data/lib/reek/smells/class_variable.rb +6 -7
  42. data/lib/reek/smells/control_parameter.rb +78 -45
  43. data/lib/reek/smells/data_clump.rb +13 -16
  44. data/lib/reek/smells/duplicate_method_call.rb +13 -11
  45. data/lib/reek/smells/feature_envy.rb +6 -7
  46. data/lib/reek/smells/irresponsible_module.rb +4 -6
  47. data/lib/reek/smells/long_parameter_list.rb +5 -7
  48. data/lib/reek/smells/long_yield_list.rb +2 -4
  49. data/lib/reek/smells/nested_iterators.rb +12 -22
  50. data/lib/reek/smells/nil_check.rb +35 -46
  51. data/lib/reek/smells/prima_donna_method.rb +24 -16
  52. data/lib/reek/smells/repeated_conditional.rb +8 -10
  53. data/lib/reek/smells/smell_detector.rb +9 -7
  54. data/lib/reek/smells/too_many_instance_variables.rb +7 -9
  55. data/lib/reek/smells/too_many_methods.rb +6 -8
  56. data/lib/reek/smells/too_many_statements.rb +4 -6
  57. data/lib/reek/smells/uncommunicative_method_name.rb +5 -7
  58. data/lib/reek/smells/uncommunicative_module_name.rb +5 -7
  59. data/lib/reek/smells/uncommunicative_parameter_name.rb +7 -9
  60. data/lib/reek/smells/uncommunicative_variable_name.rb +15 -18
  61. data/lib/reek/smells/unused_parameters.rb +5 -45
  62. data/lib/reek/smells/utility_function.rb +9 -10
  63. data/lib/reek/source.rb +0 -1
  64. data/lib/reek/source/code_comment.rb +7 -8
  65. data/lib/reek/source/config_file.rb +2 -4
  66. data/lib/reek/source/core_extras.rb +1 -1
  67. data/lib/reek/source/reference_collector.rb +1 -2
  68. data/lib/reek/source/sexp_extensions.rb +93 -10
  69. data/lib/reek/source/sexp_formatter.rb +2 -3
  70. data/lib/reek/source/sexp_node.rb +19 -15
  71. data/lib/reek/source/source_code.rb +4 -14
  72. data/lib/reek/source/source_file.rb +3 -5
  73. data/lib/reek/source/source_locator.rb +5 -6
  74. data/lib/reek/source/source_repository.rb +3 -3
  75. data/lib/reek/source/tree_dresser.rb +2 -2
  76. data/lib/reek/spec.rb +1 -2
  77. data/lib/reek/spec/should_reek.rb +8 -5
  78. data/lib/reek/spec/should_reek_of.rb +6 -4
  79. data/lib/reek/spec/should_reek_only_of.rb +10 -6
  80. data/lib/reek/version.rb +1 -1
  81. data/reek.gemspec +34 -30
  82. data/spec/gem/updates_spec.rb +3 -4
  83. data/spec/gem/yard_spec.rb +1 -2
  84. data/spec/matchers/smell_of_matcher.rb +12 -14
  85. data/spec/quality/reek_source_spec.rb +42 -0
  86. data/spec/reek/cli/help_command_spec.rb +7 -5
  87. data/spec/reek/cli/report_spec.rb +89 -22
  88. data/spec/reek/cli/version_command_spec.rb +8 -6
  89. data/spec/reek/core/code_context_spec.rb +25 -26
  90. data/spec/reek/core/code_parser_spec.rb +6 -6
  91. data/spec/reek/core/method_context_spec.rb +18 -18
  92. data/spec/reek/core/module_context_spec.rb +5 -5
  93. data/spec/reek/core/object_refs_spec.rb +21 -22
  94. data/spec/reek/core/smell_configuration_spec.rb +22 -21
  95. data/spec/reek/core/stop_context_spec.rb +2 -2
  96. data/spec/reek/core/warning_collector_spec.rb +3 -3
  97. data/spec/reek/examiner_spec.rb +9 -9
  98. data/spec/reek/smell_warning_spec.rb +29 -29
  99. data/spec/reek/smells/attribute_spec.rb +6 -6
  100. data/spec/reek/smells/behaves_like_variable_detector.rb +6 -6
  101. data/spec/reek/smells/boolean_parameter_spec.rb +17 -17
  102. data/spec/reek/smells/class_variable_spec.rb +9 -9
  103. data/spec/reek/smells/control_parameter_spec.rb +161 -137
  104. data/spec/reek/smells/data_clump_spec.rb +22 -19
  105. data/spec/reek/smells/duplicate_method_call_spec.rb +71 -27
  106. data/spec/reek/smells/feature_envy_spec.rb +32 -32
  107. data/spec/reek/smells/irresponsible_module_spec.rb +21 -21
  108. data/spec/reek/smells/long_parameter_list_spec.rb +14 -14
  109. data/spec/reek/smells/long_yield_list_spec.rb +6 -6
  110. data/spec/reek/smells/nested_iterators_spec.rb +21 -21
  111. data/spec/reek/smells/nil_check_spec.rb +23 -15
  112. data/spec/reek/smells/prima_donna_method_spec.rb +5 -5
  113. data/spec/reek/smells/repeated_conditional_spec.rb +14 -14
  114. data/spec/reek/smells/smell_detector_shared.rb +9 -9
  115. data/spec/reek/smells/too_many_instance_variables_spec.rb +12 -12
  116. data/spec/reek/smells/too_many_methods_spec.rb +10 -10
  117. data/spec/reek/smells/too_many_statements_spec.rb +41 -41
  118. data/spec/reek/smells/uncommunicative_method_name_spec.rb +4 -4
  119. data/spec/reek/smells/uncommunicative_module_name_spec.rb +12 -12
  120. data/spec/reek/smells/uncommunicative_parameter_name_spec.rb +21 -21
  121. data/spec/reek/smells/uncommunicative_variable_name_spec.rb +49 -49
  122. data/spec/reek/smells/unused_parameters_spec.rb +26 -16
  123. data/spec/reek/smells/utility_function_spec.rb +20 -20
  124. data/spec/reek/source/code_comment_spec.rb +37 -37
  125. data/spec/reek/source/object_source_spec.rb +5 -5
  126. data/spec/reek/source/reference_collector_spec.rb +9 -9
  127. data/spec/reek/source/sexp_extensions_spec.rb +73 -52
  128. data/spec/reek/source/sexp_formatter_spec.rb +3 -4
  129. data/spec/reek/source/sexp_node_spec.rb +3 -3
  130. data/spec/reek/source/source_code_spec.rb +16 -15
  131. data/spec/reek/source/tree_dresser_spec.rb +2 -2
  132. data/spec/reek/spec/should_reek_of_spec.rb +11 -11
  133. data/spec/reek/spec/should_reek_only_of_spec.rb +11 -11
  134. data/spec/reek/spec/should_reek_spec.rb +11 -11
  135. data/spec/samples/one_smelly_file/dirty.rb +3 -0
  136. data/spec/spec_helper.rb +0 -6
  137. data/tasks/develop.rake +8 -16
  138. data/tasks/reek.rake +5 -13
  139. data/tasks/test.rake +5 -22
  140. metadata +56 -34
  141. data/lib/reek/cli/command_line.rb +0 -126
  142. data/lib/reek/cli/report.rb +0 -138
@@ -15,54 +15,54 @@ describe UncommunicativeParameterName do
15
15
  it_should_behave_like 'SmellDetector'
16
16
 
17
17
  { 'obj.' => 'with a receiveer',
18
- '' => 'without a receiver'}.each do |host, description|
18
+ '' => 'without a receiver' }.each do |host, description|
19
19
  context "in a method definition #{description}" do
20
20
  it 'does not recognise *' do
21
- "def #{host}help(xray, *) basics(17) end".
22
- should_not smell_of(UncommunicativeParameterName)
21
+ expect("def #{host}help(xray, *) basics(17) end").
22
+ not_to smell_of(UncommunicativeParameterName)
23
23
  end
24
24
 
25
25
  it "reports parameter's name" do
26
26
  src = "def #{host}help(x) basics(x) end"
27
- src.should smell_of(UncommunicativeParameterName,
28
- {UncommunicativeParameterName::PARAMETER_NAME_KEY => 'x'})
27
+ expect(src).to smell_of(UncommunicativeParameterName,
28
+ UncommunicativeParameterName::PARAMETER_NAME_KEY => 'x')
29
29
  end
30
30
 
31
- it "does not report unused parameters" do
31
+ it 'does not report unused parameters' do
32
32
  src = "def #{host}help(x) basics(17) end"
33
- src.should_not smell_of(UncommunicativeParameterName)
33
+ expect(src).not_to smell_of(UncommunicativeParameterName)
34
34
  end
35
35
 
36
36
  it 'does not report two-letter parameter names' do
37
- "def #{host}help(ab) basics(ab) end".
38
- should_not smell_of(UncommunicativeParameterName)
37
+ expect("def #{host}help(ab) basics(ab) end").
38
+ not_to smell_of(UncommunicativeParameterName)
39
39
  end
40
40
 
41
41
  it 'reports names of the form "x2"' do
42
42
  src = "def #{host}help(x2) basics(x2) end"
43
- src.should smell_of(UncommunicativeParameterName,
44
- {UncommunicativeParameterName::PARAMETER_NAME_KEY => 'x2'})
43
+ expect(src).to smell_of(UncommunicativeParameterName,
44
+ UncommunicativeParameterName::PARAMETER_NAME_KEY => 'x2')
45
45
  end
46
46
 
47
47
  it 'reports long name ending in a number' do
48
48
  src = "def #{host}help(param2) basics(param2) end"
49
- src.should smell_of(UncommunicativeParameterName,
50
- {UncommunicativeParameterName::PARAMETER_NAME_KEY => 'param2'})
49
+ expect(src).to smell_of(UncommunicativeParameterName,
50
+ UncommunicativeParameterName::PARAMETER_NAME_KEY => 'param2')
51
51
  end
52
52
 
53
53
  it 'does not report unused anonymous parameter' do
54
- "def #{host}help(_) basics(17) end".
55
- should_not smell_of(UncommunicativeParameterName)
54
+ expect("def #{host}help(_) basics(17) end").
55
+ not_to smell_of(UncommunicativeParameterName)
56
56
  end
57
57
 
58
58
  it 'reports used anonymous parameter' do
59
- "def #{host}help(_) basics(_) end".
60
- should smell_of(UncommunicativeParameterName)
59
+ expect("def #{host}help(_) basics(_) end").
60
+ to smell_of(UncommunicativeParameterName)
61
61
  end
62
62
 
63
63
  it 'reports used parameters marked as unused' do
64
- "def #{host}help(_unused) basics(_unused) end".
65
- should smell_of(UncommunicativeParameterName)
64
+ expect("def #{host}help(_unused) basics(_unused) end").
65
+ to smell_of(UncommunicativeParameterName)
66
66
  end
67
67
  end
68
68
  end
@@ -78,8 +78,8 @@ describe UncommunicativeParameterName do
78
78
  it_should_behave_like 'common fields set correctly'
79
79
 
80
80
  it 'reports the correct values' do
81
- @warning.smell[UncommunicativeParameterName::PARAMETER_NAME_KEY].should == 'bad2'
82
- @warning.lines.should == [1]
81
+ expect(@warning.smell[UncommunicativeParameterName::PARAMETER_NAME_KEY]).to eq('bad2')
82
+ expect(@warning.lines).to eq([1])
83
83
  end
84
84
  end
85
85
  end
@@ -15,61 +15,61 @@ describe UncommunicativeVariableName do
15
15
 
16
16
  it_should_behave_like 'SmellDetector'
17
17
 
18
- context "field name" do
18
+ context 'field name' do
19
19
  it 'does not report use of one-letter fieldname' do
20
20
  src = 'class Thing; def simple(fred) @x end end'
21
- src.should_not smell_of(UncommunicativeVariableName)
21
+ expect(src).not_to smell_of(UncommunicativeVariableName)
22
22
  end
23
23
  it 'reports one-letter fieldname in assignment' do
24
24
  src = 'class Thing; def simple(fred) @x = fred end end'
25
- src.should reek_of(:UncommunicativeVariableName, /@x/, /Thing/, /variable name/)
25
+ expect(src).to reek_of(:UncommunicativeVariableName, /@x/, /Thing/, /variable name/)
26
26
  end
27
27
  end
28
28
 
29
- context "local variable name" do
29
+ context 'local variable name' do
30
30
  it 'does not report one-word variable name' do
31
- 'def help(fred) simple = jim(45) end'.should_not smell_of(UncommunicativeVariableName)
31
+ expect('def help(fred) simple = jim(45) end').not_to smell_of(UncommunicativeVariableName)
32
32
  end
33
33
  it 'does not report single underscore as a variable name' do
34
- 'def help(fred) _ = jim(45) end'.should_not smell_of(UncommunicativeVariableName)
34
+ expect('def help(fred) _ = jim(45) end').not_to smell_of(UncommunicativeVariableName)
35
35
  end
36
36
  it 'reports one-letter variable name' do
37
37
  src = 'def simple(fred) x = jim(45) end'
38
- src.should smell_of(UncommunicativeVariableName,
39
- {UncommunicativeVariableName::VARIABLE_NAME_KEY => 'x'})
38
+ expect(src).to smell_of(UncommunicativeVariableName,
39
+ UncommunicativeVariableName::VARIABLE_NAME_KEY => 'x')
40
40
  end
41
41
  it 'reports name of the form "x2"' do
42
42
  src = 'def simple(fred) x2 = jim(45) end'
43
- src.should smell_of(UncommunicativeVariableName,
44
- {UncommunicativeVariableName::VARIABLE_NAME_KEY => 'x2'})
43
+ expect(src).to smell_of(UncommunicativeVariableName,
44
+ UncommunicativeVariableName::VARIABLE_NAME_KEY => 'x2')
45
45
  end
46
46
  it 'reports long name ending in a number' do
47
47
  @bad_var = 'var123'
48
48
  src = "def simple(fred) #{@bad_var} = jim(45) end"
49
- src.should smell_of(UncommunicativeVariableName,
50
- {UncommunicativeVariableName::VARIABLE_NAME_KEY => @bad_var})
49
+ expect(src).to smell_of(UncommunicativeVariableName,
50
+ UncommunicativeVariableName::VARIABLE_NAME_KEY => @bad_var)
51
51
  end
52
52
  it 'reports variable name only once' do
53
53
  src = 'def simple(fred) x = jim(45); x = y end'
54
54
  ctx = CodeContext.new(nil, src.to_reek_source.syntax_tree)
55
55
  smells = @detector.examine_context(ctx)
56
- smells.length.should == 1
57
- smells[0].subclass.should == UncommunicativeVariableName::SMELL_SUBCLASS
58
- smells[0].smell[UncommunicativeVariableName::VARIABLE_NAME_KEY].should == 'x'
59
- smells[0].lines.should == [1,1]
56
+ expect(smells.length).to eq(1)
57
+ expect(smells[0].subclass).to eq(UncommunicativeVariableName::SMELL_SUBCLASS)
58
+ expect(smells[0].smell[UncommunicativeVariableName::VARIABLE_NAME_KEY]).to eq('x')
59
+ expect(smells[0].lines).to eq([1, 1])
60
60
  end
61
61
  it 'reports a bad name inside a block' do
62
62
  src = 'def clean(text) text.each { q2 = 3 } end'
63
- src.should smell_of(UncommunicativeVariableName,
64
- {UncommunicativeVariableName::VARIABLE_NAME_KEY => 'q2'})
63
+ expect(src).to smell_of(UncommunicativeVariableName,
64
+ UncommunicativeVariableName::VARIABLE_NAME_KEY => 'q2')
65
65
  end
66
66
  it 'reports variable name outside any method' do
67
- 'class Simple; x = jim(45); end'.should reek_of(:UncommunicativeVariableName, /x/)
67
+ expect('class Simple; x = jim(45); end').to reek_of(:UncommunicativeVariableName, /x/)
68
68
  end
69
69
  end
70
70
 
71
- context "block parameter name" do
72
- it "reports deep block parameter" do
71
+ context 'block parameter name' do
72
+ it 'reports deep block parameter' do
73
73
  src = <<EOS
74
74
  def bad
75
75
  unless @mod then
@@ -77,73 +77,73 @@ describe UncommunicativeVariableName do
77
77
  end
78
78
  end
79
79
  EOS
80
- src.should smell_of(UncommunicativeVariableName,
81
- {UncommunicativeVariableName::VARIABLE_NAME_KEY => 'x'})
80
+ expect(src).to smell_of(UncommunicativeVariableName,
81
+ UncommunicativeVariableName::VARIABLE_NAME_KEY => 'x')
82
82
  end
83
83
 
84
- it "reports all relevant block parameters" do
84
+ it 'reports all relevant block parameters' do
85
85
  src = <<-EOS
86
86
  def bad
87
87
  @foo.map { |x, y| x + y }
88
88
  end
89
89
  EOS
90
- src.should smell_of(UncommunicativeVariableName,
91
- {UncommunicativeVariableName::VARIABLE_NAME_KEY => 'x'},
92
- {UncommunicativeVariableName::VARIABLE_NAME_KEY => 'y'})
90
+ expect(src).to smell_of(UncommunicativeVariableName,
91
+ { UncommunicativeVariableName::VARIABLE_NAME_KEY => 'x' },
92
+ UncommunicativeVariableName::VARIABLE_NAME_KEY => 'y')
93
93
  end
94
94
 
95
- it "reports block parameters used outside of methods" do
95
+ it 'reports block parameters used outside of methods' do
96
96
  src = <<-EOS
97
97
  class Foo
98
98
  @foo.map { |x| x * 2 }
99
99
  end
100
100
  EOS
101
- src.should smell_of(UncommunicativeVariableName,
102
- {UncommunicativeVariableName::VARIABLE_NAME_KEY => 'x'})
101
+ expect(src).to smell_of(UncommunicativeVariableName,
102
+ UncommunicativeVariableName::VARIABLE_NAME_KEY => 'x')
103
103
  end
104
104
 
105
- it "reports splatted block parameters correctly" do
105
+ it 'reports splatted block parameters correctly' do
106
106
  src = <<-EOS
107
107
  def bad
108
108
  @foo.map { |*y| y << 1 }
109
109
  end
110
110
  EOS
111
- src.should smell_of(UncommunicativeVariableName,
112
- {UncommunicativeVariableName::VARIABLE_NAME_KEY => 'y'})
111
+ expect(src).to smell_of(UncommunicativeVariableName,
112
+ UncommunicativeVariableName::VARIABLE_NAME_KEY => 'y')
113
113
  end
114
114
 
115
- it "reports nested block parameters" do
115
+ it 'reports nested block parameters' do
116
116
  src = <<-EOS
117
117
  def bad
118
118
  @foo.map { |(x, y)| x + y }
119
119
  end
120
120
  EOS
121
- src.should smell_of(UncommunicativeVariableName,
122
- {UncommunicativeVariableName::VARIABLE_NAME_KEY => 'x'},
123
- {UncommunicativeVariableName::VARIABLE_NAME_KEY => 'y'})
121
+ expect(src).to smell_of(UncommunicativeVariableName,
122
+ { UncommunicativeVariableName::VARIABLE_NAME_KEY => 'x' },
123
+ UncommunicativeVariableName::VARIABLE_NAME_KEY => 'y')
124
124
  end
125
125
 
126
- it "reports splatted nested block parameters" do
126
+ it 'reports splatted nested block parameters' do
127
127
  src = <<-EOS
128
128
  def bad
129
129
  @foo.map { |(x, *y)| x + y }
130
130
  end
131
131
  EOS
132
- src.should smell_of(UncommunicativeVariableName,
133
- {UncommunicativeVariableName::VARIABLE_NAME_KEY => 'x'},
134
- {UncommunicativeVariableName::VARIABLE_NAME_KEY => 'y'})
132
+ expect(src).to smell_of(UncommunicativeVariableName,
133
+ { UncommunicativeVariableName::VARIABLE_NAME_KEY => 'x' },
134
+ UncommunicativeVariableName::VARIABLE_NAME_KEY => 'y')
135
135
  end
136
136
 
137
- it "reports deeply nested block parameters" do
137
+ it 'reports deeply nested block parameters' do
138
138
  src = <<-EOS
139
139
  def bad
140
140
  @foo.map { |(x, (y, z))| x + y + z }
141
141
  end
142
142
  EOS
143
- src.should smell_of(UncommunicativeVariableName,
144
- {UncommunicativeVariableName::VARIABLE_NAME_KEY => 'x'},
145
- {UncommunicativeVariableName::VARIABLE_NAME_KEY => 'y'},
146
- {UncommunicativeVariableName::VARIABLE_NAME_KEY => 'z'})
143
+ expect(src).to smell_of(UncommunicativeVariableName,
144
+ { UncommunicativeVariableName::VARIABLE_NAME_KEY => 'x' },
145
+ { UncommunicativeVariableName::VARIABLE_NAME_KEY => 'y' },
146
+ UncommunicativeVariableName::VARIABLE_NAME_KEY => 'z')
147
147
  end
148
148
 
149
149
  end
@@ -167,8 +167,8 @@ EOS
167
167
  it_should_behave_like 'common fields set correctly'
168
168
 
169
169
  it 'reports the correct values' do
170
- @warning.smell['variable_name'].should == 'x2'
171
- @warning.lines.should == [3,5]
170
+ expect(@warning.smell['variable_name']).to eq('x2')
171
+ expect(@warning.lines).to eq([3, 5])
172
172
  end
173
173
  end
174
174
 
@@ -183,7 +183,7 @@ EOS
183
183
  it_should_behave_like 'common fields set correctly'
184
184
 
185
185
  it 'reports the fq context' do
186
- @warning.context.should == 'self.bad'
186
+ expect(@warning.context).to eq('self.bad')
187
187
  end
188
188
  end
189
189
  end
@@ -10,57 +10,67 @@ describe UnusedParameters do
10
10
  context 'for methods' do
11
11
 
12
12
  it 'reports nothing for no parameters' do
13
- 'def simple; true end'.should_not smell_of(UnusedParameters)
13
+ expect('def simple; true end').not_to smell_of(UnusedParameters)
14
14
  end
15
15
 
16
16
  it 'reports nothing for used parameter' do
17
- 'def simple(sum); sum end'.should_not smell_of(UnusedParameters)
17
+ expect('def simple(sum); sum end').not_to smell_of(UnusedParameters)
18
18
  end
19
19
 
20
20
  it 'reports for 1 used and 2 unused parameter' do
21
21
  src = 'def simple(num,sum,denum); sum end'
22
- src.should smell_of(UnusedParameters,
23
- {UnusedParameters::PARAMETER_KEY => 'num'},
24
- {UnusedParameters::PARAMETER_KEY => 'denum'})
22
+ expect(src).to smell_of(UnusedParameters,
23
+ { UnusedParameters::PARAMETER_KEY => 'num' },
24
+ UnusedParameters::PARAMETER_KEY => 'denum')
25
25
  end
26
26
 
27
27
  it 'reports for 3 used and 1 unused parameter' do
28
28
  src = 'def simple(num,sum,denum,quotient); num + denum + sum end'
29
- src.should smell_of(UnusedParameters,
30
- {UnusedParameters::PARAMETER_KEY => 'quotient'})
29
+ expect(src).to smell_of(UnusedParameters,
30
+ UnusedParameters::PARAMETER_KEY => 'quotient')
31
31
  end
32
32
 
33
33
  it 'reports nothing for used splatted parameter' do
34
- 'def simple(*sum); sum end'.should_not smell_of(UnusedParameters)
34
+ expect('def simple(*sum); sum end').not_to smell_of(UnusedParameters)
35
35
  end
36
36
 
37
37
  it 'reports nothing for unused anonymous parameter' do
38
- 'def simple(_); end'.should_not smell_of(UnusedParameters)
38
+ expect('def simple(_); end').not_to smell_of(UnusedParameters)
39
39
  end
40
40
 
41
41
  it 'reports nothing for named parameters prefixed with _' do
42
- 'def simple(_name); end'.should_not smell_of(UnusedParameters)
42
+ expect('def simple(_name); end').not_to smell_of(UnusedParameters)
43
43
  end
44
44
 
45
45
  it 'reports nothing for unused anonymous splatted parameter' do
46
- 'def simple(*); end'.should_not smell_of(UnusedParameters)
46
+ expect('def simple(*); end').not_to smell_of(UnusedParameters)
47
47
  end
48
48
 
49
49
  it 'reports nothing when using super with implicit arguments' do
50
- 'def simple(*args); super; end'.should_not smell_of(UnusedParameters)
50
+ expect('def simple(*args); super; end').not_to smell_of(UnusedParameters)
51
51
  end
52
52
 
53
53
  it 'reports something when using super explicitely passing no arguments' do
54
- 'def simple(*args); super(); end'.should smell_of(UnusedParameters)
54
+ expect('def simple(*args); super(); end').to smell_of(UnusedParameters)
55
55
  end
56
56
 
57
57
  it 'reports nothing when using super explicitely passing all arguments' do
58
- 'def simple(*args); super(*args); end'.should_not smell_of(UnusedParameters)
58
+ expect('def simple(*args); super(*args); end').not_to smell_of(UnusedParameters)
59
59
  end
60
60
 
61
61
  it 'reports nothing when using super in a nested context' do
62
- 'def simple(*args); call_other("something", super); end'.
63
- should_not smell_of(UnusedParameters)
62
+ expect('def simple(*args); call_other("something", super); end').
63
+ not_to smell_of(UnusedParameters)
64
+ end
65
+
66
+ it 'reports something when not using a keyword argument with splat' do
67
+ expect('def simple(var, kw: :val, **args); @var, @kw = var, kw; end').
68
+ to smell_of(UnusedParameters)
69
+ end
70
+
71
+ it 'reports nothing when using a keyword argument with splat' do
72
+ expect('def simple(var, kw: :val, **args); @var, @kw, @args = var, kw, args; end').
73
+ not_to smell_of(UnusedParameters)
64
74
  end
65
75
  end
66
76
  end
@@ -18,7 +18,7 @@ describe UtilityFunction do
18
18
  it 'ignores the receiver' do
19
19
  src = "def #{receiver}.simple(arga) arga.to_s + arga.to_i end"
20
20
  ctx = MethodContext.new(nil, src.to_reek_source.syntax_tree)
21
- @detector.examine_context(ctx).should be_empty
21
+ expect(@detector.examine_context(ctx)).to be_empty
22
22
  end
23
23
  end
24
24
  end
@@ -26,60 +26,60 @@ describe UtilityFunction do
26
26
  it 'does not report empty method' do
27
27
  src = 'def simple(arga) end'
28
28
  ctx = MethodContext.new(nil, src.to_reek_source.syntax_tree)
29
- @detector.examine_context(ctx).should be_empty
29
+ expect(@detector.examine_context(ctx)).to be_empty
30
30
  end
31
31
  it 'does not report literal' do
32
- 'def simple() 3; end'.should_not reek
32
+ expect('def simple() 3; end').not_to reek
33
33
  end
34
34
  it 'does not report instance variable reference' do
35
- 'def simple() @yellow end'.should_not reek
35
+ expect('def simple() @yellow end').not_to reek
36
36
  end
37
37
  it 'does not report vcall' do
38
- 'def simple() y end'.should_not reek
38
+ expect('def simple() y end').not_to reek
39
39
  end
40
40
  it 'does not report references to self' do
41
- 'def into; self; end'.should_not reek
41
+ expect('def into; self; end').not_to reek
42
42
  end
43
43
  it 'recognises an ivar reference within a block' do
44
- 'def clean(text) text.each { @fred = 3} end'.should_not reek
44
+ expect('def clean(text) text.each { @fred = 3} end').not_to reek
45
45
  end
46
46
  it 'copes with nil superclass' do
47
- '# clean class for testing purposes
48
- class Object; def is_maybe?() false end end'.should_not reek
47
+ expect('# clean class for testing purposes
48
+ class Object; def is_maybe?() false end end').not_to reek
49
49
  end
50
50
  end
51
51
 
52
52
  context 'with only one call' do
53
53
  it 'does not report a call to a parameter' do
54
- 'def simple(arga) arga.to_s end'.should_not reek_of(:UtilityFunction, /simple/)
54
+ expect('def simple(arga) arga.to_s end').not_to reek_of(:UtilityFunction, /simple/)
55
55
  end
56
56
  it 'does not report a call to a constant' do
57
- 'def simple(arga) FIELDS[arga] end'.should_not reek
57
+ expect('def simple(arga) FIELDS[arga] end').not_to reek
58
58
  end
59
59
  end
60
60
 
61
61
  context 'with two or more calls' do
62
62
  it 'reports two calls' do
63
- 'def simple(arga) arga.to_s + arga.to_i end'.should reek_of(:UtilityFunction, /simple/)
63
+ expect('def simple(arga) arga.to_s + arga.to_i end').to reek_of(:UtilityFunction, /simple/)
64
64
  end
65
65
  it 'counts a local call in a param initializer' do
66
- 'def simple(arga=local) arga.to_s end'.should_not reek_of(:UtilityFunction)
66
+ expect('def simple(arga=local) arga.to_s end').not_to reek_of(:UtilityFunction)
67
67
  end
68
68
  it 'should count usages of self'do
69
- 'def <=>(other) Options[:sort_order].compare(self, other) end'.should_not reek
69
+ expect('def <=>(other) Options[:sort_order].compare(self, other) end').not_to reek
70
70
  end
71
71
  it 'should count self reference within a dstr' do
72
- 'def as(alias_name); "#{self} as #{alias_name}".to_sym; end'.should_not reek
72
+ expect('def as(alias_name); "#{self} as #{alias_name}".to_sym; end').not_to reek
73
73
  end
74
74
  it 'should count calls to self within a dstr' do
75
- 'def to_sql; "\'#{self.gsub(/\'/, "\'\'")}\'"; end'.should_not reek
75
+ expect('def to_sql; "\'#{self.gsub(/\'/, "\'\'")}\'"; end').not_to reek
76
76
  end
77
77
  it 'should report message chain' do
78
- 'def simple(arga) arga.b.c end'.should reek_of(:UtilityFunction, /simple/)
78
+ expect('def simple(arga) arga.b.c end').to reek_of(:UtilityFunction, /simple/)
79
79
  end
80
80
 
81
81
  it 'does not report a method that calls super' do
82
- 'def child(arg) super; arg.to_s; end'.should_not reek
82
+ expect('def child(arg) super; arg.to_s; end').not_to reek
83
83
  end
84
84
 
85
85
  it 'should recognise a deep call' do
@@ -95,7 +95,7 @@ class Object; def is_maybe?() false end end'.should_not reek
95
95
  end
96
96
  end
97
97
  EOS
98
- src.should_not reek
98
+ expect(src).not_to reek
99
99
  end
100
100
  end
101
101
 
@@ -115,7 +115,7 @@ EOS
115
115
  it_should_behave_like 'common fields set correctly'
116
116
 
117
117
  it 'reports the line number of the method' do
118
- @warning.lines.should == [1]
118
+ expect(@warning.lines).to eq([1])
119
119
  end
120
120
  end
121
121
  end