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
@@ -1,63 +1,130 @@
1
1
  require 'spec_helper'
2
2
  require 'reek/examiner'
3
- require 'reek/cli/report'
3
+ require 'reek/cli/report/report'
4
+ require 'reek/cli/report/formatter'
5
+ require 'reek/cli/report/strategy'
4
6
  require 'rainbow'
5
7
  require 'stringio'
6
8
 
7
9
  include Reek
8
10
  include Reek::Cli
9
11
 
10
- describe QuietReport, " when empty" do
12
+ def capture_output_stream
13
+ $stdout = StringIO.new
14
+ yield
15
+ $stdout.string
16
+ ensure
17
+ $stdout = STDOUT
18
+ end
19
+
20
+ def report_options
21
+ {
22
+ warning_formatter: Report::SimpleWarningFormatter,
23
+ report_formatter: Report::Formatter,
24
+ strategy: Report::Strategy::Quiet
25
+ }
26
+ end
27
+
28
+ describe Report::TextReport, ' when empty' do
11
29
  context 'empty source' do
30
+ let(:examiner) { Examiner.new('') }
31
+
32
+ def report(obj)
33
+ obj.add_examiner examiner
34
+ end
35
+
12
36
  it 'has an empty quiet_report' do
13
- examiner = Examiner.new('')
14
- qr = QuietReport.new
15
- qr.add_examiner(examiner)
16
- qr.gather_results.should == []
37
+ tr = Report::TextReport.new
38
+ tr.add_examiner(examiner)
39
+ expect { tr.show }.to_not output.to_stdout
40
+ end
41
+
42
+ context 'when output format is html' do
43
+ it 'has the text 0 total warnings' do
44
+ html_report = report(Report::HtmlReport.new(report_options))
45
+ html_report.show
46
+
47
+ file = File.expand_path('../../../../reek.html', __FILE__)
48
+ text = File.read(file)
49
+ File.delete(file)
50
+
51
+ expect(text).to include('0 total warnings')
52
+ end
53
+ end
54
+
55
+ context 'when output format is yaml' do
56
+ it 'prints empty yaml' do
57
+ yaml_report = report(Report::YamlReport.new(report_options))
58
+ output = capture_output_stream { yaml_report.show }
59
+ expect(output).to match(/^--- \[\]\n.*$/)
60
+ end
61
+ end
62
+
63
+ context 'when output format is text' do
64
+ it 'prints nothing' do
65
+ text_report = report(Report::TextReport.new)
66
+ expect { text_report.show }.to_not output.to_stdout
67
+ end
17
68
  end
18
69
  end
19
70
 
20
71
  context 'with a couple of smells' do
21
72
  before :each do
22
73
  @examiner = Examiner.new('def simple(a) a[3] end')
23
- @rpt = QuietReport.new(SimpleWarningFormatter, ReportFormatter, false, :text)
74
+ @rpt = Report::TextReport.new report_options
24
75
  end
25
76
 
26
77
  context 'with colors disabled' do
27
78
  before :each do
28
79
  Rainbow.enabled = false
29
- @result = @rpt.add_examiner(@examiner).gather_results.first
80
+ @result = @rpt.add_examiner(@examiner).smells.first
30
81
  end
31
82
 
32
83
  it 'has a header' do
33
- @result.should match('string -- 2 warnings')
84
+ expect(@result).to match('string -- 2 warnings')
34
85
  end
35
86
 
36
87
  it 'should mention every smell name' do
37
- @result.should match('[UncommunicativeParameterName]')
38
- @result.should match('[Feature Envy]')
88
+ expect(@result).to include('UncommunicativeParameterName')
89
+ expect(@result).to include('FeatureEnvy')
39
90
  end
40
91
  end
41
92
 
42
93
  context 'with colors enabled' do
43
94
  before :each do
44
95
  Rainbow.enabled = true
45
- @rpt.add_examiner(Examiner.new('def simple(a) a[3] end'))
46
- @rpt.add_examiner(Examiner.new('def simple(a) a[3] end'))
47
- @result = @rpt.gather_results
48
96
  end
