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
@@ -14,7 +14,7 @@ shared_examples_for 'a data clump detector' do
14
14
  def third(pa) pa - pb + @fred; end
15
15
  end
16
16
  EOS
17
- src.should_not smell_of(DataClump)
17
+ expect(src).not_to smell_of(DataClump)
18
18
  end
19
19
 
20
20
  context 'with 3 identical pairs' do
@@ -34,25 +34,25 @@ EOS
34
34
  @yaml = @warning.to_yaml
35
35
  end
36
36
  it 'records only the one smell' do
37
- @smells.length.should == 1
37
+ expect(@smells.length).to eq(1)
38
38
  end
39
39
  it 'reports all parameters' do
40
- @smells[0].smell[DataClump::PARAMETERS_KEY].should == ['pa', 'pb']
40
+ expect(@smells[0].smell[DataClump::PARAMETERS_KEY]).to eq(['pa', 'pb'])
41
41
  end
42
42
  it 'reports the number of occurrences' do
43
- @smells[0].smell[DataClump::OCCURRENCES_KEY].should == 3
43
+ expect(@smells[0].smell[DataClump::OCCURRENCES_KEY]).to eq(3)
44
44
  end
45
45
  it 'reports all methods' do
46
- @smells[0].smell[DataClump::METHODS_KEY].should == ['first', 'second', 'third']
46
+ expect(@smells[0].smell[DataClump::METHODS_KEY]).to eq(['first', 'second', 'third'])
47
47
  end
48
48
  it 'reports the declaration line numbers' do
49
- @smells[0].lines.should == [2,3,4]
49
+ expect(@smells[0].lines).to eq([2, 3, 4])
50
50
  end
51
51
  it 'reports the correct smell class' do
52
- @smells[0].smell_class.should == DataClump::SMELL_CLASS
52
+ expect(@smells[0].smell_class).to eq(DataClump::SMELL_CLASS)
53
53
  end
54
54
  it 'reports the context fq name' do
55
- @smells[0].context.should == @module_name
55
+ expect(@smells[0].context).to eq(@module_name)
56
56
  end
57
57
  end
58
58
 
@@ -64,8 +64,9 @@ EOS
64
64
  def tri(pa, pb) pa - pb + @fred; end
65
65
  end
66
66
  EOS
67
- src.should smell_of(DataClump, {DataClump::OCCURRENCES_KEY => 3,
68
- DataClump::PARAMETERS_KEY => ['pa', 'pb']})
67
+ expect(src).to smell_of(DataClump,
68
+ DataClump::OCCURRENCES_KEY => 3,
69
+ DataClump::PARAMETERS_KEY => ['pa', 'pb'])
69
70
  end
70
71
 
71
72
  it 'reports 3 identical parameter sets' do
@@ -76,8 +77,9 @@ EOS
76
77
  def third(pa, pb, pc) pa - pb + @fred; end
77
78
  end
78
79
  EOS
79
- src.should smell_of(DataClump, {DataClump::OCCURRENCES_KEY => 3,
80
- DataClump::PARAMETERS_KEY => ['pa', 'pb', 'pc']})
80
+ expect(src).to smell_of(DataClump,
81
+ DataClump::OCCURRENCES_KEY => 3,
82
+ DataClump::PARAMETERS_KEY => ['pa', 'pb', 'pc'])
81
83
  end
82
84
 
83
85
  it 'reports re-ordered identical parameter sets' do
@@ -88,8 +90,9 @@ EOS
88
90
  def third(pa, pb, pc) pa - pb + @fred; end
89
91
  end
90
92
  EOS
91
- src.should smell_of(DataClump, {DataClump::OCCURRENCES_KEY => 3,
92
- DataClump::PARAMETERS_KEY => ['pa', 'pb', 'pc']})
93
+ expect(src).to smell_of(DataClump,
94
+ DataClump::OCCURRENCES_KEY => 3,
95
+ DataClump::PARAMETERS_KEY => ['pa', 'pb', 'pc'])
93
96
  end
94
97
 
95
98
  it 'counts only identical parameter sets' do
