reek 1.2.7.2 → 1.2.7.3
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +9 -1
- data/config/defaults.reek +4 -4
- data/features/masking_smells.feature +14 -57
- data/features/options.feature +1 -2
- data/features/rake_task.feature +6 -6
- data/features/reports.feature +8 -38
- data/features/samples.feature +181 -181
- data/features/stdin.feature +3 -3
- data/lib/reek.rb +1 -1
- data/lib/reek/cli/command_line.rb +2 -7
- data/lib/reek/cli/reek_command.rb +6 -6
- data/lib/reek/cli/report.rb +27 -49
- data/lib/reek/core/code_parser.rb +6 -15
- data/lib/reek/core/method_context.rb +1 -1
- data/lib/reek/core/module_context.rb +0 -18
- data/lib/reek/core/smell_configuration.rb +0 -4
- data/lib/reek/core/sniffer.rb +11 -19
- data/lib/reek/core/warning_collector.rb +27 -0
- data/lib/reek/examiner.rb +43 -35
- data/lib/reek/rake/task.rb +2 -0
- data/lib/reek/smell_warning.rb +10 -25
- data/lib/reek/smells/boolean_parameter.rb +1 -1
- data/lib/reek/smells/control_couple.rb +4 -1
- data/lib/reek/smells/data_clump.rb +40 -33
- data/lib/reek/smells/feature_envy.rb +1 -1
- data/lib/reek/smells/long_parameter_list.rb +4 -1
- data/lib/reek/smells/long_yield_list.rb +6 -3
- data/lib/reek/smells/simulated_polymorphism.rb +1 -1
- data/lib/reek/smells/smell_detector.rb +4 -32
- data/lib/reek/smells/uncommunicative_method_name.rb +1 -1
- data/lib/reek/smells/uncommunicative_module_name.rb +1 -1
- data/lib/reek/smells/uncommunicative_parameter_name.rb +2 -2
- data/lib/reek/smells/uncommunicative_variable_name.rb +11 -18
- data/lib/reek/smells/utility_function.rb +7 -4
- data/lib/reek/source/reference_collector.rb +9 -2
- data/lib/reek/source/source_locator.rb +6 -0
- data/lib/reek/spec/should_reek.rb +3 -6
- data/lib/reek/spec/should_reek_only_of.rb +4 -3
- data/reek.gemspec +4 -4
- data/spec/reek/cli/reek_command_spec.rb +3 -4
- data/spec/reek/cli/report_spec.rb +10 -6
- data/spec/reek/cli/yaml_command_spec.rb +1 -1
- data/spec/reek/core/code_context_spec.rb +1 -3
- data/spec/reek/core/module_context_spec.rb +1 -1
- data/spec/reek/core/warning_collector_spec.rb +27 -0
- data/spec/reek/examiner_spec.rb +80 -19
- data/spec/reek/smell_warning_spec.rb +4 -61
- data/spec/reek/smells/attribute_spec.rb +4 -7
- data/spec/reek/smells/behaves_like_variable_detector.rb +2 -2
- data/spec/reek/smells/class_variable_spec.rb +0 -1
- data/spec/reek/smells/control_couple_spec.rb +8 -15
- data/spec/reek/smells/data_clump_spec.rb +85 -1
- data/spec/reek/smells/duplication_spec.rb +7 -8
- data/spec/reek/smells/feature_envy_spec.rb +2 -32
- data/spec/reek/smells/long_parameter_list_spec.rb +9 -16
- data/spec/reek/smells/long_yield_list_spec.rb +8 -15
- data/spec/reek/smells/smell_detector_shared.rb +12 -0
- data/spec/reek/smells/uncommunicative_variable_name_spec.rb +9 -10
- data/spec/reek/smells/utility_function_spec.rb +11 -15
- data/spec/reek/spec/should_reek_only_of_spec.rb +6 -6
- data/spec/reek/spec/should_reek_spec.rb +3 -3
- metadata +36 -22
- data/lib/reek/core/class_context.rb +0 -22
- data/lib/reek/core/detector_stack.rb +0 -33
- data/lib/reek/core/masking_collection.rb +0 -52
- data/spec/reek/core/class_context_spec.rb +0 -53
- data/spec/reek/core/masking_collection_spec.rb +0 -235
@@ -42,7 +42,7 @@ describe ShouldReekOnlyOf do
|
|
42
42
|
|
43
43
|
context 'with 1 non-matching smell' do
|
44
44
|
def smells
|
45
|
-
[SmellWarning.new('ControlCouple', 'context', [1], 'any old message'
|
45
|
+
[SmellWarning.new('ControlCouple', 'context', [1], 'any old message')]
|
46
46
|
end
|
47
47
|
|
48
48
|
it_should_behave_like 'no match'
|
@@ -51,8 +51,8 @@ describe ShouldReekOnlyOf do
|
|
51
51
|
context 'with 2 non-matching smells' do
|
52
52
|
def smells
|
53
53
|
[
|
54
|
-
SmellWarning.new('ControlCouple', 'context', [1], 'any old message'
|
55
|
-
SmellWarning.new('FeatureEnvy', 'context', [1], 'any old message'
|
54
|
+
SmellWarning.new('ControlCouple', 'context', [1], 'any old message'),
|
55
|
+
SmellWarning.new('FeatureEnvy', 'context', [1], 'any old message')
|
56
56
|
]
|
57
57
|
end
|
58
58
|
|
@@ -62,8 +62,8 @@ describe ShouldReekOnlyOf do
|
|
62
62
|
context 'with 1 non-matching and 1 matching smell' do
|
63
63
|
def smells
|
64
64
|
[
|
65
|
-
SmellWarning.new('ControlCouple', 'context', [1], 'any old message'
|
66
|
-
SmellWarning.new(@expected_smell_class.to_s, 'context', [1], "message mentioning #{@expected_context_name}"
|
65
|
+
SmellWarning.new('ControlCouple', 'context', [1], 'any old message'),
|
66
|
+
SmellWarning.new(@expected_smell_class.to_s, 'context', [1], "message mentioning #{@expected_context_name}")
|
67
67
|
]
|
68
68
|
end
|
69
69
|
|
@@ -72,7 +72,7 @@ describe ShouldReekOnlyOf do
|
|
72
72
|
|
73
73
|
context 'with 1 matching smell' do
|
74
74
|
def smells
|
75
|
-
[SmellWarning.new(@expected_smell_class.to_s, nil, [1], "message mentioning #{@expected_context_name}"
|
75
|
+
[SmellWarning.new(@expected_smell_class.to_s, nil, [1], "message mentioning #{@expected_context_name}")]
|
76
76
|
end
|
77
77
|
it 'matches' do
|
78
78
|
@match.should be_true
|
@@ -21,7 +21,7 @@ describe ShouldReek, 'checking code in a string' do
|
|
21
21
|
|
22
22
|
it 'reports the smells when should_not fails' do
|
23
23
|
@matcher.matches?(@smelly_code)
|
24
|
-
@matcher.failure_message_for_should_not.should match('
|
24
|
+
@matcher.failure_message_for_should_not.should match('UncommunicativeName')
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
@@ -42,7 +42,7 @@ describe ShouldReek, 'checking code in a Dir' do
|
|
42
42
|
|
43
43
|
it 'reports the smells when should_not fails' do
|
44
44
|
@matcher.matches?(@smelly_dir)
|
45
|
-
@matcher.failure_message_for_should_not.should match('
|
45
|
+
@matcher.failure_message_for_should_not.should match('UncommunicativeName')
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
@@ -63,6 +63,6 @@ describe ShouldReek, 'checking code in a File' do
|
|
63
63
|
|
64
64
|
it 'reports the smells when should_not fails' do
|
65
65
|
@matcher.matches?(@smelly_file)
|
66
|
-
@matcher.failure_message_for_should_not.should match('
|
66
|
+
@matcher.failure_message_for_should_not.should match('UncommunicativeName')
|
67
67
|
end
|
68
68
|
end
|
metadata
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: reek
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 1
|
7
|
+
- 2
|
8
|
+
- 7
|
9
|
+
- 3
|
10
|
+
version: 1.2.7.3
|
5
11
|
platform: ruby
|
6
12
|
authors:
|
7
13
|
- Kevin Rutherford
|
@@ -9,39 +15,48 @@ autorequire:
|
|
9
15
|
bindir: bin
|
10
16
|
cert_chain: []
|
11
17
|
|
12
|
-
date: 2010-03-
|
18
|
+
date: 2010-03-29 00:00:00 +01:00
|
13
19
|
default_executable:
|
14
20
|
dependencies:
|
15
21
|
- !ruby/object:Gem::Dependency
|
16
22
|
name: ruby_parser
|
17
|
-
|
18
|
-
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
25
|
requirements:
|
21
26
|
- - ~>
|
22
27
|
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 2
|
30
|
+
- 0
|
23
31
|
version: "2.0"
|
24
|
-
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
25
34
|
- !ruby/object:Gem::Dependency
|
26
35
|
name: ruby2ruby
|
27
|
-
|
28
|
-
|
29
|
-
version_requirements: !ruby/object:Gem::Requirement
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
38
|
requirements:
|
31
39
|
- - ~>
|
32
40
|
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 1
|
43
|
+
- 2
|
33
44
|
version: "1.2"
|
34
|
-
|
45
|
+
type: :runtime
|
46
|
+
version_requirements: *id002
|
35
47
|
- !ruby/object:Gem::Dependency
|
36
48
|
name: sexp_processor
|
37
|
-
|
38
|
-
|
39
|
-
version_requirements: !ruby/object:Gem::Requirement
|
49
|
+
prerelease: false
|
50
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
40
51
|
requirements:
|
41
52
|
- - ~>
|
42
53
|
- !ruby/object:Gem::Version
|
54
|
+
segments:
|
55
|
+
- 3
|
56
|
+
- 0
|
43
57
|
version: "3.0"
|
44
|
-
|
58
|
+
type: :runtime
|
59
|
+
version_requirements: *id003
|
45
60
|
description: |
|
46
61
|
Reek is a tool that examines Ruby classes, modules and methods
|
47
62
|
and reports any code smells it finds.
|
@@ -80,11 +95,8 @@ files:
|
|
80
95
|
- lib/reek/cli/report.rb
|
81
96
|
- lib/reek/cli/version_command.rb
|
82
97
|
- lib/reek/cli/yaml_command.rb
|
83
|
-
- lib/reek/core/class_context.rb
|
84
98
|
- lib/reek/core/code_context.rb
|
85
99
|
- lib/reek/core/code_parser.rb
|
86
|
-
- lib/reek/core/detector_stack.rb
|
87
|
-
- lib/reek/core/masking_collection.rb
|
88
100
|
- lib/reek/core/method_context.rb
|
89
101
|
- lib/reek/core/module_context.rb
|
90
102
|
- lib/reek/core/object_refs.rb
|
@@ -92,6 +104,7 @@ files:
|
|
92
104
|
- lib/reek/core/smell_configuration.rb
|
93
105
|
- lib/reek/core/sniffer.rb
|
94
106
|
- lib/reek/core/stop_context.rb
|
107
|
+
- lib/reek/core/warning_collector.rb
|
95
108
|
- lib/reek/examiner.rb
|
96
109
|
- lib/reek/rake/task.rb
|
97
110
|
- lib/reek/smell_warning.rb
|
@@ -136,17 +149,16 @@ files:
|
|
136
149
|
- spec/reek/cli/report_spec.rb
|
137
150
|
- spec/reek/cli/version_command_spec.rb
|
138
151
|
- spec/reek/cli/yaml_command_spec.rb
|
139
|
-
- spec/reek/core/class_context_spec.rb
|
140
152
|
- spec/reek/core/code_context_spec.rb
|
141
153
|
- spec/reek/core/code_parser_spec.rb
|
142
154
|
- spec/reek/core/config_spec.rb
|
143
|
-
- spec/reek/core/masking_collection_spec.rb
|
144
155
|
- spec/reek/core/method_context_spec.rb
|
145
156
|
- spec/reek/core/module_context_spec.rb
|
146
157
|
- spec/reek/core/object_refs_spec.rb
|
147
158
|
- spec/reek/core/singleton_method_context_spec.rb
|
148
159
|
- spec/reek/core/smell_configuration_spec.rb
|
149
160
|
- spec/reek/core/stop_context_spec.rb
|
161
|
+
- spec/reek/core/warning_collector_spec.rb
|
150
162
|
- spec/reek/examiner_spec.rb
|
151
163
|
- spec/reek/smell_warning_spec.rb
|
152
164
|
- spec/reek/smells/attribute_spec.rb
|
@@ -233,18 +245,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
233
245
|
requirements:
|
234
246
|
- - ">="
|
235
247
|
- !ruby/object:Gem::Version
|
248
|
+
segments:
|
249
|
+
- 0
|
236
250
|
version: "0"
|
237
|
-
version:
|
238
251
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
239
252
|
requirements:
|
240
253
|
- - ">="
|
241
254
|
- !ruby/object:Gem::Version
|
255
|
+
segments:
|
256
|
+
- 0
|
242
257
|
version: "0"
|
243
|
-
version:
|
244
258
|
requirements: []
|
245
259
|
|
246
260
|
rubyforge_project: reek
|
247
|
-
rubygems_version: 1.3.
|
261
|
+
rubygems_version: 1.3.6
|
248
262
|
signing_key:
|
249
263
|
specification_version: 3
|
250
264
|
summary: Code smell detector for Ruby
|
@@ -1,22 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(File.expand_path(__FILE__)), 'module_context')
|
2
|
-
|
3
|
-
module Reek
|
4
|
-
module Core
|
5
|
-
|
6
|
-
#
|
7
|
-
# A context wrapper for any class found in a syntax tree.
|
8
|
-
#
|
9
|
-
class ClassContext < ModuleContext
|
10
|
-
|
11
|
-
attr_reader :parsed_methods
|
12
|
-
|
13
|
-
def initialize(outer, name, exp)
|
14
|
-
super
|
15
|
-
end
|
16
|
-
|
17
|
-
def is_struct?
|
18
|
-
exp.superclass == [:const, :Struct]
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
|
2
|
-
module Reek
|
3
|
-
module Core
|
4
|
-
|
5
|
-
#
|
6
|
-
# A list of smell detectors of the same class, but with differing
|
7
|
-
# configurations.
|
8
|
-
#
|
9
|
-
class DetectorStack
|
10
|
-
|
11
|
-
def initialize(default_detector)
|
12
|
-
@detectors = [default_detector]
|
13
|
-
end
|
14
|
-
|
15
|
-
def push(config)
|
16
|
-
clone = @detectors[-1].supersede_with(config)
|
17
|
-
@detectors << clone
|
18
|
-
end
|
19
|
-
|
20
|
-
def adopt(config)
|
21
|
-
@detectors[-1].configure_with(config)
|
22
|
-
end
|
23
|
-
|
24
|
-
def listen_to(hooks)
|
25
|
-
@detectors.each { |det| det.listen_to(hooks) }
|
26
|
-
end
|
27
|
-
|
28
|
-
def report_on(report)
|
29
|
-
@detectors.each { |det| det.report_on(report) }
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
@@ -1,52 +0,0 @@
|
|
1
|
-
require 'set'
|
2
|
-
|
3
|
-
module Reek
|
4
|
-
module Core
|
5
|
-
|
6
|
-
#
|
7
|
-
# A set of items that can be "masked" or "visible". If an item is added
|
8
|
-
# more than once, only the "visible" copy is retained.
|
9
|
-
#
|
10
|
-
class MaskingCollection
|
11
|
-
def initialize
|
12
|
-
@visible_items = SortedSet.new
|
13
|
-
@masked_items = SortedSet.new
|
14
|
-
end
|
15
|
-
|
16
|
-
def collect_from(sources, config)
|
17
|
-
sources.each { |src| Core::Sniffer.new(src, config).report_on(self) }
|
18
|
-
self
|
19
|
-
end
|
20
|
-
|
21
|
-
def all_items
|
22
|
-
all = SortedSet.new(@visible_items)
|
23
|
-
all.merge(@masked_items)
|
24
|
-
all.to_a
|
25
|
-
end
|
26
|
-
def all_active_items
|
27
|
-
@visible_items
|
28
|
-
end
|
29
|
-
def found_smell(item)
|
30
|
-
@visible_items.add(item)
|
31
|
-
@masked_items.delete(item) if @masked_items.include?(item)
|
32
|
-
end
|
33
|
-
def found_masked_smell(item)
|
34
|
-
@masked_items.add(item) unless @visible_items.include?(item)
|
35
|
-
end
|
36
|
-
def num_visible_items
|
37
|
-
@visible_items.length
|
38
|
-
end
|
39
|
-
def num_masked_items
|
40
|
-
@masked_items.length
|
41
|
-
end
|
42
|
-
def each_item(&blk)
|
43
|
-
all = SortedSet.new(@visible_items)
|
44
|
-
all.merge(@masked_items)
|
45
|
-
all.each(&blk)
|
46
|
-
end
|
47
|
-
def each_visible_item(&blk)
|
48
|
-
@visible_items.each(&blk)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
@@ -1,53 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__)))), 'spec_helper')
|
2
|
-
require File.join(File.dirname(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__))))), 'lib', 'reek', 'core', 'class_context')
|
3
|
-
require File.join(File.dirname(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__))))), 'lib', 'reek', 'core', 'stop_context')
|
4
|
-
|
5
|
-
include Reek::Core
|
6
|
-
|
7
|
-
describe ClassContext do
|
8
|
-
it 'should report Long Parameter List' do
|
9
|
-
ruby = 'class Inner; def simple(arga, argb, argc, argd) f(3);true end end'
|
10
|
-
ruby.should reek_of(:LongParameterList, /Inner/, /simple/, /4 parameters/)
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'should report two different methods' do
|
14
|
-
src = <<EOEX
|
15
|
-
# module for test
|
16
|
-
class Fred
|
17
|
-
def simple(arga, argb, argc, argd) f(3);true end
|
18
|
-
def simply(arga, argb, argc, argd) f(3);false end
|
19
|
-
end
|
20
|
-
EOEX
|
21
|
-
|
22
|
-
src.should reek_of(:LongParameterList, /Fred/, /simple/)
|
23
|
-
src.should reek_of(:LongParameterList, /Fred/, /simply/)
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'should report many different methods' do
|
27
|
-
src = <<EOEX
|
28
|
-
# module for test
|
29
|
-
class Fred
|
30
|
-
def textile_bq(tag, atts, cite, content) f(3);end
|
31
|
-
def textile_p(tag, atts, cite, content) f(3);end
|
32
|
-
def textile_fn_(tag, num, atts, cite, content) f(3);end
|
33
|
-
def textile_popup_help(name, windowW, windowH) f(3);end
|
34
|
-
end
|
35
|
-
EOEX
|
36
|
-
|
37
|
-
src.should reek_of(:LongParameterList, /Fred/, /textile_bq/)
|
38
|
-
src.should reek_of(:LongParameterList, /Fred/, /textile_fn_/)
|
39
|
-
src.should reek_of(:LongParameterList, /Fred/, /textile_p/)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
describe ClassContext do
|
44
|
-
it 'does not report empty class in another module' do
|
45
|
-
'# module for test
|
46
|
-
class Treetop::Runtime::SyntaxNode; end'.should_not reek
|
47
|
-
end
|
48
|
-
|
49
|
-
it 'deals with :: scoped names' do
|
50
|
-
element = ClassContext.create(StopContext.new, [:colon2, [:colon2, [:const, :Treetop], :Runtime], :SyntaxNode])
|
51
|
-
element.num_methods.should == 0
|
52
|
-
end
|
53
|
-
end
|
@@ -1,235 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__)))), 'spec_helper')
|
2
|
-
require File.join(File.dirname(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__))))), 'lib', 'reek', 'core', 'masking_collection')
|
3
|
-
|
4
|
-
include Reek::Core
|
5
|
-
|
6
|
-
describe MaskingCollection do
|
7
|
-
before(:each) do
|
8
|
-
@collection = MaskingCollection.new
|
9
|
-
end
|
10
|
-
|
11
|
-
context 'when empty' do
|
12
|
-
it 'has no visible items' do
|
13
|
-
@collection.num_visible_items.should == 0
|
14
|
-
end
|
15
|
-
it 'has no masked items' do
|
16
|
-
@collection.num_masked_items.should == 0
|
17
|
-
end
|
18
|
-
it 'yields no items' do
|
19
|
-
count = 0
|
20
|
-
@collection.each_item {|item| count+= 1}
|
21
|
-
count.should == 0
|
22
|
-
end
|
23
|
-
it 'yields no visible items' do
|
24
|
-
count = 0
|
25
|
-
@collection.each_visible_item {|item| count+= 1}
|
26
|
-
count.should == 0
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
shared_examples_for 'one visible item' do
|
31
|
-
it 'has one visible item' do
|
32
|
-
@collection.num_visible_items.should == 1
|
33
|
-
end
|
34
|
-
it 'has no masked items' do
|
35
|
-
@collection.num_masked_items.should == 0
|
36
|
-
end
|
37
|
-
it 'yields one item' do
|
38
|
-
count = 0
|
39
|
-
@collection.each_item do |item|
|
40
|
-
item.should == @item
|
41
|
-
count+= 1
|
42
|
-
end
|
43
|
-
count.should == 1
|
44
|
-
end
|
45
|
-
it 'yields one visible item' do
|
46
|
-
count = 0
|
47
|
-
@collection.each_visible_item do |item|
|
48
|
-
item.should == @item
|
49
|
-
count+= 1
|
50
|
-
end
|
51
|
-
count.should == 1
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
shared_examples_for 'one masked item' do
|
56
|
-
it 'has no visible items' do
|
57
|
-
@collection.num_visible_items.should == 0
|
58
|
-
end
|
59
|
-
it 'has one masked item' do
|
60
|
-
@collection.num_masked_items.should == 1
|
61
|
-
end
|
62
|
-
it 'yields one item' do
|
63
|
-
count = 0
|
64
|
-
@collection.each_item do |item|
|
65
|
-
item.should == @item
|
66
|
-
count+= 1
|
67
|
-
end
|
68
|
-
count.should == 1
|
69
|
-
end
|
70
|
-
it 'yields no visible items' do
|
71
|
-
count = 0
|
72
|
-
@collection.each_visible_item { |item| count+= 1 }
|
73
|
-
count.should == 0
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
context 'with one visible item' do
|
78
|
-
before :each do
|
79
|
-
@item = "hello"
|
80
|
-
@collection.found_smell(@item)
|
81
|
-
end
|
82
|
-
it_should_behave_like 'one visible item'
|
83
|
-
end
|
84
|
-
|
85
|
-
context 'with one masked item' do
|
86
|
-
before :each do
|
87
|
-
@item = "hiding!"
|
88
|
-
@collection.found_masked_smell(@item)
|
89
|
-
end
|
90
|
-
it_should_behave_like 'one masked item'
|
91
|
-
end
|
92
|
-
|
93
|
-
context 'with one masked and one visible' do
|
94
|
-
before :each do
|
95
|
-
@visible = "visible"
|
96
|
-
@masked = "masked"
|
97
|
-
@collection.found_masked_smell(@masked)
|
98
|
-
@collection.found_smell(@visible)
|
99
|
-
end
|
100
|
-
it 'has one visible item' do
|
101
|
-
@collection.num_visible_items.should == 1
|
102
|
-
end
|
103
|
-
it 'has one masked item' do
|
104
|
-
@collection.num_masked_items.should == 1
|
105
|
-
end
|
106
|
-
it 'yields both items' do
|
107
|
-
yielded_items = []
|
108
|
-
@collection.each_item { |item| yielded_items << item }
|
109
|
-
yielded_items.length.should == 2
|
110
|
-
yielded_items.should include(@visible)
|
111
|
-
yielded_items.should include(@masked)
|
112
|
-
end
|
113
|
-
it 'yields one visible item' do
|
114
|
-
count = 0
|
115
|
-
@collection.each_visible_item do |item|
|
116
|
-
item.should == @visible
|
117
|
-
count+= 1
|
118
|
-
end
|
119
|
-
count.should == 1
|
120
|
-
end
|
121
|
-
it 'yields the items in sort order' do
|
122
|
-
yielded_items = []
|
123
|
-
@collection.each_item { |item| yielded_items << item }
|
124
|
-
yielded_items.length.should == 2
|
125
|
-
yielded_items[0].should == @masked
|
126
|
-
yielded_items[1].should == @visible
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
context 'with one visible item added twice' do
|
131
|
-
before :each do
|
132
|
-
@item = "hello"
|
133
|
-
@collection.found_smell(@item)
|
134
|
-
@collection.found_smell(@item)
|
135
|
-
end
|
136
|
-
it_should_behave_like 'one visible item'
|
137
|
-
end
|
138
|
-
|
139
|
-
context 'with one masked item added twice' do
|
140
|
-
before :each do
|
141
|
-
@item = "hello"
|
142
|
-
@collection.found_masked_smell(@item)
|
143
|
-
@collection.found_masked_smell(@item)
|
144
|
-
end
|
145
|
-
it_should_behave_like 'one masked item'
|
146
|
-
end
|
147
|
-
|
148
|
-
context 'with two different visible items' do
|
149
|
-
before :each do
|
150
|
-
@first_item = "hello"
|
151
|
-
@second_item = "goodbye"
|
152
|
-
@collection.found_smell(@first_item)
|
153
|
-
@collection.found_smell(@second_item)
|
154
|
-
end
|
155
|
-
it 'has 2 visible items' do
|
156
|
-
@collection.num_visible_items.should == 2
|
157
|
-
end
|
158
|
-
it 'has no masked items' do
|
159
|
-
@collection.num_masked_items.should == 0
|
160
|
-
end
|
161
|
-
it 'yields both items' do
|
162
|
-
yielded_items = []
|
163
|
-
@collection.each_item { |item| yielded_items << item }
|
164
|
-
yielded_items.length.should == 2
|
165
|
-
yielded_items.should include(@first_item)
|
166
|
-
yielded_items.should include(@second_item)
|
167
|
-
end
|
168
|
-
it 'yields both visible items' do
|
169
|
-
yielded_items = []
|
170
|
-
@collection.each_visible_item { |item| yielded_items << item }
|
171
|
-
yielded_items.length.should == 2
|
172
|
-
yielded_items.should include(@first_item)
|
173
|
-
yielded_items.should include(@second_item)
|
174
|
-
end
|
175
|
-
it 'yields the items in sort order' do
|
176
|
-
yielded_items = []
|
177
|
-
@collection.each_visible_item { |item| yielded_items << item }
|
178
|
-
yielded_items.length.should == 2
|
179
|
-
yielded_items[0].should == @second_item
|
180
|
-
yielded_items[1].should == @first_item
|
181
|
-
end
|
182
|
-
end
|
183
|
-
|
184
|
-
context 'with two different masked items' do
|
185
|
-
before :each do
|
186
|
-
@first_item = "hello"
|
187
|
-
@second_item = "goodbye"
|
188
|
-
@collection.found_masked_smell(@first_item)
|
189
|
-
@collection.found_masked_smell(@second_item)
|
190
|
-
end
|
191
|
-
it 'has 0 visible items' do
|
192
|
-
@collection.num_visible_items.should == 0
|
193
|
-
end
|
194
|
-
it 'has 2 masked items' do
|
195
|
-
@collection.num_masked_items.should == 2
|
196
|
-
end
|
197
|
-
it 'yields both items' do
|
198
|
-
yielded_items = []
|
199
|
-
@collection.each_item { |item| yielded_items << item }
|
200
|
-
yielded_items.length.should == 2
|
201
|
-
yielded_items.should include(@first_item)
|
202
|
-
yielded_items.should include(@second_item)
|
203
|
-
end
|
204
|
-
it 'yields no visible items' do
|
205
|
-
count = 0
|
206
|
-
@collection.each_visible_item { |item| count+= 1 }
|
207
|
-
count.should == 0
|
208
|
-
end
|
209
|
-
it 'yields the items in sort order' do
|
210
|
-
yielded_items = []
|
211
|
-
@collection.each_item { |item| yielded_items << item }
|
212
|
-
yielded_items.length.should == 2
|
213
|
-
yielded_items[0].should == @second_item
|
214
|
-
yielded_items[1].should == @first_item
|
215
|
-
end
|
216
|
-
end
|
217
|
-
|
218
|
-
context 'with one masked item later made visible' do
|
219
|
-
before :each do
|
220
|
-
@item = "hello"
|
221
|
-
@collection.found_masked_smell(@item)
|
222
|
-
@collection.found_smell(@item)
|
223
|
-
end
|
224
|
-
it_should_behave_like 'one visible item'
|
225
|
-
end
|
226
|
-
|
227
|
-
context 'with one visible item later masked' do
|
228
|
-
before :each do
|
229
|
-
@item = "hello"
|
230
|
-
@collection.found_smell(@item)
|
231
|
-
@collection.found_masked_smell(@item)
|
232
|
-
end
|
233
|
-
it_should_behave_like 'one visible item'
|
234
|
-
end
|
235
|
-
end
|