reek 1.2.0 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,48 +6,114 @@ require 'reek/smells/feature_envy'
6
6
  include Reek
7
7
 
8
8
  describe SmellWarning, 'equality' do
9
- before :each do
10
- @first = SmellWarning.new(Smells::FeatureEnvy.new, "self", "self", true)
11
- @second = SmellWarning.new(Smells::FeatureEnvy.new, "self", "self", false)
12
- end
9
+ context 'sort order' do
10
+ context 'smells differing only by masking' do
11
+ before :each do
12
+ @first = SmellWarning.new(Smells::FeatureEnvy.new, "self", "self", true)
13
+ @second = SmellWarning.new(Smells::FeatureEnvy.new, "self", "self", false)
14
+ end
13
15
 
14
- it 'should hash equal when the smell is the same' do
15
- @first.hash.should == @second.hash
16
- end
16
+ it 'should hash equal when the smell is the same' do
17
+ @first.hash.should == @second.hash
18
+ end
19
+ it 'should compare equal when the smell is the same' do
20
+ @first.should == @second
21
+ end
22
+ it 'should compare equal when using <=>' do
23
+ (@first <=> @second).should == 0
24
+ end
25
+ end
17
26
 
18
- it 'should compare equal when the smell is the same' do
19
- @first.should == @second
20
- end
27
+ shared_examples_for 'first sorts ahead of second' do
28
+ it 'hash differently' do
29
+ @first.hash.should_not == @second.hash
30
+ end
31
+ it 'are not equal' do
32
+ @first.should_not == @second
33
+ end
34
+ it 'sort correctly' do
35
+ (@first <=> @second).should be < 0
36
+ end
37
+ end
21
38
 
22
- it 'should compare equal when using <=>' do
23
- (@first <=> @second).should == 0
24
- end
25
-
26
- class CountingReport
27
- attr_reader :masked, :non_masked
28
- def initialize
29
- @masked = @non_masked = 0
39
+ context 'smells differing only by detector' do
40
+ before :each do
41
+ @first = SmellWarning.new(Smells::Duplication.new, "self", "self", true)
42
+ @second = SmellWarning.new(Smells::FeatureEnvy.new, "self", "self", false)
43
+ end
44
+
45
+ it_should_behave_like 'first sorts ahead of second'
30
46
  end
31
- def <<(sw)
32
- @non_masked += 1
47
+
48
+ context 'smells differing only by context' do
49
+ before :each do
50
+ @first = SmellWarning.new(Smells::FeatureEnvy.new, "first", "self", true)
51
+ @second = SmellWarning.new(Smells::FeatureEnvy.new, "second", "self", false)
52
+ end
53
+
54
+ it_should_behave_like 'first sorts ahead of second'
33
55
  end
34
-
35
- def record_masked_smell(sw)
36
- @masked += 1
56
+
57
+ context 'smells differing only by message' do
58
+ before :each do
59
+ @first = SmellWarning.new(Smells::FeatureEnvy.new, "context", "first", true)
60
+ @second = SmellWarning.new(Smells::FeatureEnvy.new, "context", "second", false)
61
+ end
62
+
63
+ it_should_behave_like 'first sorts ahead of second'
37
64
  end
38
- end
39
65
 
40
- it 'reports as masked when masked' do
41
- rpt = CountingReport.new
42
- @first.report_on(rpt)
43
- rpt.masked.should == 1
44
- rpt.non_masked.should == 0
66
+ context 'message takes precedence over smell name' do
67
+ before :each do
68
+ @first = SmellWarning.new(Smells::UtilityFunction.new, "context", "first", true)
69
+ @second = SmellWarning.new(Smells::FeatureEnvy.new, "context", "second", false)
70
+ end
71
+
72
+ it_should_behave_like 'first sorts ahead of second'
73
+ end
74
+
75
+ context 'smells differing everywhere' do
76
+ before :each do
77
+ @first = SmellWarning.new(Smells::UncommunicativeName.new, "Dirty", "has the variable name '@s'", true)
78
+ @second = SmellWarning.new(Smells::Duplication.new, 'Dirty#a', "calls @s.title twice", false)
79
+ end
80
+
81
+ it_should_behave_like 'first sorts ahead of second'
82
+ end
45
83
  end
