reek 1.2.3 → 1.2.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. data/History.txt +9 -1
  2. data/features/options.feature +1 -9
  3. data/features/samples.feature +7 -2
  4. data/features/step_definitions/reek_steps.rb +3 -3
  5. data/lib/reek.rb +1 -1
  6. data/lib/reek/adapters/application.rb +22 -27
  7. data/lib/reek/adapters/command_line.rb +41 -42
  8. data/lib/reek/adapters/report.rb +30 -23
  9. data/lib/reek/adapters/spec.rb +1 -1
  10. data/lib/reek/code_context.rb +6 -2
  11. data/lib/reek/code_parser.rb +3 -7
  12. data/lib/reek/detector_stack.rb +2 -4
  13. data/lib/reek/help_command.rb +14 -0
  14. data/lib/reek/masking_collection.rb +33 -0
  15. data/lib/reek/method_context.rb +18 -6
  16. data/lib/reek/module_context.rb +0 -13
  17. data/lib/reek/reek_command.rb +28 -0
  18. data/lib/reek/singleton_method_context.rb +1 -1
  19. data/lib/reek/smell_warning.rb +5 -3
  20. data/lib/reek/smells/attribute.rb +17 -1
  21. data/lib/reek/smells/class_variable.rb +1 -1
  22. data/lib/reek/smells/control_couple.rb +13 -10
  23. data/lib/reek/smells/large_class.rb +1 -1
  24. data/lib/reek/smells/long_method.rb +0 -2
  25. data/lib/reek/smells/simulated_polymorphism.rb +2 -2
  26. data/lib/reek/sniffer.rb +1 -3
  27. data/lib/reek/tree_dresser.rb +35 -23
  28. data/lib/reek/version_command.rb +14 -0
  29. data/reek.gemspec +3 -3
  30. data/spec/reek/adapters/report_spec.rb +8 -8
  31. data/spec/reek/adapters/should_reek_of_spec.rb +1 -1
  32. data/spec/reek/adapters/should_reek_only_of_spec.rb +2 -2
  33. data/spec/reek/adapters/should_reek_spec.rb +3 -3
  34. data/spec/reek/code_context_spec.rb +11 -11
  35. data/spec/reek/code_parser_spec.rb +0 -88
  36. data/spec/reek/help_command_spec.rb +24 -0
  37. data/spec/reek/masking_collection_spec.rb +236 -0
  38. data/spec/reek/method_context_spec.rb +43 -1
  39. data/spec/reek/reek_command_spec.rb +45 -0
  40. data/spec/reek/smell_warning_spec.rb +12 -4
  41. data/spec/reek/smells/attribute_spec.rb +79 -7
  42. data/spec/reek/smells/control_couple_spec.rb +40 -11
  43. data/spec/reek/smells/long_parameter_list_spec.rb +1 -1
  44. data/spec/reek/smells/smell_detector_spec.rb +0 -17
  45. data/spec/reek/tree_dresser_spec.rb +20 -0
  46. data/spec/reek/version_command_spec.rb +29 -0
  47. metadata +11 -2
@@ -7,7 +7,7 @@ include Reek
7
7
 
8
8
  describe MethodContext, 'matching' do
9
9
  before :each do
10
- @element = MethodContext.new(StopContext.new, s(0, :mod), s(:module, :mod, nil))
10
+ @element = MethodContext.new(StopContext.new, s(0, :mod))
11
11
  end
12
12
 
13
13
  it 'should recognise itself in a collection of names' do
@@ -64,3 +64,45 @@ describe MethodContext do
64
64
  mc.envious_receivers.should be_empty
65
65
  end
66
66
  end