49
97
 
50
- it 'has a header in color' do
51
- @result.first.should start_with "\e[36mstring -- \e[0m\e[33m2 warning\e[0m\e[33ms\e[0m"
98
+ context 'with non smelly files' do
99
+ before :each do
100
+ Rainbow.enabled = true
101
+ @rpt.add_examiner(Examiner.new('def simple() puts "a" end'))
102
+ @rpt.add_examiner(Examiner.new('def simple() puts "a" end'))
103
+ @result = @rpt.smells
104
+ end
105
+
106
+ it 'has a footer in color' do
107
+ output = capture_output_stream { @rpt.show }
108
+ expect(output).to end_with "\e[32m0 total warnings\n\e[0m"
109
+ end
52
110
  end
53
111
 
54
- it 'has a footer in color' do
55
- stdout = StringIO.new
56
- $stdout = stdout
57
- @rpt.show
58
- $stdout = STDOUT
112
+ context 'with smelly files' do
113
+ before :each do
114
+ Rainbow.enabled = true
115
+ @rpt.add_examiner(Examiner.new('def simple(a) a[3] end'))
116
+ @rpt.add_examiner(Examiner.new('def simple(a) a[3] end'))
117
+ @result = @rpt.smells
118
+ end
119
+
120
+ it 'has a header in color' do
121
+ expect(@result.first).to start_with "\e[36mstring -- \e[0m\e[33m2 warning\e[0m\e[33ms\e[0m"
122
+ end
59
123
 
60
- stdout.string.should end_with "\e[31m4 total warnings\n\e[0m"
124
+ it 'has a footer in color' do
125
+ output = capture_output_stream { @rpt.show }
126
+ expect(output).to end_with "\e[31m4 total warnings\n\e[0m"
127
+ end
61
128
  end
62
129
  end
63
130
  end
@@ -6,24 +6,26 @@ include Reek::Cli
6
6
 
7
7
  describe VersionCommand do
8
8
  before :each do
9
- @text = 'Piece of interesting text'
10
- @cmd = VersionCommand.new(@text)
9
+ @program_name = 'the_name_of_the_program'
10
+ @parser = double('parser')
11
+ expect(@parser).to receive(:program_name).and_return @program_name
12
+ @cmd = VersionCommand.new(@parser)
11
13
  @view = double('view').as_null_object
12
- @view.should_not_receive(:report_smells)
13
14
  end
14
15
 
15
16
  it 'displays the text on the view' do