84
+
85
+ context 'masked reporting' do
86
+ class CountingReport
87
+ attr_reader :masked, :non_masked
88
+ def initialize
89
+ @masked = @non_masked = 0
90
+ end
91
+ def <<(sw)
92
+ @non_masked += 1
93
+ end
46
94
 
47
- it 'reports as non-masked when non-masked' do
48
- rpt = CountingReport.new
49
- @second.report_on(rpt)
50
- rpt.masked.should == 0
51
- rpt.non_masked.should == 1
95
+ def record_masked_smell(sw)
96
+ @masked += 1
97
+ end
98
+ end
99
+
100
+ before :each do
101
+ @masked = SmellWarning.new(Smells::FeatureEnvy.new, "self", "self", true)
102
+ @visible = SmellWarning.new(Smells::FeatureEnvy.new, "self", "self", false)
103
+ end
104
+
105
+ it 'reports as masked when masked' do
106
+ rpt = CountingReport.new
107
+ @masked.report_on(rpt)
108
+ rpt.masked.should == 1
109
+ rpt.non_masked.should == 0
110
+ end
111
+
112
+ it 'reports as non-masked when non-masked' do
113
+ rpt = CountingReport.new
114
+ @visible.report_on(rpt)
115
+ rpt.masked.should == 0
116
+ rpt.non_masked.should == 1
117
+ end
52
118
  end
53
119
  end
@@ -0,0 +1,81 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
+
3
+ require 'reek/smells/class_variable'
4
+ require 'reek/class_context'
5
+
6
+ include Reek
7
+ include Reek::Smells
8
+
9
+ describe ClassVariable do
10
+ shared_examples_for 'a class variable container' do
11
+ context 'no class variables' do
12
+ it "doesn't record a smell" do
13
+ @detector.examine_context(@ctx)
14
+ @detector.num_smells.should == 0
15
+ end
16
+ end
17
+
18
+ context 'one class variable' do
19
+ before :each do
20
+ @ctx.record_class_variable(:@@cvar)
21
+ @detector.examine_context(@ctx)
22
+ end
23
+
24
+ it 'records a smell' do
25
+ @detector.num_smells.should == 1
26
+ end
27
+ it 'mentions the variable name in the report' do
28
+ @detector.should have_smell([/@@cvar/])
29
+ end
30
+ end
31
+
32
+ context 'one class variable encountered twice' do
33
+ before :each do
34
+ @ctx.record_class_variable(:@@cvar)
35
+ @ctx.record_class_variable(:@@cvar)
36
+ @detector.examine_context(@ctx)
37
+ end
38
+
39
+ it 'records only one smell' do
40
+ @detector.num_smells.should == 1
41
+ end
42
+ it 'mentions the variable name in the report' do
43
+ @detector.should have_smell([/@@cvar/])
44
+ end
45
+ end
46
+
47
+ context 'two class variables' do
48
+ before :each do
49
+ @ctx.record_class_variable(:@@cvar)
50
+ @ctx.record_class_variable(:@@another)
51
+ @detector.examine_context(@ctx)
52
+ end
53
+
54
+ it 'records a smell' do
55
+ @detector.num_smells.should == 2
56
+ end
57
+ it 'mentions both variable names in the report' do
58
+ @detector.should have_smell([/@@cvar/])
59
+ @detector.should have_smell([/@@another/])
60
+ end
61
+ end
62
+ end
63
+
64
+ context 'in a class' do
65
+ before :each do
66
+ @ctx = ClassContext.create(StopContext.new, "Fred")
67
+ @detector = ClassVariable.new
68
+ end
69
+
70
+ it_should_behave_like 'a class variable container'
71
+ end
72
+
73
+ context 'in a module' do
74
+ before :each do
75
+ @ctx = ModuleContext.create(StopContext.new, "Fred")
76
+ @detector = ClassVariable.new
77
+ end
78
+
79
+ it_should_behave_like 'a class variable container'
80
+ end
81
+ end
@@ -0,0 +1,27 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper.rb'
2
+
3
+ require 'reek/stop_context'
4
+
5
+ include Reek
6
+ include Reek::Smells
7
+
8
+ describe StopContext do
9
+ before :each do
10
+ @stop = StopContext.new
11
+ end
12
+
13
+ context 'with a module that is not loaded' do
14
+ it 'does not find the module' do
15
+ @stop.find_module('CGI').should == nil
16
+ end
17
+ it 'does not find an unqualified class in the module' do
18
+ @stop.find_module('HtmlExtension').should == nil
19
+ end
20
+ end
21
+
22
+ context 'with a module that is loaded' do
23
+ it 'finds the module' do
24
+ @stop.find_module('Reek').name.should == 'Reek'
25
+ end
26
+ end
27
+ end
@@ -8,6 +8,8 @@ rescue LoadError
8
8
  require 'spec/expectations'