67
+
68
+ describe MethodParameters, 'default assignments' do
69
+ def assignments_from(src)
70
+ exp = src.to_reek_source.syntax_tree
71
+ ctx = MethodContext.new(StopContext.new, exp)
72
+ return ctx.parameters.default_assignments
73
+ end
74
+
75
+ context 'with no defaults' do
76
+ it 'returns an empty hash' do
77
+ src = 'def meth(arga, argb, &blk) end'
78
+ assignments_from(src).should be_empty
79
+ end
80
+ end
81
+
82
+ context 'with 1 default' do
83
+ before :each do
84
+ src = "def meth(arga, argb=456, &blk) end"
85
+ @defaults = assignments_from(src)
86
+ end
87
+ it 'returns the param-value pair' do
88
+ @defaults[:argb].should == s(:lit, 456)
89
+ end
90
+ it 'returns the nothing else' do
91
+ @defaults.length.should == 1
92
+ end
93
+ end
94
+
95
+ context 'with 2 defaults' do
96
+ before :each do
97
+ src = "def meth(arga=123, argb=456, &blk) end"
98
+ @defaults = assignments_from(src)
99
+ end
100
+ it 'returns both param-value pairs' do
101
+ @defaults[:arga].should == s(:lit, 123)
102
+ @defaults[:argb].should == s(:lit, 456)
103
+ end
104
+ it 'returns nothing else' do
105
+ @defaults.length.should == 2
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,45 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper.rb'
2
+
3
+ require 'reek/reek_command'
4
+
5
+ include Reek
6
+
7
+ describe ReekCommand do
8
+ before :each do
9
+ @view = mock('view', :null_object => true)
10
+ end
11
+
12
+ context 'with smells' do
13
+ before :each do
14
+ src = 'def x(); end'
15
+ @cmd = ReekCommand.new(src, QuietReport, false)
16
+ end
17
+
18
+ it 'displays the correct text on the view' do
19
+ @view.should_receive(:output).with(/Uncommunicative Name/)
20
+ @cmd.execute(@view)
21
+ end
22
+
23
+ it 'tells the view it succeeded' do
24
+ @view.should_receive(:report_smells)
25
+ @cmd.execute(@view)
26
+ end
27
+ end
28
+
29
+ context 'with no smells' do
30
+ before :each do
31
+ src = 'def clean(); end'
32
+ @cmd = ReekCommand.new(src, QuietReport, false)
33
+ end
34
+
35
+ it 'displays nothing on the view' do
36
+ @view.should_receive(:output).with('')
37
+ @cmd.execute(@view)
38
+ end
39
+
40
+ it 'tells the view it succeeded' do
41
+ @view.should_receive(:report_success)
42
+ @cmd.execute(@view)
43
+ end
44
+ end
45
+ end
@@ -22,6 +22,10 @@ describe SmellWarning, 'equality' do
22
22
  it 'should compare equal when using <=>' do
23
23
  (@first <=> @second).should == 0
24
24
  end
25
+ it 'matches using eql?' do
26
+ @first.should eql(@second)
27
+ @second.should eql(@first)
28
+ end
25
29
  end
26
30
 
27
31
  shared_examples_for 'first sorts ahead of second' do
@@ -34,12 +38,16 @@ describe SmellWarning, 'equality' do
34
38
  it 'sort correctly' do
35
39
  (@first <=> @second).should be < 0
36
40
  end
41
+ it 'does not match using eql?' do
42
+ @first.should_not eql(@second)
43
+ @second.should_not eql(@first)
44
+ end
37
45
  end
38
46
 
39
47
  context 'smells differing only by detector' do
40
48
  before :each do
41
- @first = SmellWarning.new(Smells::Duplication.new, "self", "self", true)
42
- @second = SmellWarning.new(Smells::FeatureEnvy.new, "self", "self", false)
49
+ @first = SmellWarning.new(Smells::Duplication.new, "self", "self", false)
50
+ @second = SmellWarning.new(Smells::FeatureEnvy.new, "self", "self", true)
43
51
  end
44
52
 
45
53
  it_should_behave_like 'first sorts ahead of second'
@@ -88,11 +96,11 @@ describe SmellWarning, 'equality' do
88
96
  def initialize
89
97
  @masked = @non_masked = 0
90
98
  end
91
- def <<(sw)
99
+ def found_smell(sw)
92
100
  @non_masked += 1
93
101
  end
94
102
 
95
- def record_masked_smell(sw)
103
+ def found_masked_smell(sw)
96
104
  @masked += 1
97
105
  end
98
106
  end
@@ -3,24 +3,96 @@ require File.dirname(__FILE__) + '/../../spec_helper.rb'
3
3
  require 'reek/smells/attribute'