@@ -100,7 +103,7 @@ EOS
100
103
  def fc(name, windowW, windowH) end
101
104
  end
102
105
  EOS
103
- src.should_not smell_of(DataClump)
106
+ expect(src).not_to smell_of(DataClump)
104
107
  end
105
108
 
106
109
  it 'gets a real example right' do
@@ -113,7 +116,7 @@ EOS
113
116
  def c_raw_singleton (src, options) end
114
117
  end
115
118
  EOS
116
- src.should smell_of(DataClump, DataClump::OCCURRENCES_KEY => 5)
119
+ expect(src).to smell_of(DataClump, DataClump::OCCURRENCES_KEY => 5)
117
120
  end
118
121
 
119
122
  it 'correctly checks number of occurences' do
@@ -126,7 +129,7 @@ EOS
126
129
  def fe(p5, p1, p2) end
127
130
  end
128
131
  EOS
129
- src.should_not smell_of(DataClump)
132
+ expect(src).not_to smell_of(DataClump)
130
133
  end
131
134
 
132
135
  it 'detects clumps smaller than the total number of arguments' do
@@ -137,8 +140,8 @@ EOS
137
140
  def fc(p4, p1, p2) end
138
141
  end
139
142
  EOS
140
- src.should smell_of(DataClump,
141
- { DataClump::PARAMETERS_KEY => %w(p1 p2) })
143
+ expect(src).to smell_of(DataClump,
144
+ DataClump::PARAMETERS_KEY => %w(p1 p2))
142
145
  end
143
146
  end
144
147
 
@@ -22,7 +22,7 @@ end
22
22
  EOS
23
23
  ctx = CodeContext.new(nil, src.to_reek_source.syntax_tree)
24
24
  smells = @detector.examine_context(ctx)
25
- smells.length.should == 1
25
+ expect(smells.length).to eq(1)
26
26
  @warning = smells[0]
27
27
  end
28
28
 
@@ -30,38 +30,38 @@ EOS
30
30
  it_should_behave_like 'common fields set correctly'
31
31
 
32
32
  it 'reports the call' do
33
- @warning.smell[DuplicateMethodCall::CALL_KEY].should == 'other[@thing]'
33
+ expect(@warning.smell[DuplicateMethodCall::CALL_KEY]).to eq('other[@thing]')
34
34
  end
35
35
  it 'reports the correct lines' do
36
- @warning.lines.should == [2,4]
36
+ expect(@warning.lines).to eq([2, 4])
37
37
  end
38
38
  end
39
39
 
40
- context "with repeated method calls" do
40
+ context 'with repeated method calls' do
41
41
  it 'reports repeated call' do
42
42
  src = 'def double_thing() @other.thing + @other.thing end'
43
- src.should smell_of(DuplicateMethodCall, DuplicateMethodCall::CALL_KEY => '@other.thing')
43
+ expect(src).to smell_of(DuplicateMethodCall, DuplicateMethodCall::CALL_KEY => '@other.thing')
44
44
  end
45
45
  it 'reports repeated call to lvar' do
46
46
  src = 'def double_thing(other) other[@thing] + other[@thing] end'
47
- src.should smell_of(DuplicateMethodCall, DuplicateMethodCall::CALL_KEY => 'other[@thing]')
47
+ expect(src).to smell_of(DuplicateMethodCall, DuplicateMethodCall::CALL_KEY => 'other[@thing]')
48
48
  end
49
49
  it 'reports call parameters' do
50
50
  src = 'def double_thing() @other.thing(2,3) + @other.thing(2,3) end'
51
- src.should smell_of(DuplicateMethodCall, DuplicateMethodCall::CALL_KEY => '@other.thing(2, 3)')
51
+ expect(src).to smell_of(DuplicateMethodCall, DuplicateMethodCall::CALL_KEY => '@other.thing(2, 3)')
52
52
  end
53
53
  it 'should report nested calls' do
54
54
  src = 'def double_thing() @other.thing.foo + @other.thing.foo end'