9
9
  end
10
10
 
11
+ require 'spec/autorun'
12
+
11
13
  require 'reek/adapters/spec'
12
14
 
13
15
  SAMPLES_DIR = 'spec/samples' unless Object.const_defined?('SAMPLES_DIR')
@@ -8,3 +8,8 @@ begin
8
8
  end
9
9
  rescue Gem::LoadError
10
10
  end
11
+
12
+ begin
13
+ require 'metric_fu'
14
+ rescue LoadError
15
+ 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.0
4
+ version: 1.2.1
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-09-20 00:00:00 +01:00
12
+ date: 2009-10-03 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -69,6 +69,7 @@ files:
69
69
  - features/support/env.rb
70
70
  - lib/reek.rb
71
71
  - lib/reek/adapters/application.rb
72
+ - lib/reek/adapters/command_line.rb
72
73
  - lib/reek/adapters/config_file.rb
73
74
  - lib/reek/adapters/core_extras.rb
74
75
  - lib/reek/adapters/object_source.rb
@@ -80,7 +81,6 @@ files:
80
81
  - lib/reek/class_context.rb
81
82
  - lib/reek/code_context.rb
82
83
  - lib/reek/code_parser.rb
83
- - lib/reek/command_line.rb
84
84
  - lib/reek/configuration.rb
85
85
  - lib/reek/detector_stack.rb
86
86
  - lib/reek/exceptions.reek
@@ -92,6 +92,7 @@ files:
92
92
  - lib/reek/sexp_formatter.rb
93
93
  - lib/reek/singleton_method_context.rb
94
94
  - lib/reek/smell_warning.rb
95
+ - lib/reek/smells/class_variable.rb
95
96
  - lib/reek/smells/control_couple.rb
96
97
  - lib/reek/smells/data_clump.rb
97
98
  - lib/reek/smells/duplication.rb
@@ -128,6 +129,7 @@ files:
128
129
  - spec/reek/object_source_spec.rb
129
130
  - spec/reek/singleton_method_context_spec.rb
130
131
  - spec/reek/smell_warning_spec.rb
132
+ - spec/reek/smells/class_variable_spec.rb
131
133
  - spec/reek/smells/control_couple_spec.rb
132
134
  - spec/reek/smells/data_clump_spec.rb
133
135
  - spec/reek/smells/duplication_spec.rb
@@ -141,6 +143,7 @@ files:
141
143
  - spec/reek/smells/uncommunicative_name_spec.rb
142
144
  - spec/reek/smells/utility_function_spec.rb
143
145
  - spec/reek/sniffer_spec.rb
146
+ - spec/reek/stop_context_spec.rb
144
147
  - spec/samples/all_but_one_masked/clean_one.rb
145
148
  - spec/samples/all_but_one_masked/dirty.rb
146
149
  - spec/samples/all_but_one_masked/masked.reek
@@ -189,7 +192,7 @@ post_install_message: |
189
192
 
190
193
  rdoc_options:
191
194
  - --main
192
- - README.txt
195
+ - README.rdoc
193
196
  require_paths:
194
197
  - lib
195
198
  required_ruby_version: !ruby/object:Gem::Requirement