4
4
  require 'reek/class_context'
5
5
 
6
- require 'spec/reek/smells/behaves_like_variable_detector'
7
-
8
6
  include Reek
9
7
  include Reek::Smells
10
8
 
11
9
  describe Attribute do
12
10
  before :each do
13
11
  @detector = Attribute.new
14
- @record_variable = :record_attribute
15
12
  end
13
+ context 'with no attributes' do
14
+ it 'records nothing in the class' do
15
+ ctx = ClassContext.from_s('class Fred; end')
16
+ @detector.attributes_in(ctx).should be_empty
17
+ end
18
+ it 'records nothing in the module' do
19
+ ctx = ModuleContext.from_s('module Fred; end')
20
+ @detector.attributes_in(ctx).should be_empty
21
+ end
22
+ end
23
+
24
+ context 'with one attribute' do
25
+ shared_examples_for 'one attribute found' do
26
+ it 'records the attribute' do
27
+ @detector.attributes_in(@ctx).should include(:property)
28
+ end
29
+ it 'records only that attribute' do
30
+ @detector.attributes_in(@ctx).length.should == 1
31
+ end
32
+ end
33
+
34
+ context 'declared in a class' do
35
+ before :each do
36
+ @ctx = ClassContext.from_s('class Fred; attr :property; end')
37
+ end
38
+
39
+ it_should_behave_like 'one attribute found'
40
+ end
41
+
42
+ context 'reader in a class' do
43
+ before :each do
44
+ @ctx = ClassContext.from_s('class Fred; attr_reader :property; end')
45
+ end
46
+
47
+ it_should_behave_like 'one attribute found'
48
+ end
49
+
50
+ context 'writer in a class' do
51
+ before :each do
52
+ @ctx = ClassContext.from_s('class Fred; attr_writer :property; end')
53
+ end
54
+
55
+ it_should_behave_like 'one attribute found'
56
+ end
57
+
58
+ context 'accessor in a class' do
59
+ before :each do
60
+ @ctx = ClassContext.from_s('class Fred; attr_accessor :property; end')
61
+ end
62
+
63
+ it_should_behave_like 'one attribute found'
64
+ end
65
+
66
+ context 'declared in a module' do
67
+ before :each do
68
+ @ctx = ModuleContext.from_s('module Fred; attr :property; end')
69
+ end
70
+
71
+ it_should_behave_like 'one attribute found'
72
+ end
73
+
74
+ context 'reader in a module' do
75
+ before :each do
76
+ @ctx = ModuleContext.from_s('module Fred; attr_reader :property; end')
77
+ end
78
+
79
+ it_should_behave_like 'one attribute found'
80
+ end
81
+
82
+ context 'writer in a module' do
83
+ before :each do
84
+ @ctx = ModuleContext.from_s('module Fred; attr_writer :property; end')
85
+ end
86
+
87
+ it_should_behave_like 'one attribute found'
88
+ end
16
89
 
17
- [ClassContext, ModuleContext].each do |klass|
18
- context "in a #{klass}" do
90
+ context 'accessor in a module' do
19
91
  before :each do
20
- @ctx = klass.create(StopContext.new, s(:null, :Fred))
92
+ @ctx = ModuleContext.from_s('module Fred; attr_accessor :property; end')
21
93
  end
22
94
 
23
- it_should_behave_like 'a variable detector'
95
+ it_should_behave_like 'one attribute found'
24
96
  end
25
97
  end
26
98
  end
@@ -5,19 +5,48 @@ require 'reek/smells/control_couple'
5
5
  include Reek::Smells
6
6
 
7
7
  describe ControlCouple do