55
- src.should smell_of(DuplicateMethodCall, {DuplicateMethodCall::CALL_KEY => '@other.thing'},
56
- {DuplicateMethodCall::CALL_KEY => '@other.thing.foo'})
55
+ expect(src).to smell_of(DuplicateMethodCall, { DuplicateMethodCall::CALL_KEY => '@other.thing' },
56
+ DuplicateMethodCall::CALL_KEY => '@other.thing.foo')
57
57
  end
58
58
  it 'should ignore calls to new' do
59
59
  src = 'def double_thing() @other.new + @other.new end'
60
- src.should_not smell_of(DuplicateMethodCall)
60
+ expect(src).not_to smell_of(DuplicateMethodCall)
61
61
  end
62
62
  end
63
63
 
64
- context "with repeated simple method calls" do
64
+ context 'with repeated simple method calls' do
65
65
  it 'reports no smell' do
66
66
  src = <<-EOS
67
67
  def foo
@@ -73,14 +73,58 @@ EOS
73
73
  end
74
74
  end
75
75
  EOS
76
- src.should_not smell_of(DuplicateMethodCall)
76
+ expect(src).not_to smell_of(DuplicateMethodCall)
77
+ end
78
+ end
79
+
80
+ context 'with repeated simple method calls with blocks' do
81
+ it 'reports a smell if the blocks are identical' do
82
+ src = <<-EOS
83
+ def foo
84
+ bar { baz }
85
+ bar { baz }
86
+ end
87
+ EOS
88
+ expect(src).to smell_of(DuplicateMethodCall)
89
+ end
90
+
91
+ it 'reports no smell if the blocks are different' do
92
+ src = <<-EOS
93
+ def foo
94
+ bar { baz }
95
+ bar { qux }
96
+ end
97
+ EOS
98
+ expect(src).not_to smell_of(DuplicateMethodCall)
99
+ end
100
+ end
101
+
102
+ context 'with repeated method calls with receivers with blocks' do
103
+ it 'reports a smell if the blocks are identical' do
104
+ src = <<-EOS
105
+ def foo
106
+ bar.qux { baz }
107
+ bar.qux { baz }
108
+ end
109
+ EOS
110
+ expect(src).to smell_of(DuplicateMethodCall)
111
+ end
112
+
113
+ it 'reports a smell if the blocks are different' do
114
+ src = <<-EOS
115
+ def foo
116
+ bar.qux { baz }
117
+ bar.qux { qux }
118
+ end
119
+ EOS
120
+ expect(src).to smell_of(DuplicateMethodCall)
77
121
  end
78
122
  end
79
123
 
80
124
  context 'with repeated attribute assignment' do
81
125
  it 'reports repeated assignment' do
82
126
  src = 'def double_thing(thing) @other[thing] = true; @other[thing] = true; end'
83
- src.should smell_of(DuplicateMethodCall, DuplicateMethodCall::CALL_KEY => '@other[thing] = true')
127
+ expect(src).to smell_of(DuplicateMethodCall, DuplicateMethodCall::CALL_KEY => '@other[thing] = true')
84
128
  end
85
129
  it 'does not report multi-assignments' do
86
130
  src = <<EOS
@@ -89,54 +133,54 @@ def _parse ctxt
89
133
  error, ctxt.index = @err, @err_ind
90
134
  end
91
135
  EOS
92
- src.should_not smell_of(DuplicateMethodCall)
136
+ expect(src).not_to smell_of(DuplicateMethodCall)
93
137
  end
94
138
  end
95
139
 
96
- context "non-repeated method calls" do
140
+ context 'non-repeated method calls' do
97
141
  it 'should not report similar calls' do
98
142
  src = 'def equals(other) other.thing == self.thing end'
99
- src.should_not smell_of(DuplicateMethodCall)
143
+ expect(src).not_to smell_of(DuplicateMethodCall)
100
144
  end
101
145
  it 'should respect call parameters' do
102
146
  src = 'def double_thing() @other.thing(3) + @other.thing(2) end'
