compo 0.4.0 → 0.5.0
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.
- checksums.yaml +4 -4
- data/.rspec +0 -1
- data/.travis.yml +3 -0
- data/CHANGELOG +11 -0
- data/README.md +3 -0
- data/compo.gemspec +3 -4
- data/lib/compo/composites/composite.rb +16 -0
- data/lib/compo/composites/parentless.rb +14 -15
- data/lib/compo/finders/root.rb +77 -0
- data/lib/compo/finders.rb +1 -0
- data/lib/compo/mixins/parent_tracker.rb +15 -0
- data/lib/compo/mixins/url_referenceable.rb +8 -23
- data/lib/compo/version.rb +1 -1
- data/spec/array_branch_spec.rb +1 -1
- data/spec/array_composite_shared_examples.rb +108 -103
- data/spec/array_composite_spec.rb +1 -1
- data/spec/branch_shared_examples.rb +9 -6
- data/spec/branch_spec.rb +1 -1
- data/spec/composite_shared_examples.rb +64 -47
- data/spec/composite_spec.rb +1 -1
- data/spec/constant_branch_spec.rb +1 -1
- data/spec/hash_branch_spec.rb +1 -1
- data/spec/hash_composite_shared_examples.rb +28 -31
- data/spec/hash_composite_spec.rb +1 -1
- data/spec/leaf_branch_spec.rb +1 -1
- data/spec/leaf_composite_shared_examples.rb +14 -28
- data/spec/leaf_composite_spec.rb +1 -1
- data/spec/movable_shared_examples.rb +4 -4
- data/spec/movable_spec.rb +1 -1
- data/spec/parent_tracker_spec.rb +1 -1
- data/spec/parentless_spec.rb +21 -11
- data/spec/root_finder_spec.rb +66 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/url_finder_shared_examples.rb +1 -1
- data/spec/url_finder_spec.rb +1 -1
- data/spec/url_referenceable_shared_examples.rb +16 -14
- data/spec/url_referenceable_spec.rb +1 -1
- metadata +14 -23
@@ -2,7 +2,7 @@ require 'url_finder_shared_examples'
|
|
2
2
|
require 'url_referenceable_shared_examples'
|
3
3
|
require 'movable_shared_examples'
|
4
4
|
|
5
|
-
shared_examples 'a branch' do
|
5
|
+
RSpec.shared_examples 'a branch' do
|
6
6
|
it_behaves_like 'a URL referenceable object'
|
7
7
|
it_behaves_like 'a movable object'
|
8
8
|
|
@@ -16,6 +16,11 @@ shared_examples 'a branch' do
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
+
shared_context 'the branch has a parent' do
|
20
|
+
let(:parent) { Compo::Branches::Hash.new }
|
21
|
+
before(:each) { subject.move_to(parent, :id) }
|
22
|
+
end
|
23
|
+
|
19
24
|
describe '#url' do
|
20
25
|
context 'when the Branch has no parent' do
|
21
26
|
it 'returns the empty string' do
|
@@ -23,8 +28,7 @@ shared_examples 'a branch' do
|
|
23
28
|
end
|
24
29
|
end
|
25
30
|
context 'when the Branch is the child of a root' do
|
26
|
-
|
27
|
-
before(:each) { subject.move_to(parent, :id) }
|
31
|
+
include_context 'the branch has a parent'
|
28
32
|
|
29
33
|
it 'returns /ID, where ID is the ID of the Branch' do
|
30
34
|
expect(subject.url).to eq('/id')
|
@@ -35,8 +39,7 @@ shared_examples 'a branch' do
|
|
35
39
|
describe '#move_to' do
|
36
40
|
context 'when the Branch has a parent' do
|
37
41
|
context 'when the new parent is nil' do
|
38
|
-
|
39
|
-
before(:each) { subject.move_to(parent, :id) }
|
42
|
+
include_context 'the branch has a parent'
|
40
43
|
|
41
44
|
it 'loses its previous parent' do
|
42
45
|
expect(subject.move_to(nil, :id).parent).to be_a(
|
@@ -53,7 +56,7 @@ shared_examples 'a branch' do
|
|
53
56
|
end
|
54
57
|
end
|
55
58
|
|
56
|
-
shared_examples 'a branch with children' do
|
59
|
+
RSpec.shared_examples 'a branch with children' do
|
57
60
|
it_behaves_like 'a branch'
|
58
61
|
|
59
62
|
describe '#find_url' do
|
data/spec/branch_spec.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'compo'
|
2
2
|
|
3
|
-
shared_examples 'a removal of a child from its parent' do
|
3
|
+
RSpec.shared_examples 'a removal of a child from its parent' do
|
4
4
|
it 'calls #update_parent on the child with a Parentless' do
|
5
5
|
expect(child).to receive(:update_parent).once do |parent, _|
|
6
6
|
expect(parent).to be_a(Compo::Composites::Parentless)
|
@@ -16,7 +16,7 @@ shared_examples 'a removal of a child from its parent' do
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
shared_examples 'a composite' do
|
19
|
+
RSpec.shared_examples 'a composite' do
|
20
20
|
let(:id) { double(:id) }
|
21
21
|
let(:child) { double(:child) }
|
22
22
|
|
@@ -32,7 +32,19 @@ shared_examples 'a composite' do
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
+
describe '#on_node' do
|
36
|
+
it 'calls the block given with the subject' do
|
37
|
+
expect { |block| subject.on_node(&block) }.to yield_with_args(subject)
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'returns the result of the block' do
|
41
|
+
expect(subject.on_node { |subject| subject }).to eq(subject)
|
42
|
+
expect(subject.on_node { 3 }).to eq(3)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
35
46
|
describe '#add' do
|
47
|
+
let(:idf) { double(:id_function) }
|
36
48
|
before(:each) { allow(subject).to receive(:add!) }
|
37
49
|
|
38
50
|
context 'when #add! returns nil' do
|
@@ -48,26 +60,24 @@ shared_examples 'a composite' do
|
|
48
60
|
|
49
61
|
context 'when #add! returns the child' do
|
50
62
|
before(:each) do
|
51
|
-
allow(subject).to
|
52
|
-
allow(subject).to receive(:id_function)
|
63
|
+
allow(subject).to receive_messages(add!: child, id_function: nil)
|
53
64
|
allow(child).to receive(:update_parent)
|
54
65
|
end
|
55
66
|
|
56
67
|
it 'calls #add! with the ID and child given' do
|
57
|
-
expect(subject).to receive(:add!).once.with(id, child)
|
58
68
|
subject.add(id, child)
|
69
|
+
expect(subject).to have_received(:add!).once.with(id, child)
|
59
70
|
end
|
60
71
|
|
61
72
|
it 'calls #id_function with the child given' do
|
62
|
-
expect(subject).to receive(:id_function).once.with(child)
|
63
73
|
subject.add(id, child)
|
74
|
+
expect(subject).to have_received(:id_function).once.with(child)
|
64
75
|
end
|
65
76
|
|
66
77
|
it 'calls #update_parent on the child with the parent and ID function' do
|
67
|
-
idf = double(:id_function)
|
68
78
|
allow(subject).to receive(:id_function).and_return(idf)
|
69
|
-
expect(child).to receive(:update_parent).once.with(subject, idf)
|
70
79
|
subject.add(id, child)
|
80
|
+
expect(child).to have_received(:update_parent).once.with(subject, idf)
|
71
81
|
end
|
72
82
|
|
73
83
|
it 'returns the given child' do
|
@@ -95,16 +105,18 @@ shared_examples 'a composite' do
|
|
95
105
|
end
|
96
106
|
end
|
97
107
|
|
98
|
-
shared_examples 'a composite with default #remove!' do
|
108
|
+
RSpec.shared_examples 'a composite with default #remove!' do
|
99
109
|
let(:child) { double(:child) }
|
100
110
|
let(:id) { double(:id) }
|
101
111
|
|
102
112
|
describe '#remove' do
|
103
113
|
context 'when #remove! is defined' do
|
104
|
-
before(:each)
|
114
|
+
before(:each) do
|
115
|
+
allow(subject).to receive(:remove!).and_return(remove_result)
|
116
|
+
end
|
105
117
|
|
106
118
|
context 'when #remove! returns nil' do
|
107
|
-
|
119
|
+
let(:remove_result) { nil }
|
108
120
|
|
109
121
|
specify { expect(subject.remove(child)).to be_nil }
|
110
122
|
|
@@ -115,10 +127,8 @@ shared_examples 'a composite with default #remove!' do
|
|
115
127
|
end
|
116
128
|
|
117
129
|
context 'when #remove! returns the child' do
|
118
|
-
|
119
|
-
|
120
|
-
allow(child).to receive(:update_parent)
|
121
|
-
end
|
130
|
+
let(:remove_result) { child }
|
131
|
+
before(:each) { allow(child).to receive(:update_parent) }
|
122
132
|
|
123
133
|
it 'calls #remove! with the child given' do
|
124
134
|
expect(subject).to receive(:remove!).once.with(child)
|
@@ -137,40 +147,40 @@ shared_examples 'a composite with default #remove!' do
|
|
137
147
|
|
138
148
|
context 'when #remove_id! is defined but #remove! is not' do
|
139
149
|
before(:each) do
|
140
|
-
allow(subject).to
|
141
|
-
|
150
|
+
allow(subject).to receive_messages(remove_id!: remove_id_result,
|
151
|
+
children: { id => child })
|
142
152
|
end
|
143
153
|
|
144
154
|
context 'when #remove_id! returns nil' do
|
145
|
-
|
146
|
-
allow(subject).to receive(:remove_id!).and_return(nil)
|
147
|
-
end
|
155
|
+
let(:remove_id_result) { nil }
|
148
156
|
|
149
157
|
specify { expect(subject.remove(child)).to be_nil }
|
150
158
|
|
151
159
|
it 'calls #remove! with the child given' do
|
160
|
+
# Note: #remove! is not a stub, so we must use this form of
|
161
|
+
# expectation.
|
152
162
|
expect(subject).to receive(:remove!).once.with(child)
|
153
163
|
subject.remove(child)
|
154
164
|
end
|
155
165
|
|
156
166
|
it 'calls #remove_id! with the ID of the child' do
|
157
|
-
expect(subject).to receive(:remove_id!).once.with(id)
|
158
167
|
subject.remove(child)
|
168
|
+
expect(subject).to have_received(:remove_id!).once.with(id)
|
159
169
|
end
|
160
170
|
|
161
171
|
it 'calls #children' do
|
162
|
-
expect(subject).to receive(:children).once
|
163
172
|
subject.remove(child)
|
173
|
+
expect(subject).to have_received(:children).once
|
164
174
|
end
|
165
175
|
end
|
166
176
|
|
167
177
|
context 'when #remove_id! returns the child' do
|
168
|
-
|
169
|
-
allow(
|
170
|
-
allow(child).to receive(:update_parent)
|
171
|
-
end
|
178
|
+
let(:remove_id_result) { child }
|
179
|
+
before(:each) { allow(child).to receive(:update_parent) }
|
172
180
|
|
173
|
-
it 'calls #
|
181
|
+
it 'calls #remove! with the child given' do
|
182
|
+
# Note: #remove! is not a stub, so we must use this form of
|
183
|
+
# expectation.
|
174
184
|
expect(subject).to receive(:remove!).once.with(child)
|
175
185
|
subject.remove(child)
|
176
186
|
end
|
@@ -187,38 +197,34 @@ shared_examples 'a composite with default #remove!' do
|
|
187
197
|
end
|
188
198
|
end
|
189
199
|
|
190
|
-
shared_examples 'a composite with default #remove_id!' do
|
200
|
+
RSpec.shared_examples 'a composite with default #remove_id!' do
|
191
201
|
let(:child) { double(:child) }
|
192
|
-
let(:id)
|
202
|
+
let(:id) { double(:id) }
|
193
203
|
|
194
204
|
describe '#remove_id' do
|
195
|
-
let(:id) { double(:id) }
|
196
|
-
|
197
205
|
context 'when #remove_id! is defined' do
|
198
|
-
before(:each)
|
206
|
+
before(:each) do
|
207
|
+
allow(subject).to receive(:remove_id!).and_return(remove_id_result)
|
208
|
+
end
|
199
209
|
|
200
210
|
context 'and #remove_id! returns nil' do
|
201
|
-
|
202
|
-
allow(subject).to receive(:remove_id!).and_return(nil)
|
203
|
-
end
|
211
|
+
let(:remove_id_result) { nil }
|
204
212
|
|
205
213
|
specify { expect(subject.remove_id(id)).to be_nil }
|
206
214
|
|
207
215
|
it 'calls #remove_id! with the ID given' do
|
208
|
-
expect(subject).to receive(:remove_id!).once.with(id)
|
209
216
|
subject.remove_id(id)
|
217
|
+
expect(subject).to have_received(:remove_id!).once.with(id)
|
210
218
|
end
|
211
219
|
end
|
212
220
|
|
213
221
|
context 'and #remove_id! returns the child' do
|
214
|
-
|
215
|
-
allow(
|
216
|
-
allow(child).to receive(:update_parent)
|
217
|
-
end
|
222
|
+
let(:remove_id_result) { child }
|
223
|
+
before(:each) { allow(child).to receive(:update_parent) }
|
218
224
|
|
219
225
|
it 'calls #remove_id! with the ID given' do
|
220
|
-
expect(subject).to receive(:remove_id!).once.with(id)
|
221
226
|
subject.remove_id(id)
|
227
|
+
expect(subject).to have_received(:remove_id!).once.with(id)
|
222
228
|
end
|
223
229
|
|
224
230
|
it_behaves_like 'a removal of a child from its parent' do
|
@@ -232,42 +238,53 @@ shared_examples 'a composite with default #remove_id!' do
|
|
232
238
|
end
|
233
239
|
|
234
240
|
context 'when #remove! is defined but #remove_id! is not' do
|
235
|
-
before(:each)
|
241
|
+
before(:each) do
|
242
|
+
allow(subject).to receive(:remove!).and_return(remove_result)
|
243
|
+
end
|
236
244
|
|
237
245
|
context 'and #remove! returns nil' do
|
246
|
+
let(:remove_result) { nil }
|
238
247
|
before(:each) do
|
239
|
-
allow(subject).to receive(:remove!).and_return(nil)
|
240
248
|
allow(subject).to receive(:get_child).and_return(child)
|
241
249
|
end
|
242
250
|
|
243
251
|
specify { expect(subject.remove_id(id)).to be_nil }
|
244
252
|
|
245
253
|
it 'calls #remove_id! with the ID given' do
|
254
|
+
# Note: #remove_id! is not a stub, so we must use this form of
|
255
|
+
# expectation.
|
246
256
|
expect(subject).to receive(:remove_id!).once.with(id)
|
247
257
|
subject.remove_id(id)
|
248
258
|
end
|
249
259
|
|
250
260
|
it 'calls #get_child with the ID given' do
|
251
|
-
expect(subject).to receive(:get_child).once.with(id)
|
252
261
|
subject.remove_id(id)
|
262
|
+
expect(subject).to have_received(:get_child).once.with(id)
|
253
263
|
end
|
254
264
|
|
255
265
|
it 'calls #remove! with the child given' do
|
256
|
-
expect(subject).to receive(:remove!).once.with(child)
|
257
266
|
subject.remove_id(id)
|
267
|
+
expect(subject).to have_received(:remove!).once.with(child)
|
258
268
|
end
|
259
269
|
end
|
260
270
|
|
261
271
|
context 'and #remove! returns the child' do
|
272
|
+
let(:remove_result) { child }
|
262
273
|
before(:each) do
|
263
|
-
allow(subject).to receive(:remove!).and_return(child)
|
264
274
|
allow(subject).to receive(:get_child).and_return(child)
|
265
275
|
allow(child).to receive(:update_parent)
|
266
276
|
end
|
267
277
|
|
278
|
+
it 'calls #remove_id! with the ID given' do
|
279
|
+
# Note: #remove_id! is not a stub, so we must use this form of
|
280
|
+
# expectation.
|
281
|
+
expect(subject).to receive(:remove_id!).once.with(id)
|
282
|
+
subject.remove_id(id)
|
283
|
+
end
|
284
|
+
|
268
285
|
it 'calls #remove! with the child given' do
|
269
|
-
expect(subject).to receive(:remove!).once.with(child)
|
270
286
|
subject.remove_id(id)
|
287
|
+
expect(subject).to have_received(:remove!).once.with(child)
|
271
288
|
end
|
272
289
|
|
273
290
|
it_behaves_like 'a removal of a child from its parent' do
|
data/spec/composite_spec.rb
CHANGED
@@ -7,7 +7,7 @@ class MockComposite
|
|
7
7
|
include Compo::Composites::Composite
|
8
8
|
end
|
9
9
|
|
10
|
-
describe MockComposite do
|
10
|
+
RSpec.describe MockComposite do
|
11
11
|
before(:each) { allow(subject).to receive(:children).and_return(children) }
|
12
12
|
let(:children) { { in_children: child } }
|
13
13
|
let(:child) { double(:child) }
|
data/spec/hash_branch_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'compo'
|
2
2
|
require 'composite_shared_examples'
|
3
3
|
|
4
|
-
shared_examples 'a hash composite' do
|
4
|
+
RSpec.shared_examples 'a hash composite' do
|
5
5
|
it_behaves_like 'a composite'
|
6
6
|
|
7
7
|
let(:child1) { double(:child1) }
|
@@ -22,10 +22,9 @@ shared_examples 'a hash composite' do
|
|
22
22
|
end
|
23
23
|
|
24
24
|
it 'replaces the old child in the child hash' do
|
25
|
-
expect
|
26
|
-
|
27
|
-
|
28
|
-
expect(subject.children).to eq(a: child2)
|
25
|
+
expect { subject.add(:a, child2) }.to change { subject.children }
|
26
|
+
.from(a: child1)
|
27
|
+
.to(a: child2)
|
29
28
|
end
|
30
29
|
|
31
30
|
it 'calls #update_parent on the new child with itself and an ID proc' do
|
@@ -61,14 +60,15 @@ shared_examples 'a hash composite' do
|
|
61
60
|
it 'adds to the child hash' do
|
62
61
|
expect(subject.children).to eq({})
|
63
62
|
|
64
|
-
subject.add(:a, child1)
|
65
|
-
|
66
|
-
|
67
|
-
subject.add(:b, child2)
|
68
|
-
|
69
|
-
|
70
|
-
subject.add(:c, child3)
|
71
|
-
|
63
|
+
expect { subject.add(:a, child1) }.to change { subject.children }
|
64
|
+
.from({})
|
65
|
+
.to(a: child1)
|
66
|
+
expect { subject.add(:b, child2) }.to change { subject.children }
|
67
|
+
.from(a: child1)
|
68
|
+
.to(a: child1, b: child2)
|
69
|
+
expect { subject.add(:c, child3) }.to change { subject.children }
|
70
|
+
.from(a: child1, b: child2)
|
71
|
+
.to(a: child1, b: child2, c: child3)
|
72
72
|
end
|
73
73
|
|
74
74
|
it 'calls #update_parent on the child with itself and an ID proc' do
|
@@ -106,9 +106,10 @@ shared_examples 'a hash composite' do
|
|
106
106
|
it 'removes the child, and only the child, from the children hash' do
|
107
107
|
subject.add(:b, child2)
|
108
108
|
subject.add(:c, child3)
|
109
|
-
|
110
|
-
subject.remove(child2)
|
111
|
-
|
109
|
+
|
110
|
+
expect { subject.remove(child2) }.to change { subject.children }
|
111
|
+
.from(a: child1, b: child2, c: child3)
|
112
|
+
.to(a: child1, c: child3)
|
112
113
|
end
|
113
114
|
end
|
114
115
|
|
@@ -116,15 +117,13 @@ shared_examples 'a hash composite' do
|
|
116
117
|
specify { expect(subject.remove(child1)).to be_nil }
|
117
118
|
|
118
119
|
it 'does not change the children' do
|
119
|
-
expect
|
120
|
-
|
121
|
-
expect(subject.children).to eq({})
|
120
|
+
expect { subject.remove(child1) }.to_not change { subject.children }
|
121
|
+
.from({})
|
122
122
|
|
123
123
|
subject.add(:a, child1)
|
124
124
|
subject.add(:b, child2)
|
125
|
-
expect
|
126
|
-
|
127
|
-
expect(subject.children).to eq(a: child1, b: child2)
|
125
|
+
expect { subject.remove(child3) }.to_not change { subject.children }
|
126
|
+
.from(a: child1, b: child2)
|
128
127
|
end
|
129
128
|
end
|
130
129
|
end
|
@@ -154,9 +153,9 @@ shared_examples 'a hash composite' do
|
|
154
153
|
it 'does not change the IDs of other children' do
|
155
154
|
subject.add(:b, child2)
|
156
155
|
subject.add(:c, child3)
|
157
|
-
expect
|
158
|
-
|
159
|
-
|
156
|
+
expect { subject.remove_id(:b) }.to change { subject.children }
|
157
|
+
.from(a: child1, b: child2, c: child3)
|
158
|
+
.to(a: child1, c: child3)
|
160
159
|
end
|
161
160
|
end
|
162
161
|
|
@@ -164,15 +163,13 @@ shared_examples 'a hash composite' do
|
|
164
163
|
specify { expect(subject.remove_id(:a)).to be_nil }
|
165
164
|
|
166
165
|
it 'does not change the children' do
|
167
|
-
expect
|
168
|
-
|
169
|
-
expect(subject.children).to eq({})
|
166
|
+
expect { subject.remove_id(:a) }.to_not change { subject.children }
|
167
|
+
.from({})
|
170
168
|
|
171
169
|
subject.add(:a, child1)
|
172
170
|
subject.add(:b, child2)
|
173
|
-
expect
|
174
|
-
|
175
|
-
expect(subject.children).to eq(a: child1, b: child2)
|
171
|
+
expect { subject.remove_id(:c) }.to_not change { subject.children }
|
172
|
+
.from(a: child1, b: child2)
|
176
173
|
end
|
177
174
|
end
|
178
175
|
end
|
data/spec/hash_composite_spec.rb
CHANGED
data/spec/leaf_branch_spec.rb
CHANGED
@@ -1,47 +1,33 @@
|
|
1
1
|
require 'composite_shared_examples'
|
2
2
|
|
3
|
-
shared_examples 'a leaf composite' do
|
3
|
+
RSpec.shared_examples 'a leaf composite' do
|
4
4
|
it_behaves_like 'a composite'
|
5
5
|
|
6
|
-
let(:
|
7
|
-
let(:
|
8
|
-
let(:
|
6
|
+
let(:c1) { double(:child1) }
|
7
|
+
let(:c2) { double(:child2) }
|
8
|
+
let(:c3) { double(:child3) }
|
9
9
|
|
10
10
|
describe '#add' do
|
11
11
|
it 'always returns nil' do
|
12
|
-
expect(subject.add(1,
|
13
|
-
expect(subject.add(:a,
|
14
|
-
expect(subject.add(nil,
|
12
|
+
expect(subject.add(1, c1)).to be_nil
|
13
|
+
expect(subject.add(:a, c2)).to be_nil
|
14
|
+
expect(subject.add(nil, c3)).to be_nil
|
15
15
|
end
|
16
16
|
|
17
17
|
it 'does not change the result of #children' do
|
18
|
-
expect(subject.children
|
19
|
-
|
20
|
-
subject.add(
|
21
|
-
expect(subject.children).to eq({})
|
22
|
-
|
23
|
-
subject.add(:a, child2)
|
24
|
-
expect(subject.children).to eq({})
|
25
|
-
|
26
|
-
subject.add(:a, child3)
|
27
|
-
expect(subject.children).to eq({})
|
18
|
+
expect { subject.add(1, c1) }.to_not change { subject.children }.from({})
|
19
|
+
expect { subject.add(:a, c2) }.to_not change { subject.children }.from({})
|
20
|
+
expect { subject.add(:a, c3) }.to_not change { subject.children }.from({})
|
28
21
|
end
|
29
22
|
end
|
30
23
|
|
31
24
|
describe '#remove' do
|
32
|
-
specify { expect(subject.remove(
|
25
|
+
specify { expect(subject.remove(c1)).to eq(nil) }
|
33
26
|
|
34
27
|
it 'does not change the result of #children' do
|
35
|
-
expect(subject.children
|
36
|
-
|
37
|
-
subject.remove(
|
38
|
-
expect(subject.children).to eq({})
|
39
|
-
|
40
|
-
subject.remove(child2)
|
41
|
-
expect(subject.children).to eq({})
|
42
|
-
|
43
|
-
subject.remove(child3)
|
44
|
-
expect(subject.children).to eq({})
|
28
|
+
expect { subject.remove(c1) }.to_not change { subject.children }.from({})
|
29
|
+
expect { subject.remove(c2) }.to_not change { subject.children }.from({})
|
30
|
+
expect { subject.remove(c3) }.to_not change { subject.children }.from({})
|
45
31
|
end
|
46
32
|
end
|
47
33
|
|
data/spec/leaf_composite_spec.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'compo'
|
2
2
|
|
3
|
-
shared_examples 'a normal call to #move_to' do
|
3
|
+
RSpec.shared_examples 'a normal call to #move_to' do
|
4
4
|
it 'returns itself' do
|
5
5
|
expect(subject.move_to(to, :test)).to eq(subject)
|
6
6
|
end
|
@@ -11,14 +11,14 @@ shared_examples 'a normal call to #move_to' do
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
shared_examples 'a removal from the old parent' do
|
14
|
+
RSpec.shared_examples 'a removal from the old parent' do
|
15
15
|
it 'calls #remove on the old parent with the Movable' do
|
16
16
|
expect(from).to receive(:remove).once.with(subject)
|
17
17
|
subject.move_to(to, :test)
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
-
shared_examples 'an addition to the new parent' do
|
21
|
+
RSpec.shared_examples 'an addition to the new parent' do
|
22
22
|
it 'calls #add on the new parent with the ID and Movable' do
|
23
23
|
expect(to).to_not be_nil
|
24
24
|
expect(to).to receive(:add).once.with(:test, subject)
|
@@ -26,7 +26,7 @@ shared_examples 'an addition to the new parent' do
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
-
shared_examples 'a movable object' do
|
29
|
+
RSpec.shared_examples 'a movable object' do
|
30
30
|
let(:old_parent) { double(:old_parent) }
|
31
31
|
let(:new_parent) { double(:new_parent) }
|
32
32
|
let(:remove_result) { subject }
|
data/spec/movable_spec.rb
CHANGED
data/spec/parent_tracker_spec.rb
CHANGED