8
- it 'should report a ternary check on a parameter' do
9
- 'def simple(arga) arga ? @ivar : 3 end'.should reek_only_of(:ControlCouple, /arga/)
8
+ context 'conditional on a parameter' do
9
+ it 'should report a ternary check on a parameter' do
10
+ 'def simple(arga) arga ? @ivar : 3 end'.should reek_only_of(:ControlCouple, /arga/)
11
+ end
12
+ it 'should not report a ternary check on an ivar' do
13
+ 'def simple(arga) @ivar ? arga : 3 end'.should_not reek
14
+ end
15
+ it 'should not report a ternary check on a lvar' do
16
+ 'def simple(arga) lvar = 27; lvar ? arga : @ivar end'.should_not reek
17
+ end
18
+ it 'should spot a couple inside a block' do
19
+ 'def blocks(arg) @text.map { |blk| arg ? blk : "#{blk}" } end'.should reek_of(:ControlCouple, /arg/)
20
+ end
10
21
  end
11
22
 
12
- it 'should not report a ternary check on an ivar' do
13
- 'def simple(arga) @ivar ? arga : 3 end'.should_not reek
14
- end
15
-
16
- it 'should not report a ternary check on a lvar' do
17
- 'def simple(arga) lvar = 27; lvar ? arga : @ivar end'.should_not reek
18
- end
23
+ context 'parameter defaulted with boolean' do
24
+ context 'in a method' do
25
+ it 'reports a parameter defaulted to true' do
26
+ 'def cc(arga = true) end'.should reek_of(:ControlCouple, /arga/)
27
+ end
28
+ it 'reports a parameter defaulted to false' do
29
+ 'def cc(arga = false) end'.should reek_of(:ControlCouple, /arga/)
30
+ end
31
+ it 'reports two parameters defaulted to booleans' do
32
+ src = 'def cc(nowt, arga = true, argb = false, &blk) end'
33
+ src.should reek_of(:ControlCouple, /arga/)
34
+ src.should reek_of(:ControlCouple, /argb/)
35
+ end
36
+ end
19
37
 
20
- it 'should spot a couple inside a block' do
21
- 'def blocks(arg) @text.map { |blk| arg ? blk : "#{blk}" } end'.should reek_of(:ControlCouple, /arg/)
38
+ context 'in a singleton method' do
39
+ it 'reports a parameter defaulted to true' do
40
+ 'def self.cc(arga = true) end'.should reek_of(:ControlCouple, /arga/)
41
+ end
42
+ it 'reports a parameter defaulted to false' do
43
+ 'def fred.cc(arga = false) end'.should reek_of(:ControlCouple, /arga/)
44
+ end
45
+ it 'reports two parameters defaulted to booleans' do
46
+ src = 'def Module.cc(nowt, arga = true, argb = false, &blk) end'
47
+ src.should reek_of(:ControlCouple, /arga/)
48
+ src.should reek_of(:ControlCouple, /argb/)
49
+ end
50
+ end
22
51
  end
23
52
  end
@@ -50,7 +50,7 @@ describe LongParameterList do
50
50
  'def simple(polly, queue, yep, zero=nil) f(3);false end'.should reek_only_of(:LongParameterList, /4 parameters/)
51
51
  end
52
52
  it 'should report with 3 defaulted' do
53
- 'def simple(aarg, polly=2, yep=true, zero=nil) f(3);false end'.should reek_only_of(:LongParameterList, /4 parameters/)
53
+ 'def simple(aarg, polly=2, yep=:truth, zero=nil) f(3);false end'.should reek_only_of(:LongParameterList, /4 parameters/)
54
54
  end
55
55
  end
56
56
  end
@@ -19,23 +19,6 @@ describe SmellDetector, 'configuration' do
19
19
  end
20
20
  end
21
21
 
22
- describe SmellDetector, 'when copied' do
23
- before :each do
24
- @detector = LongMethod.new
25
- @copy = @detector.copy
26
- end
27
-
28
- it 'should have the same state' do
29
- @copy.max_statements.should == @detector.max_statements
30
- end
31
-
32
- it 'should change independently of its parent' do
33
- default_max = @detector.max_statements
34
- @copy.configure_with(LongMethod::MAX_ALLOWED_STATEMENTS_KEY => 25)
35
- @detector.max_statements.should == default_max
36
- end
37
- end
38
-
39
22
  describe SmellDetector, 'configuration' do
40
23
  # it 'stays enabled when not disabled' do
41
24
  # @detector = LargeClass.new
