interaktor 0.5.1 → 0.6.0.pre
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/README.md +79 -69
- data/interaktor.gemspec +2 -2
- data/lib/interaktor/attributes.rb +24 -0
- data/lib/interaktor/callable.rb +42 -262
- data/lib/interaktor/error/attribute_error.rb +2 -2
- data/lib/interaktor/error/attribute_validation_error.rb +20 -0
- data/lib/interaktor/error/missing_explicit_success_error.rb +7 -2
- data/lib/interaktor/error/organizer_missing_passed_attribute_error.rb +7 -7
- data/lib/interaktor/error/organizer_success_attribute_missing_error.rb +4 -4
- data/lib/interaktor/error/unknown_attribute_error.rb +4 -4
- data/lib/interaktor/interaction.rb +83 -29
- data/lib/interaktor/organizer.rb +7 -35
- data/lib/interaktor.rb +2 -18
- data/spec/interaktor/hooks_spec.rb +357 -363
- data/spec/interaktor/organizer_spec.rb +57 -48
- data/spec/support/helpers.rb +13 -2
- data/spec/support/lint.rb +219 -271
- metadata +11 -11
- data/lib/interaktor/error/attribute_schema_validation_error.rb +0 -54
- data/spec/interaktor/context_spec.rb +0 -187
|
@@ -1,460 +1,454 @@
|
|
|
1
|
-
|
|
1
|
+
RSpec.describe Interaktor::Hooks do
|
|
2
|
+
describe "#with_hooks" do
|
|
3
|
+
def build_hooked(&block)
|
|
4
|
+
hooked = Class.new.send(:include, Interaktor::Hooks)
|
|
2
5
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
describe "#with_hooks" do
|
|
6
|
-
def build_hooked(&block)
|
|
7
|
-
hooked = Class.new.send(:include, Interaktor::Hooks)
|
|
6
|
+
hooked.class_eval do
|
|
7
|
+
attr_reader :steps
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
def self.process
|
|
13
|
-
new.tap(&:process).steps
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def initialize
|
|
17
|
-
@steps = []
|
|
18
|
-
end
|
|
9
|
+
def self.process
|
|
10
|
+
new.tap(&:process).steps
|
|
11
|
+
end
|
|
19
12
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
end
|
|
13
|
+
def initialize
|
|
14
|
+
@steps = []
|
|
23
15
|
end
|
|
24
16
|
|
|
25
|
-
|
|
26
|
-
|
|
17
|
+
def process
|
|
18
|
+
with_hooks { steps << :process }
|
|
19
|
+
end
|
|
27
20
|
end
|
|
28
21
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
around :add_around_before_and_around_after
|
|
22
|
+
hooked.class_eval(&block) if block
|
|
23
|
+
hooked
|
|
24
|
+
end
|
|
33
25
|
|
|
34
|
-
|
|
26
|
+
context "with an around hook method" do
|
|
27
|
+
let(:hooked) {
|
|
28
|
+
build_hooked do
|
|
29
|
+
around :add_around_before_and_around_after
|
|
35
30
|
|
|
36
|
-
|
|
37
|
-
steps << :around_before
|
|
38
|
-
hooked.call
|
|
39
|
-
steps << :around_after
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
}
|
|
31
|
+
private
|
|
43
32
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
:
|
|
48
|
-
|
|
49
|
-
])
|
|
33
|
+
def add_around_before_and_around_after(hooked)
|
|
34
|
+
steps << :around_before
|
|
35
|
+
hooked.call
|
|
36
|
+
steps << :around_after
|
|
37
|
+
end
|
|
50
38
|
end
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
it "runs the around hook method" do
|
|
42
|
+
expect(hooked.process).to eq([
|
|
43
|
+
:around_before,
|
|
44
|
+
:process,
|
|
45
|
+
:around_after
|
|
46
|
+
])
|
|
51
47
|
end
|
|
48
|
+
end
|
|
52
49
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
end
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
it "runs the around hook block" do
|
|
65
|
-
expect(hooked.process).to eq([
|
|
66
|
-
:around_before,
|
|
67
|
-
:process,
|
|
68
|
-
:around_after
|
|
69
|
-
])
|
|
50
|
+
context "with an around hook block" do
|
|
51
|
+
let(:hooked) {
|
|
52
|
+
build_hooked do
|
|
53
|
+
around do |hooked|
|
|
54
|
+
steps << :around_before
|
|
55
|
+
hooked.call
|
|
56
|
+
steps << :around_after
|
|
57
|
+
end
|
|
70
58
|
end
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
it "runs the around hook block" do
|
|
62
|
+
expect(hooked.process).to eq([
|
|
63
|
+
:around_before,
|
|
64
|
+
:process,
|
|
65
|
+
:around_after
|
|
66
|
+
])
|
|
71
67
|
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
context "with an around hook method and block in one call" do
|
|
71
|
+
let(:hooked) {
|
|
72
|
+
build_hooked do
|
|
73
|
+
around :add_around_before1_and_around_after1 do |hooked|
|
|
74
|
+
steps << :around_before2
|
|
75
|
+
hooked.call
|
|
76
|
+
steps << :around_after2
|
|
77
|
+
end
|
|
72
78
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
private
|
|
83
|
-
|
|
84
|
-
def add_around_before1_and_around_after1(hooked)
|
|
85
|
-
steps << :around_before1
|
|
86
|
-
hooked.call
|
|
87
|
-
steps << :around_after1
|
|
88
|
-
end
|
|
89
|
-
end
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
it "runs the around hook method and block in order" do
|
|
93
|
-
expect(hooked.process).to eq([
|
|
94
|
-
:around_before1,
|
|
95
|
-
:around_before2,
|
|
96
|
-
:process,
|
|
97
|
-
:around_after2,
|
|
98
|
-
:around_after1
|
|
99
|
-
])
|
|
79
|
+
private
|
|
80
|
+
|
|
81
|
+
def add_around_before1_and_around_after1(hooked)
|
|
82
|
+
steps << :around_before1
|
|
83
|
+
hooked.call
|
|
84
|
+
steps << :around_after1
|
|
85
|
+
end
|
|
100
86
|
end
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
it "runs the around hook method and block in order" do
|
|
90
|
+
expect(hooked.process).to eq([
|
|
91
|
+
:around_before1,
|
|
92
|
+
:around_before2,
|
|
93
|
+
:process,
|
|
94
|
+
:around_after2,
|
|
95
|
+
:around_after1
|
|
96
|
+
])
|
|
101
97
|
end
|
|
98
|
+
end
|
|
102
99
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
end
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
it "runs the around hook block and method in order" do
|
|
125
|
-
expect(hooked.process).to eq([
|
|
126
|
-
:around_before1,
|
|
127
|
-
:around_before2,
|
|
128
|
-
:process,
|
|
129
|
-
:around_after2,
|
|
130
|
-
:around_after1
|
|
131
|
-
])
|
|
100
|
+
context "with an around hook method and block in multiple calls" do
|
|
101
|
+
let(:hooked) {
|
|
102
|
+
build_hooked do
|
|
103
|
+
around do |hooked|
|
|
104
|
+
steps << :around_before1
|
|
105
|
+
hooked.call
|
|
106
|
+
steps << :around_after1
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
around :add_around_before2_and_around_after2
|
|
110
|
+
|
|
111
|
+
private
|
|
112
|
+
|
|
113
|
+
def add_around_before2_and_around_after2(hooked)
|
|
114
|
+
steps << :around_before2
|
|
115
|
+
hooked.call
|
|
116
|
+
steps << :around_after2
|
|
117
|
+
end
|
|
132
118
|
end
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
it "runs the around hook block and method in order" do
|
|
122
|
+
expect(hooked.process).to eq([
|
|
123
|
+
:around_before1,
|
|
124
|
+
:around_before2,
|
|
125
|
+
:process,
|
|
126
|
+
:around_after2,
|
|
127
|
+
:around_after1
|
|
128
|
+
])
|
|
133
129
|
end
|
|
130
|
+
end
|
|
134
131
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
132
|
+
context "with a before hook method" do
|
|
133
|
+
let(:hooked) {
|
|
134
|
+
build_hooked do
|
|
135
|
+
before :add_before
|
|
139
136
|
|
|
140
|
-
|
|
137
|
+
private
|
|
141
138
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
end
|
|
139
|
+
def add_before
|
|
140
|
+
steps << :before
|
|
145
141
|
end
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
it "runs the before hook method" do
|
|
149
|
-
expect(hooked.process).to eq([
|
|
150
|
-
:before,
|
|
151
|
-
:process
|
|
152
|
-
])
|
|
153
142
|
end
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
it "runs the before hook method" do
|
|
146
|
+
expect(hooked.process).to eq([
|
|
147
|
+
:before,
|
|
148
|
+
:process
|
|
149
|
+
])
|
|
154
150
|
end
|
|
151
|
+
end
|
|
155
152
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
end
|
|
153
|
+
context "with a before hook block" do
|
|
154
|
+
let(:hooked) {
|
|
155
|
+
build_hooked do
|
|
156
|
+
before do
|
|
157
|
+
steps << :before
|
|
162
158
|
end
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
it "runs the before hook block" do
|
|
166
|
-
expect(hooked.process).to eq([
|
|
167
|
-
:before,
|
|
168
|
-
:process
|
|
169
|
-
])
|
|
170
159
|
end
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
it "runs the before hook block" do
|
|
163
|
+
expect(hooked.process).to eq([
|
|
164
|
+
:before,
|
|
165
|
+
:process
|
|
166
|
+
])
|
|
171
167
|
end
|
|
168
|
+
end
|
|
172
169
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
170
|
+
context "with a before hook method and block in one call" do
|
|
171
|
+
let(:hooked) {
|
|
172
|
+
build_hooked do
|
|
173
|
+
before :add_before1 do
|
|
174
|
+
steps << :before2
|
|
175
|
+
end
|
|
179
176
|
|
|
180
|
-
|
|
177
|
+
private
|
|
181
178
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
end
|
|
179
|
+
def add_before1
|
|
180
|
+
steps << :before1
|
|
185
181
|
end
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
it "runs the before hook method and block in order" do
|
|
189
|
-
expect(hooked.process).to eq([
|
|
190
|
-
:before1,
|
|
191
|
-
:before2,
|
|
192
|
-
:process
|
|
193
|
-
])
|
|
194
182
|
end
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
it "runs the before hook method and block in order" do
|
|
186
|
+
expect(hooked.process).to eq([
|
|
187
|
+
:before1,
|
|
188
|
+
:before2,
|
|
189
|
+
:process
|
|
190
|
+
])
|
|
195
191
|
end
|
|
192
|
+
end
|
|
196
193
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
194
|
+
context "with a before hook method and block in multiple calls" do
|
|
195
|
+
let(:hooked) {
|
|
196
|
+
build_hooked do
|
|
197
|
+
before do
|
|
198
|
+
steps << :before1
|
|
199
|
+
end
|
|
203
200
|
|
|
204
|
-
|
|
201
|
+
before :add_before2
|
|
205
202
|
|
|
206
|
-
|
|
203
|
+
private
|
|
207
204
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
end
|
|
205
|
+
def add_before2
|
|
206
|
+
steps << :before2
|
|
211
207
|
end
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
it "runs the before hook block and method in order" do
|
|
215
|
-
expect(hooked.process).to eq([
|
|
216
|
-
:before1,
|
|
217
|
-
:before2,
|
|
218
|
-
:process
|
|
219
|
-
])
|
|
220
208
|
end
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
it "runs the before hook block and method in order" do
|
|
212
|
+
expect(hooked.process).to eq([
|
|
213
|
+
:before1,
|
|
214
|
+
:before2,
|
|
215
|
+
:process
|
|
216
|
+
])
|
|
221
217
|
end
|
|
218
|
+
end
|
|
222
219
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
220
|
+
context "with an after hook method" do
|
|
221
|
+
let(:hooked) {
|
|
222
|
+
build_hooked do
|
|
223
|
+
after :add_after
|
|
227
224
|
|
|
228
|
-
|
|
225
|
+
private
|
|
229
226
|
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
end
|
|
227
|
+
def add_after
|
|
228
|
+
steps << :after
|
|
233
229
|
end
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
it "runs the after hook method" do
|
|
237
|
-
expect(hooked.process).to eq([
|
|
238
|
-
:process,
|
|
239
|
-
:after
|
|
240
|
-
])
|
|
241
230
|
end
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
it "runs the after hook method" do
|
|
234
|
+
expect(hooked.process).to eq([
|
|
235
|
+
:process,
|
|
236
|
+
:after
|
|
237
|
+
])
|
|
242
238
|
end
|
|
239
|
+
end
|
|
243
240
|
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
end
|
|
241
|
+
context "with an after hook block" do
|
|
242
|
+
let(:hooked) {
|
|
243
|
+
build_hooked do
|
|
244
|
+
after do
|
|
245
|
+
steps << :after
|
|
250
246
|
end
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
it "runs the after hook block" do
|
|
254
|
-
expect(hooked.process).to eq([
|
|
255
|
-
:process,
|
|
256
|
-
:after
|
|
257
|
-
])
|
|
258
247
|
end
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
it "runs the after hook block" do
|
|
251
|
+
expect(hooked.process).to eq([
|
|
252
|
+
:process,
|
|
253
|
+
:after
|
|
254
|
+
])
|
|
259
255
|
end
|
|
256
|
+
end
|
|
260
257
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
258
|
+
context "with an after hook method and block in one call" do
|
|
259
|
+
let(:hooked) {
|
|
260
|
+
build_hooked do
|
|
261
|
+
after :add_after1 do
|
|
262
|
+
steps << :after2
|
|
263
|
+
end
|
|
267
264
|
|
|
268
|
-
|
|
265
|
+
private
|
|
269
266
|
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
end
|
|
267
|
+
def add_after1
|
|
268
|
+
steps << :after1
|
|
273
269
|
end
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
it "runs the after hook method and block in order" do
|
|
277
|
-
expect(hooked.process).to eq([
|
|
278
|
-
:process,
|
|
279
|
-
:after2,
|
|
280
|
-
:after1
|
|
281
|
-
])
|
|
282
270
|
end
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
it "runs the after hook method and block in order" do
|
|
274
|
+
expect(hooked.process).to eq([
|
|
275
|
+
:process,
|
|
276
|
+
:after2,
|
|
277
|
+
:after1
|
|
278
|
+
])
|
|
283
279
|
end
|
|
280
|
+
end
|
|
284
281
|
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
282
|
+
context "with an after hook method and block in multiple calls" do
|
|
283
|
+
let(:hooked) {
|
|
284
|
+
build_hooked do
|
|
285
|
+
after do
|
|
286
|
+
steps << :after1
|
|
287
|
+
end
|
|
291
288
|
|
|
292
|
-
|
|
289
|
+
after :add_after2
|
|
293
290
|
|
|
294
|
-
|
|
291
|
+
private
|
|
295
292
|
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
end
|
|
293
|
+
def add_after2
|
|
294
|
+
steps << :after2
|
|
299
295
|
end
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
it "runs the after hook block and method in order" do
|
|
303
|
-
expect(hooked.process).to eq([
|
|
304
|
-
:process,
|
|
305
|
-
:after2,
|
|
306
|
-
:after1
|
|
307
|
-
])
|
|
308
296
|
end
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
it "runs the after hook block and method in order" do
|
|
300
|
+
expect(hooked.process).to eq([
|
|
301
|
+
:process,
|
|
302
|
+
:after2,
|
|
303
|
+
:after1
|
|
304
|
+
])
|
|
309
305
|
end
|
|
306
|
+
end
|
|
310
307
|
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
308
|
+
context "with an ensure_hook method" do
|
|
309
|
+
let(:hooked) {
|
|
310
|
+
build_hooked do
|
|
311
|
+
ensure_hook :add_ensure
|
|
315
312
|
|
|
316
|
-
|
|
313
|
+
private
|
|
317
314
|
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
end
|
|
315
|
+
def add_ensure
|
|
316
|
+
steps << :ensure
|
|
321
317
|
end
|
|
322
|
-
|
|
318
|
+
end
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
it "runs the after hook method" do
|
|
322
|
+
expect(hooked.process).to eq([
|
|
323
|
+
:process,
|
|
324
|
+
:ensure
|
|
325
|
+
])
|
|
326
|
+
end
|
|
327
|
+
end
|
|
323
328
|
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
+
context "with an ensure_hook block" do
|
|
330
|
+
let(:hooked) {
|
|
331
|
+
build_hooked do
|
|
332
|
+
ensure_hook do
|
|
333
|
+
steps << :ensure
|
|
334
|
+
end
|
|
329
335
|
end
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
it "runs the after hook block" do
|
|
339
|
+
expect(hooked.process).to eq([
|
|
340
|
+
:process,
|
|
341
|
+
:ensure
|
|
342
|
+
])
|
|
330
343
|
end
|
|
344
|
+
end
|
|
331
345
|
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
end
|
|
346
|
+
context "with an ensure_hook method and block in one call" do
|
|
347
|
+
let(:hooked) {
|
|
348
|
+
build_hooked do
|
|
349
|
+
ensure_hook :add_ensure1 do
|
|
350
|
+
steps << :ensure2
|
|
338
351
|
end
|
|
339
|
-
}
|
|
340
352
|
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
:
|
|
345
|
-
|
|
353
|
+
private
|
|
354
|
+
|
|
355
|
+
def add_ensure1
|
|
356
|
+
steps << :ensure1
|
|
357
|
+
end
|
|
346
358
|
end
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
it "runs the ensure_hook method and block in order" do
|
|
362
|
+
expect(hooked.process).to eq([
|
|
363
|
+
:process,
|
|
364
|
+
:ensure1,
|
|
365
|
+
:ensure2
|
|
366
|
+
])
|
|
347
367
|
end
|
|
368
|
+
end
|
|
348
369
|
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
370
|
+
context "with an ensure_hook method and block in multiple calls" do
|
|
371
|
+
let(:hooked) {
|
|
372
|
+
build_hooked do
|
|
373
|
+
ensure_hook do
|
|
374
|
+
steps << :ensure1
|
|
375
|
+
end
|
|
355
376
|
|
|
356
|
-
|
|
377
|
+
ensure_hook :add_ensure2
|
|
357
378
|
|
|
358
|
-
|
|
359
|
-
steps << :ensure1
|
|
360
|
-
end
|
|
361
|
-
end
|
|
362
|
-
}
|
|
379
|
+
private
|
|
363
380
|
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
:ensure1,
|
|
368
|
-
:ensure2
|
|
369
|
-
])
|
|
381
|
+
def add_ensure2
|
|
382
|
+
steps << :ensure2
|
|
383
|
+
end
|
|
370
384
|
end
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
it "runs the ensure_hook block and method in order" do
|
|
388
|
+
expect(hooked.process).to eq([
|
|
389
|
+
:process,
|
|
390
|
+
:ensure1,
|
|
391
|
+
:ensure2
|
|
392
|
+
])
|
|
371
393
|
end
|
|
394
|
+
end
|
|
395
|
+
|
|
396
|
+
context "with around, before, after and ensure_hook hooks" do
|
|
397
|
+
let(:hooked) {
|
|
398
|
+
build_hooked do
|
|
399
|
+
around do |hooked|
|
|
400
|
+
steps << :around_before1
|
|
401
|
+
hooked.call
|
|
402
|
+
steps << :around_after1
|
|
403
|
+
end
|
|
404
|
+
|
|
405
|
+
around do |hooked|
|
|
406
|
+
steps << :around_before2
|
|
407
|
+
hooked.call
|
|
408
|
+
steps << :around_after2
|
|
409
|
+
end
|
|
372
410
|
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
ensure_hook do
|
|
377
|
-
steps << :ensure1
|
|
378
|
-
end
|
|
411
|
+
before do
|
|
412
|
+
steps << :before1
|
|
413
|
+
end
|
|
379
414
|
|
|
380
|
-
|
|
415
|
+
before do
|
|
416
|
+
steps << :before2
|
|
417
|
+
end
|
|
381
418
|
|
|
382
|
-
|
|
419
|
+
after do
|
|
420
|
+
steps << :after1
|
|
421
|
+
end
|
|
383
422
|
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
end
|
|
423
|
+
after do
|
|
424
|
+
steps << :after2
|
|
387
425
|
end
|
|
388
|
-
}
|
|
389
426
|
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
:ensure1,
|
|
394
|
-
:ensure2
|
|
395
|
-
])
|
|
396
|
-
end
|
|
397
|
-
end
|
|
427
|
+
ensure_hook do
|
|
428
|
+
steps << :ensure1
|
|
429
|
+
end
|
|
398
430
|
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
around do |hooked|
|
|
403
|
-
steps << :around_before1
|
|
404
|
-
hooked.call
|
|
405
|
-
steps << :around_after1
|
|
406
|
-
end
|
|
407
|
-
|
|
408
|
-
around do |hooked|
|
|
409
|
-
steps << :around_before2
|
|
410
|
-
hooked.call
|
|
411
|
-
steps << :around_after2
|
|
412
|
-
end
|
|
413
|
-
|
|
414
|
-
before do
|
|
415
|
-
steps << :before1
|
|
416
|
-
end
|
|
417
|
-
|
|
418
|
-
before do
|
|
419
|
-
steps << :before2
|
|
420
|
-
end
|
|
421
|
-
|
|
422
|
-
after do
|
|
423
|
-
steps << :after1
|
|
424
|
-
end
|
|
425
|
-
|
|
426
|
-
after do
|
|
427
|
-
steps << :after2
|
|
428
|
-
end
|
|
429
|
-
|
|
430
|
-
ensure_hook do
|
|
431
|
-
steps << :ensure1
|
|
432
|
-
end
|
|
433
|
-
|
|
434
|
-
ensure_hook do
|
|
435
|
-
steps << :ensure2
|
|
436
|
-
end
|
|
437
|
-
end
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
it "runs hooks in the proper order" do
|
|
441
|
-
expect(hooked.process).to eq([
|
|
442
|
-
:around_before1,
|
|
443
|
-
:around_before2,
|
|
444
|
-
:before1,
|
|
445
|
-
:before2,
|
|
446
|
-
:process,
|
|
447
|
-
:after2,
|
|
448
|
-
:after1,
|
|
449
|
-
:around_after2,
|
|
450
|
-
:around_after1,
|
|
451
|
-
:ensure1,
|
|
452
|
-
:ensure2
|
|
453
|
-
])
|
|
431
|
+
ensure_hook do
|
|
432
|
+
steps << :ensure2
|
|
433
|
+
end
|
|
454
434
|
end
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
it "runs hooks in the proper order" do
|
|
438
|
+
expect(hooked.process).to eq([
|
|
439
|
+
:around_before1,
|
|
440
|
+
:around_before2,
|
|
441
|
+
:before1,
|
|
442
|
+
:before2,
|
|
443
|
+
:process,
|
|
444
|
+
:after2,
|
|
445
|
+
:after1,
|
|
446
|
+
:around_after2,
|
|
447
|
+
:around_after1,
|
|
448
|
+
:ensure1,
|
|
449
|
+
:ensure2
|
|
450
|
+
])
|
|
455
451
|
end
|
|
456
452
|
end
|
|
457
453
|
end
|
|
458
454
|
end
|
|
459
|
-
|
|
460
|
-
# rubocop:enable RSpec/ScatteredSetup
|