103
- src.should_not smell_of(DuplicateMethodCall)
147
+ expect(src).not_to smell_of(DuplicateMethodCall)
104
148
  end
105
149
  end
106
150
 
107
- context "allowing up to 3 calls" do
151
+ context 'allowing up to 3 calls' do
108
152
  before :each do
109
- @config = {DuplicateMethodCall::MAX_ALLOWED_CALLS_KEY => 3}
153
+ @config = { DuplicateMethodCall::MAX_ALLOWED_CALLS_KEY => 3 }
110
154
  end
111
155
  it 'does not report double calls' do
112
156
  src = 'def double_thing() @other.thing + @other.thing end'
113
- src.should_not smell_of(DuplicateMethodCall).with_config(@config)
157
+ expect(src).not_to smell_of(DuplicateMethodCall).with_config(@config)
114
158
  end
115
159
  it 'does not report triple calls' do
116
160
  src = 'def double_thing() @other.thing + @other.thing + @other.thing end'
117
- src.should_not smell_of(DuplicateMethodCall).with_config(@config)
161
+ expect(src).not_to smell_of(DuplicateMethodCall).with_config(@config)
118
162
  end
119
163
  it 'reports quadruple calls' do
120
164
  src = 'def double_thing() @other.thing + @other.thing + @other.thing + @other.thing end'
121
- src.should smell_of(DuplicateMethodCall, {DuplicateMethodCall::CALL_KEY => '@other.thing', DuplicateMethodCall::OCCURRENCES_KEY => 4}).with_config(@config)
165
+ expect(src).to smell_of(DuplicateMethodCall, DuplicateMethodCall::CALL_KEY => '@other.thing', DuplicateMethodCall::OCCURRENCES_KEY => 4).with_config(@config)
122
166
  end
123
167
  end
124
168
 
125
- context "allowing calls to some methods" do
169
+ context 'allowing calls to some methods' do
126
170
  before :each do
127
- @config = {DuplicateMethodCall::ALLOW_CALLS_KEY => ['@some.thing',/puts/]}
171
+ @config = { DuplicateMethodCall::ALLOW_CALLS_KEY => ['@some.thing', /puts/] }
128
172
  end
129
173
  it 'does not report calls to some methods' do
130
174
  src = 'def double_some_thing() @some.thing + @some.thing end'
131
- src.should_not smell_of(DuplicateMethodCall).with_config(@config)
175
+ expect(src).not_to smell_of(DuplicateMethodCall).with_config(@config)
132
176
  end
133
177
  it 'reports calls to other methods' do
134
178
  src = 'def double_other_thing() @other.thing + @other.thing end'
135
- src.should smell_of(DuplicateMethodCall, {DuplicateMethodCall::CALL_KEY => '@other.thing'}).with_config(@config)
179
+ expect(src).to smell_of(DuplicateMethodCall, DuplicateMethodCall::CALL_KEY => '@other.thing').with_config(@config)
136
180
  end
137
181
  it 'does not report calls to methods specifed with a regular expression' do
138
182
  src = 'def double_puts() puts @other.thing; puts @other.thing end'
139
- src.should smell_of(DuplicateMethodCall, {DuplicateMethodCall::CALL_KEY => '@other.thing'}).with_config(@config)
183
+ expect(src).to smell_of(DuplicateMethodCall, DuplicateMethodCall::CALL_KEY => '@other.thing').with_config(@config)
140
184
  end
141
185
  end
142
186
  end
@@ -8,40 +8,40 @@ include Reek::Smells
8
8
  describe FeatureEnvy do
9
9
  context 'with no smell' do
10
10
  it 'should not report use of self' do
11
- 'def simple() self.to_s + self.to_i end'.should_not reek
11
+ expect('def simple() self.to_s + self.to_i end').not_to reek
12
12
  end
13
13
  it 'should not report vcall with no argument' do
14
- 'def simple() func; end'.should_not reek
14
+ expect('def simple() func; end').not_to reek
15
15
  end
16
16
  it 'should not report single use' do
17
- 'def no_envy(arga) arga.barg(@item) end'.should_not reek
17
+ expect('def no_envy(arga) arga.barg(@item) end').not_to reek
18
18
  end