16
- @view.should_receive(:output).with(/#{@text}/)
17
+ expect(@view).to receive(:output).with(/#{@program_name}/)
17
18
  @cmd.execute(@view)
18
19
  end
19
20
 
20
21
  it 'displays the Reek version on the view' do
21
- @view.should_receive(:output).with(/#{Reek::VERSION}/)
22
+ expect(@view).to receive(:output).with(/#{Reek::VERSION}/)
22
23
  @cmd.execute(@view)
23
24
  end
24
25
 
25
26
  it 'tells the view it succeeded' do
26
- @view.should_receive(:report_success)
27
+ expect(@view).to receive(:report_success)
28
+ expect(@view).not_to receive(:report_smells)
27
29
  @cmd.execute(@view)
28
30
  end
29
31
  end
@@ -17,19 +17,19 @@ describe CodeContext do
17
17
  @ctx = CodeContext.new(nil, @exp)
18
18
  end
19
19
  it 'gets its short name from the exp' do
20
- @ctx.name.should == @exp_name
20
+ expect(@ctx.name).to eq(@exp_name)
21
21
  end
22
22
  it 'does not match an empty list' do
23
- @ctx.matches?([]).should == false
23
+ expect(@ctx.matches?([])).to eq(false)
24
24
  end
25
25
  it 'does not match when its own short name is not given' do
26
- @ctx.matches?(['banana']).should == false
26
+ expect(@ctx.matches?(['banana'])).to eq(false)
27
27
  end
28
28
  it 'recognises its own short name' do
29
- @ctx.matches?(['banana', @exp_name]).should == true
29
+ expect(@ctx.matches?(['banana', @exp_name])).to eq(true)
30
30
  end
31
31
  it 'recognises its short name as a regex' do
32
- @ctx.matches?([/banana/, /#{@exp_name}/]).should == true
32
+ expect(@ctx.matches?([/banana/, /#{@exp_name}/])).to eq(true)
33
33
  end
34
34
 
35
35
  context 'when there is an outer' do
@@ -41,13 +41,13 @@ describe CodeContext do
41
41
  @ctx = CodeContext.new(outer, @exp)
42
42
  end
43
43
  it 'creates the correct full name' do
44
- @ctx.full_name.should == "#{@full_name}"
44
+ expect(@ctx.full_name).to eq("#{@full_name}")
45
45
  end
46
46
  it 'recognises its own full name' do
47
- @ctx.matches?(['banana', @full_name]).should == true
47
+ expect(@ctx.matches?(['banana', @full_name])).to eq(true)
48
48
  end
49
49
  it 'recognises its full name as a regex' do
50
- @ctx.matches?([/banana/, /#{@full_name}/]).should == true
50
+ expect(@ctx.matches?([/banana/, /#{@full_name}/])).to eq(true)
51
51
  end
52
52
  end
53
53
  end
@@ -58,7 +58,7 @@ describe CodeContext do
58
58
  def stop.bananas(arg1, arg2) arg1 + arg2 + 43 end
59
59
  element = ModuleContext.new(stop, ast(:module, :mod, nil))
60
60
  element = MethodContext.new(element, ast(:defn, :bad))
61
- element.bananas(17, -5).should == 55
61
+ expect(element.bananas(17, -5)).to eq(55)
62
62
  end
63
63
  end
64
64
 
@@ -71,20 +71,20 @@ describe CodeContext do
71
71
  @ctx = CodeContext.new(nil, ast)
72
72
  end
73
73
  it 'yields no calls' do
74
- @ctx.each_node(:call, []) {|exp| raise "#{exp} yielded by empty module!"}
74
+ @ctx.each_node(:call, []) { |exp| raise "#{exp} yielded by empty module!" }
75
75
  end
76
76
  it 'yields one module' do
77
77
  mods = 0
78
- @ctx.each_node(:module, []) {|exp| mods += 1}
79
- mods.should == 1
78
+ @ctx.each_node(:module, []) { |_exp| mods += 1 }
79
+ expect(mods).to eq(1)
80
80
  end
81
81
  it "yields the module's full AST" do
82
- @ctx.each_node(:module, []) {|exp| exp[1].should == @module_name.to_sym}
82
+ @ctx.each_node(:module, []) { |exp| expect(exp[1]).to eq(@module_name.to_sym) }
83
83
  end
84
84
 
85
85
  context 'with no block' do
86
86
  it 'returns an empty array of ifs' do
87
- @ctx.each_node(:if, []).should be_empty
87
+ expect(@ctx.each_node(:if, [])).to be_empty
88
88
  end
89
89
  end
90
90
  end
@@ -98,24 +98,24 @@ describe CodeContext do
98
98
  @ctx = CodeContext.new(nil, ast)
99
99
  end
100
100
  it 'yields no ifs' do
101
- @ctx.each_node(:if, []) {|exp| raise "#{exp} yielded by empty module!"}
101
+ @ctx.each_node(:if, []) { |exp| raise "#{exp} yielded by empty module!" }
102
102
  end
103
103
  it 'yields one module' do
104
- @ctx.each_node(:module, []).length.should == 1
104
+ expect(@ctx.each_node(:module, []).length).to eq(1)
105
105
  end
106
106
  it "yields the module's full AST" do
107
- @ctx.each_node(:module, []) {|exp| exp[1].should == @module_name.to_sym}
107
+ @ctx.each_node(:module, []) { |exp| expect(exp[1]).to eq(@module_name.to_sym) }
108
108
  end
109
109
  it 'yields one method' do
110
- @ctx.each_node(:defn, []).length.should == 1
110
+ expect(@ctx.each_node(:defn, []).length).to eq(1)
111
111
  end
112
112
  it "yields the method's full AST" do
113
- @ctx.each_node(:defn, []) {|exp| exp[1].should == @method_name.to_sym}
113
+ @ctx.each_node(:defn, []) { |exp| expect(exp[1]).to eq(@method_name.to_sym) }
114
114
  end
115
115
 
116
116
  context 'pruning the traversal' do
117
117
  it 'ignores the call inside the method' do
118
- @ctx.each_node(:call, [:defn]).should be_empty
118
+ expect(@ctx.each_node(:call, [:defn])).to be_empty
119
119
  end
120
120
  end
121
121
  end
@@ -139,7 +139,7 @@ EOS
139
139
 
140
140
  ast = src.to_reek_source.syntax_tree
141
141
  ctx = CodeContext.new(nil, ast)
142
- ctx.each_node(:if, []).length.should == 3
142
+ expect(ctx.each_node(:if, []).length).to eq(3)
143
143
  end
144
144
  end
145
145
 
@@ -156,8 +156,7 @@ EOS
156
156
  end
157
157
 
158
158
  it 'gets its configuration from the exp comments' do
159
- ctx.config_for(sniffer).should == {
160
- 'allow_calls' => [ 'puts' ] }
159
+ expect(ctx.config_for(sniffer)).to eq('allow_calls' => ['puts'])
161
160
  end
162
161
 
163
162
  context 'when there is an outer' do
@@ -165,12 +164,12 @@ EOS
165
164
 
166
165
  before :each do
167
166
  allow(outer).to receive(:config_for).with(sniffer).and_return(
168
- { 'max_calls' => 2 })
167
+ 'max_calls' => 2)
169
168
  end
170
169
 
171
170
  it 'merges the outer config with its own configuration' do
172
- ctx.config_for(sniffer).should == { 'allow_calls' => [ 'puts' ],
173
- 'max_calls' => 2 }
171
+ expect(ctx.config_for(sniffer)).to eq('allow_calls' => ['puts'],
172
+ 'max_calls' => 2)
174
173
  end
175
174
  end
176
175
  end
@@ -3,20 +3,20 @@ require 'reek/core/code_parser'
3
3
 
4
4
  include Reek::Core
5
5
 
6
- describe CodeParser, "with no method definitions" do
6
+ describe CodeParser, 'with no method definitions' do
7
7
  it 'reports no problems for empty source code' do
8
- ''.should_not reek
8
+ expect('').not_to reek
9
9
  end
10
10
  it 'reports no problems for empty class' do
11
- '# clean class for testing purposes
12
- class Fred; end'.should_not reek
11
+ expect('# clean class for testing purposes
12
+ class Fred; end').not_to reek
13
13
  end
14
14
  end
15
15
 
16
16
  describe CodeParser, 'with a global method definition' do
17
17
  it 'reports no problems for simple method' do
18
18
  src = 'def Outermost::fred() true; end'
19
- src.should_not reek
19
+ expect(src).not_to reek
20
20
  end
21
21
  end
22
22
 
@@ -31,6 +31,6 @@ def values(*args)
31
31
  self
32
32
  end
33
33
  EOS
34
- src.should_not reek
34
+ expect(src).not_to reek
35
35
  end
36
36
  end
@@ -7,41 +7,41 @@ include Reek::Core
7
7
  describe MethodContext, 'matching' do
8
8
  before :each do
9
9
  exp = double('exp').as_null_object
10
- exp.should_receive(:full_name).at_least(:once).and_return('mod')
10
+ expect(exp).to receive(:full_name).at_least(:once).and_return('mod')
11
11
  @element = MethodContext.new(StopContext.new, exp)
12
12
  end
13
13
 
14
14
  it 'should recognise itself in a collection of names' do
15
- @element.matches?(['banana', 'mod']).should == true
16
- @element.matches?(['banana']).should == false
15
+ expect(@element.matches?(['banana', 'mod'])).to eq(true)
16
+ expect(@element.matches?(['banana'])).to eq(false)
17
17
  end
18
18
 
19
19
  it 'should recognise itself in a collection of REs' do
20
- @element.matches?([/banana/, /mod/]).should == true
21
- @element.matches?([/banana/]).should == false
20
+ expect(@element.matches?([/banana/, /mod/])).to eq(true)
21
+ expect(@element.matches?([/banana/])).to eq(false)
22
22
  end
23
23
  end
24
24
 
25
25
  describe MethodContext do
26
26
  it 'should record ivars as refs to self' do
27
27
  mctx = MethodContext.new(StopContext.new, ast(:defn, :feed))
28
- mctx.envious_receivers.should == []
28
+ expect(mctx.envious_receivers).to eq([])
29
29
  mctx.record_call_to(ast(:call, s(:ivar, :@cow), :feed_to))
30
- mctx.envious_receivers.should == []
30
+ expect(mctx.envious_receivers).to eq([])
31
31
  end
32
32
 
33
33
  it 'should count calls to self' do
34
34
  mctx = MethodContext.new(StopContext.new, ast(:defn, :equals))
35
35
  mctx.refs.record_reference_to([:lvar, :other])
36
36
  mctx.record_call_to(ast(:call, s(:self), :thing))
37
- mctx.envious_receivers.should be_empty
37
+ expect(mctx.envious_receivers).to be_empty
38
38
  end
39
39
 
40
40
  it 'should recognise a call on self' do
41
41
  mc = MethodContext.new(StopContext.new, s(:defn, :deep))
42
42
  mc.record_call_to(ast(:call, s(:lvar, :text), :each, s(:arglist)))
43
43
  mc.record_call_to(ast(:call, nil, :shelve, s(:arglist)))
44
- mc.envious_receivers.should be_empty
44
+ expect(mc.envious_receivers).to be_empty
45
45
  end
46
46
  end
47
47
 
@@ -49,40 +49,40 @@ describe MethodParameters, 'default assignments' do
49
49
  def assignments_from(src)
50
50
  exp = src.to_reek_source.syntax_tree
51
51
  ctx = MethodContext.new(StopContext.new, exp)
52
- return ctx.parameters.default_assignments
52
+ ctx.parameters.default_assignments
53
53
  end
54
54
 
55
55
  context 'with no defaults' do
56
56
  it 'returns an empty hash' do
57
57
  src = 'def meth(arga, argb, &blk) end'
58
- assignments_from(src).should be_empty
58
+ expect(assignments_from(src)).to be_empty
59
59
  end
60
60
  end
61
61
 
62
62
  context 'with 1 default' do
63
63
  before :each do
64
- src = "def meth(arga, argb=456, &blk) end"
64
+ src = 'def meth(arga, argb=456, &blk) end'
65
65
  @defaults = assignments_from(src)
66
66
  end
67
67
  it 'returns the param-value pair' do
68
- @defaults[0].should == s(:argb, s(:lit, 456))
68
+ expect(@defaults[0]).to eq(s(:argb, s(:lit, 456)))
69
69
  end
70
70
  it 'returns the nothing else' do
71
- @defaults.length.should == 1
71
+ expect(@defaults.length).to eq(1)
72
72
  end
73
73
  end
74
74
 
75
75
  context 'with 2 defaults' do
76
76
  before :each do
77
- src = "def meth(arga=123, argb=456, &blk) end"
77
+ src = 'def meth(arga=123, argb=456, &blk) end'
78
78
  @defaults = assignments_from(src)
79
79
  end
80
80
  it 'returns both param-value pairs' do
81
- @defaults[0].should == s(:arga, s(:lit, 123))
82
- @defaults[1].should == s(:argb, s(:lit, 456))
81
+ expect(@defaults[0]).to eq(s(:arga, s(:lit, 123)))
82
+ expect(@defaults[1]).to eq(s(:argb, s(:lit, 456)))
83
83
  end
84
84
  it 'returns nothing else' do
85
- @defaults.length.should == 2
85
+ expect(@defaults.length).to eq(2)
86
86
  end
87
87
  end
88
88
  end