@@ -0,0 +1,20 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper.rb'
2
+
3
+ require 'reek/tree_dresser'
4
+
5
+ include Reek
6
+
7
+ describe TreeDresser do
8
+ before(:each) do
9
+ @dresser = TreeDresser.new
10
+ end
11
+
12
+ it 'maps :if to IfNode' do
13
+ @dresser.extensions_for(:if).should == 'IfNode'
14
+ end
15
+
16
+ it 'maps :call to CallNode' do
17
+ @dresser.extensions_for(:call).should == 'CallNode'
18
+ end
19
+ end
20
+
@@ -0,0 +1,29 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper.rb'
2
+
3
+ require 'reek/version_command'
4
+
5
+ include Reek
6
+
7
+ describe VersionCommand do
8
+ before :each do
9
+ @text = 'Piece of interesting text'
10
+ @cmd = VersionCommand.new(@text)
11
+ @view = mock('view', :null_object => true)
12
+ @view.should_not_receive(:report_smells)
13
+ end
14
+
15
+ it 'displays the text on the view' do
16
+ @view.should_receive(:output).with(/#{@text}/)
17
+ @cmd.execute(@view)
18
+ end
19
+
20
+ it 'displays the Reek version on the view' do
21
+ @view.should_receive(:output).with(/#{Reek::VERSION}/)
22
+ @cmd.execute(@view)
23
+ end
24
+
25
+ it 'tells the view it succeeded' do
26
+ @view.should_receive(:report_success)
27
+ @cmd.execute(@view)
28
+ end
29
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reek
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.3
4
+ version: 1.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Rutherford
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-02 00:00:00 +00:00
12
+ date: 2009-11-17 00:00:00 +00:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -84,11 +84,14 @@ files:
84
84
  - lib/reek/code_parser.rb
85
85
  - lib/reek/configuration.rb
86
86
  - lib/reek/detector_stack.rb
87
+ - lib/reek/help_command.rb
87
88
  - lib/reek/if_context.rb
89
+ - lib/reek/masking_collection.rb
88
90
  - lib/reek/method_context.rb
89
91
  - lib/reek/module_context.rb
90
92
  - lib/reek/name.rb
91
93
  - lib/reek/object_refs.rb
94
+ - lib/reek/reek_command.rb
92
95
  - lib/reek/sexp_formatter.rb
93
96
  - lib/reek/singleton_method_context.rb
94
97
  - lib/reek/smell_warning.rb
@@ -110,6 +113,7 @@ files:
110
113
  - lib/reek/sniffer.rb
111
114
  - lib/reek/stop_context.rb
112
115
  - lib/reek/tree_dresser.rb
116
+ - lib/reek/version_command.rb
113
117
  - lib/reek/yield_call_context.rb
114
118
  - reek.gemspec
115
119
  - spec/reek/adapters/report_spec.rb
@@ -122,12 +126,15 @@ files:
122
126
  - spec/reek/code_parser_spec.rb
123
127
  - spec/reek/config_spec.rb
124
128
  - spec/reek/configuration_spec.rb
129
+ - spec/reek/help_command_spec.rb
125
130
  - spec/reek/if_context_spec.rb
131
+ - spec/reek/masking_collection_spec.rb
126
132
  - spec/reek/method_context_spec.rb
127
133
  - spec/reek/module_context_spec.rb
128
134
  - spec/reek/name_spec.rb
129
135
  - spec/reek/object_refs_spec.rb
130
136
  - spec/reek/object_source_spec.rb
137
+ - spec/reek/reek_command_spec.rb
131
138
  - spec/reek/singleton_method_context_spec.rb
132
139
  - spec/reek/smell_warning_spec.rb
133
140
  - spec/reek/smells/attribute_spec.rb
@@ -147,6 +154,8 @@ files:
147
154
  - spec/reek/smells/utility_function_spec.rb
148
155
  - spec/reek/sniffer_spec.rb
149
156
  - spec/reek/stop_context_spec.rb
157
+ - spec/reek/tree_dresser_spec.rb
158
+ - spec/reek/version_command_spec.rb
150
159
  - spec/samples/all_but_one_masked/clean_one.rb
151
160
  - spec/samples/all_but_one_masked/dirty.rb
152
161
  - spec/samples/all_but_one_masked/masked.reek