19
19
  it 'should not report return value' do
20
- 'def no_envy(arga) arga.barg(@item); arga end'.should_not reek
20
+ expect('def no_envy(arga) arga.barg(@item); arga end').not_to reek
21
21
  end
22
22
  it 'should ignore global variables' do
23
- 'def no_envy() $s2.to_a; $s2[@item] end'.should_not reek
23
+ expect('def no_envy() $s2.to_a; $s2[@item] end').not_to reek
24
24
  end
25
25
  it 'should not report class methods' do
26
- 'def simple() self.class.new.flatten_merge(self) end'.should_not reek
26
+ expect('def simple() self.class.new.flatten_merge(self) end').not_to reek
27
27
  end
28
28
  it 'should not report single use of an ivar' do
29
- 'def no_envy() @item.to_a end'.should_not reek
29
+ expect('def no_envy() @item.to_a end').not_to reek
30
30
  end
31
31
  it 'should not report returning an ivar' do
32
- 'def no_envy() @item.to_a; @item end'.should_not reek
32
+ expect('def no_envy() @item.to_a; @item end').not_to reek
33
33
  end
34
34
  it 'should not report ivar usage in a parameter' do
35
- 'def no_envy() @item.price + tax(@item) - savings(@item) end'.should_not reek
35
+ expect('def no_envy() @item.price + tax(@item) - savings(@item) end').not_to reek
36
36
  end
37
37
  it 'should not report single use of an lvar' do
38
- 'def no_envy() lv = @item; lv.to_a end'.should_not reek
38
+ expect('def no_envy() lv = @item; lv.to_a end').not_to reek
39
39
  end
40
40
  it 'should not report returning an lvar' do
41
- 'def no_envy() lv = @item; lv.to_a; lv end'.should_not reek
41
+ expect('def no_envy() lv = @item; lv.to_a; lv end').not_to reek
42
42
  end
43
43
  it 'ignores lvar usage in a parameter' do
44
- 'def no_envy() lv = @item; lv.price + tax(lv) - savings(lv); end'.should_not reek
44
+ expect('def no_envy() lv = @item; lv.price + tax(lv) - savings(lv); end').not_to reek
45
45
  end
46
46
  it 'ignores multiple ivars' do
47
47
  src = <<EOS
@@ -52,7 +52,7 @@ describe FeatureEnvy do
52
52
  @nother.d
53
53
  end
54
54
  EOS
55
- src.should_not reek
55
+ expect(src).not_to reek
56
56
  #
57
57
  # def other.func(me)
58
58
  # a
@@ -66,7 +66,7 @@ EOS
66
66
 
67
67
  context 'with 2 calls to a parameter' do
68
68
  it 'reports the smell' do
69
- 'def envy(arga) arga.b(arga) + arga.c(@fred) end'.should reek_only_of(:FeatureEnvy, /arga/)
69
+ expect('def envy(arga) arga.b(arga) + arga.c(@fred) end').to reek_only_of(:FeatureEnvy, /arga/)
70
70
  end
71
71
  end
72
72
 
@@ -80,7 +80,7 @@ def total_envy
80
80
  total *= 1.15
81
81
  end
82
82
  EOS
83
- src.should reek_only_of(:FeatureEnvy, /total/)
83
+ expect(src).to reek_only_of(:FeatureEnvy, /total/)
84
84
  end
85
85
 
86
86
  it 'should report multiple affinities' do
@@ -92,20 +92,20 @@ def total_envy
92
92
  total += fred.tax
93
93
  end
94
94
  EOS
95
- src.should reek_of(:FeatureEnvy, /total/)
96
- src.should reek_of(:FeatureEnvy, /fred/)
95
+ expect(src).to reek_of(:FeatureEnvy, /total/)
96
+ expect(src).to reek_of(:FeatureEnvy, /fred/)
97
97
  end
98
98
 
99
99
  it 'should not be fooled by duplication' do
100
- 'def feed(thing) @cow.feed_to(thing.pig); @duck.feed_to(thing.pig) end'.should reek_only_of(:Duplication, /thing.pig/)
100
+ expect('def feed(thing) @cow.feed_to(thing.pig); @duck.feed_to(thing.pig) end').to reek_only_of(:Duplication, /thing.pig/)
101
101
  end
102
102
 
103
103
  it 'should count local calls' do
104
- 'def feed(thing) cow.feed_to(thing.pig); duck.feed_to(thing.pig) end'.should reek_only_of(:Duplication, /thing.pig/)
104
+ expect('def feed(thing) cow.feed_to(thing.pig); duck.feed_to(thing.pig) end').to reek_only_of(:Duplication, /thing.pig/)
105
105
  end
106
106
 
107
107
  it 'should report many calls to lvar' do
108
- 'def envy() lv = @item; lv.price + lv.tax; end'.should reek_only_of(:FeatureEnvy, /lv/)
108
+ expect('def envy() lv = @item; lv.price + lv.tax; end').to reek_only_of(:FeatureEnvy, /lv/)
109
109
  #
110
110
  # def moved_version
111
111
  # price + tax
@@ -117,7 +117,7 @@ EOS
117
117
  end
118
118
 
119
119
  it 'ignores frequent use of a call' do
120
- 'def func() other.a; other.b; nother.c end'.should_not reek_of(:FeatureEnvy)
120
+ expect('def func() other.a; other.b; nother.c end').not_to reek_of(:FeatureEnvy)
121
121
  end
122
122
 
123
123
  it 'counts self references correctly' do
@@ -130,7 +130,7 @@ def adopt(other)
130
130
  self
131
131
  end
132
132
  EOS
133
- src.should_not reek
133
+ expect(src).not_to reek
134
134
  end
135
135
  end
136
136
 
@@ -147,7 +147,7 @@ def report
147
147
  @report
148
148
  end
149
149
  EOS
150
- ruby.should_not reek
150
+ expect(ruby).not_to reek
151
151
  end
152
152
 
153
153
  it 'interprets << correctly' do
@@ -161,7 +161,7 @@ def report_on(report)
161
161
  end
162
162
  EOS
163
163
 
164
- ruby.should_not reek
164
+ expect(ruby).not_to reek
165
165
  end
166
166
  end
167
167
 
@@ -190,26 +190,26 @@ EOS
190
190
  @smells = @detector.examine_context(@mctx)
191
191
  end
192
192
  it 'reports only that smell' do
193
- @smells.length.should == 1
193
+ expect(@smells.length).to eq(1)
194
194
  end
195
195
  it 'reports the source' do
196
- @smells[0].source.should == @source_name
196
+ expect(@smells[0].source).to eq(@source_name)
197
197
  end
198
198
  it 'reports the class' do
199
- @smells[0].smell_class.should == FeatureEnvy::SMELL_CLASS
199
+ expect(@smells[0].smell_class).to eq(FeatureEnvy::SMELL_CLASS)
200
200
  end
201
201
  it 'reports the subclass' do
202
- @smells[0].subclass.should == FeatureEnvy::SMELL_SUBCLASS
202
+ expect(@smells[0].subclass).to eq(FeatureEnvy::SMELL_SUBCLASS)
203
203
  end
204
204
  it 'reports the envious receiver' do
205
- @smells[0].smell[FeatureEnvy::RECEIVER_KEY].should == @receiver
205
+ expect(@smells[0].smell[FeatureEnvy::RECEIVER_KEY]).to eq(@receiver)
206
206
  end
207
207
  it 'reports the number of references' do
208
- @smells[0].smell[FeatureEnvy::REFERENCES_KEY].should == 3
208
+ expect(@smells[0].smell[FeatureEnvy::REFERENCES_KEY]).to eq(3)
209
209
  end
210
210
  it 'reports the referring lines' do
211
- pending
212
- @smells[0].lines.should == [2, 4, 5]
211
+ skip
212
+ expect(@smells[0].lines).to eq([2, 4, 5])
213
213
  end
214
214
  end
215
215
  end