light-service 0.10.0 → 0.10.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 24c5a758ab50b3cd0ec404ef0b8a426a3e77e42b
4
- data.tar.gz: 03ec6d27e900c9685bd141340c2b191df781ab84
3
+ metadata.gz: 1f6b68783827acc1479c9728d2483dcba8c9c0e7
4
+ data.tar.gz: 0446e28166fd582394cb74819e855d26241e0393
5
5
  SHA512:
6
- metadata.gz: ef89eee65b07381b629c9f4b8e5aad0e4e719e370e8aa84c32a23f65824d42c3e9c14424810b8518a244df4769b3f2e4f22a1752f6c498e44e146b803041bff3
7
- data.tar.gz: 3476522df0af4775eff555a986d0dffbfed8dad3c0cd77a7a5eb19ca25b39c7109c8da8756a30625d39bf89e10fb7a54fd6212c15955bc544c37e66f2be6293d
6
+ metadata.gz: 6ac7178a1ea5e9fa7cd22a16de9533c953b504b5a999c26912fbb512e578cd1dcde66fc44d4414b56bf6e0c5be4d679b85b595bdc4e708cc6ac1bbd177a61e94
7
+ data.tar.gz: 5a881eca505d834cbf1b270215c0134f9b6d831fa37c29ca2737dec6d3fec6de9e224d0683f704e635301d6c9b47eb545e6e165d0c5a6aa69fd8f2b621e34376
data/RELEASES.md CHANGED
@@ -1,5 +1,8 @@
1
1
  A brief list of new features and changes introduced with the specified version.
2
2
 
3
+ ### 0.10.1
4
+ * [Fixing ContextFactory](https://github.com/adomokos/light-service/pull/141) for orchestrator methods in Organizers.
5
+
3
6
  ### 0.10.0
4
7
  * Adding [before_actions and after_actions hooks](https://github.com/adomokos/light-service/pull/144).
5
8
 
@@ -1,17 +1,6 @@
1
1
  module LightService
2
2
  module Testing
3
3
  class ContextFactory
4
- class ContextFactoryOrganizer
5
- extend LightService::Organizer
6
- class << self
7
- attr_accessor :actions
8
- end
9
-
10
- def self.call(ctx)
11
- with(ctx).reduce(actions)
12
- end
13
- end
14
-
15
4
  attr_reader :organizer
16
5
 
17
6
  def self.make_from(organizer)
@@ -19,25 +8,28 @@ module LightService
19
8
  end
20
9
 
21
10
  def for(action)
22
- ContextFactoryOrganizer.actions = find_up_to(action)
11
+ @organizer.before_actions = [
12
+ lambda do |ctx|
13
+ if ctx.current_action == action
14
+ throw(:return_ctx_from_execution, ctx)
15
+ end
16
+ end
17
+ ]
18
+
23
19
  self
24
20
  end
25
21
 
26
22
  def with(ctx)
27
- ContextFactoryOrganizer.call(ctx)
23
+ escaped = catch(:return_ctx_from_execution) do
24
+ @organizer.call(ctx)
25
+ end
26
+
27
+ escaped
28
28
  end
29
29
 
30
30
  def initialize(organizer)
31
31
  @organizer = organizer
32
32
  end
33
-
34
- def find_up_to(action)
35
- original_actions = organizer.actions
36
-
37
- original_actions.take_while do |current_action|
38
- current_action != action
39
- end
40
- end
41
33
  end
42
34
  end
43
35
  end
@@ -1,3 +1,3 @@
1
1
  module LightService
2
- VERSION = "0.10.0".freeze
2
+ VERSION = "0.10.1".freeze
3
3
  end
@@ -8,7 +8,7 @@ class AdditionOrganizerContextFactory
8
8
  LightService::Testing::ContextFactory
9
9
  .make_from(TestDoubles::AdditionOrganizer)
10
10
  .for(action)
11
- .with(:number => number)
11
+ .with(number)
12
12
  end
13
13
  end
14
14
 
@@ -26,8 +26,20 @@ RSpec.describe TestDoubles::AddsThreeAction do
26
26
  LightService::Testing::ContextFactory
27
27
  .make_from(TestDoubles::AdditionOrganizer)
28
28
  .for(TestDoubles::AddsThreeAction)
29
- .with(:number => 4) # Context is a "glorified" hash
29
+ .with(4) # Context is a "glorified" hash
30
30
 
31
31
  expect(context.number).to eq(7)
32
32
  end
33
33
  end
34
+
35
+ RSpec.describe TestDoubles::AddsTwoAction do
36
+ it "does not execute a callback entirely from a ContextFactory" do
37
+ context = LightService::Testing::ContextFactory
38
+ .make_from(TestDoubles::CallbackOrganizer)
39
+ .for(described_class)
40
+ .with(:number => 0)
41
+
42
+ # add 1, add 10, then stop before executing first add 2
43
+ expect(context.number).to eq(11)
44
+ end
45
+ end
data/spec/test_doubles.rb CHANGED
@@ -251,6 +251,99 @@ module TestDoubles
251
251
  end
252
252
  end
253
253
 
254
+ class IterateOrganizer
255
+ extend LightService::Organizer
256
+
257
+ def self.call(ctx)
258
+ with(ctx).reduce(actions)
259
+ end
260
+
261
+ def self.actions
262
+ [
263
+ AddsOneIteratesAction,
264
+ iterate(:numbers, [
265
+ AddsTwoAction,
266
+ AddsThreeAction
267
+ ])
268
+ ]
269
+ end
270
+ end
271
+
272
+ class AddsOneIteratesAction
273
+ extend LightService::Action
274
+ expects :numbers
275
+ promises :numbers
276
+
277
+ executed do |context|
278
+ context.numbers = context.numbers.map { |n| n + 1 }
279
+ end
280
+ end
281
+
282
+ class CallbackOrganizer
283
+ extend LightService::Organizer
284
+
285
+ def self.call(ctx)
286
+ with(ctx).reduce(actions)
287
+ end
288
+
289
+ def self.actions
290
+ [
291
+ AddsOneAction,
292
+ with_callback(AddTenCallbackAction, [
293
+ AddsTwoAction,
294
+ AddsThreeAction
295
+ ])
296
+ ]
297
+ end
298
+ end
299
+
300
+ class AddTenCallbackAction
301
+ extend LightService::Action
302
+ expects :number, :callback
303
+
304
+ executed do |context|
305
+ context.number += 10
306
+ context.number =
307
+ context.callback.call(context).fetch(:number)
308
+ end
309
+ end
310
+
311
+ class ReduceUntilOrganizer
312
+ extend LightService::Organizer
313
+
314
+ def self.call(ctx)
315
+ with(ctx).reduce(actions)
316
+ end
317
+
318
+ def self.actions
319
+ [
320
+ AddsOneAction,
321
+ reduce_until(->(ctx) { ctx.number > 3 }, [
322
+ AddsTwoAction,
323
+ AddsThreeAction
324
+ ])
325
+ ]
326
+ end
327
+ end
328
+
329
+ class ReduceIfOrganizer
330
+ extend LightService::Organizer
331
+
332
+ def self.call(ctx)
333
+ with(ctx).reduce(actions)
334
+ end
335
+
336
+ def self.actions
337
+ [
338
+ AddsOneAction,
339
+ reduce_if(->(ctx) { ctx.number > 1 }, [
340
+ AddsTwoAction,
341
+ AddsThreeAction
342
+ ])
343
+ ]
344
+ end
345
+ end
346
+
254
347
  class MakesTeaExpectingReservedKey
255
348
  extend LightService::Action
256
349
  expects :tea, :message
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+ require 'test_doubles'
3
+
4
+ RSpec.describe 'ContextFactory - used with IterateOrganizer' do
5
+ let(:organizer) { TestDoubles::IterateOrganizer }
6
+
7
+ context 'when called with outside iterate steps' do
8
+ it 'creates a context up-to the action defined before the iteration' do
9
+ ctx =
10
+ LightService::Testing::ContextFactory
11
+ .make_from(organizer)
12
+ .for(TestDoubles::AddsOneIteratesAction)
13
+ .with(:numbers => [1, 2])
14
+
15
+ expect(ctx[:numbers]).to eq([1, 2])
16
+ end
17
+
18
+ it 'creates a context up-to iteration with empty context steps' do
19
+ ctx =
20
+ LightService::Testing::ContextFactory
21
+ .make_from(organizer)
22
+ .for(TestDoubles::AddsTwoAction)
23
+ .with(:numbers => [1, 2])
24
+
25
+ expect(ctx.numbers).to eq([2, 3])
26
+ end
27
+
28
+ it 'creates a context only to the first step of the iteration' do
29
+ ctx =
30
+ LightService::Testing::ContextFactory
31
+ .make_from(organizer)
32
+ .for(TestDoubles::AddsThreeAction)
33
+ .with(:numbers => [1, 2])
34
+
35
+ expect(ctx.numbers).to eq([2, 3])
36
+ expect(ctx.number).to eq(4)
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,40 @@
1
+ require 'spec_helper'
2
+ require 'test_doubles'
3
+
4
+ RSpec.describe 'ContextFactory - used with ReduceIfOrganizer' do
5
+ let(:organizer) { TestDoubles::ReduceIfOrganizer }
6
+
7
+ context 'when called with a truthy argument action' do
8
+ it 'executes a context up-to the callback action' do
9
+ ctx =
10
+ LightService::Testing::ContextFactory
11
+ .make_from(organizer)
12
+ .for(TestDoubles::AddsThreeAction)
13
+ .with(:number => 1)
14
+
15
+ expect(ctx.number).to eq(4)
16
+ end
17
+
18
+ it 'creates a context up-to action with empty context steps' do
19
+ ctx =
20
+ LightService::Testing::ContextFactory
21
+ .make_from(organizer)
22
+ .for(TestDoubles::AddsTwoAction)
23
+ .with(:number => 1)
24
+
25
+ expect(ctx.number).to eq(2)
26
+ end
27
+ end
28
+
29
+ context 'when called with a false argument action' do
30
+ it 'does not execute the steps' do
31
+ ctx =
32
+ LightService::Testing::ContextFactory
33
+ .make_from(organizer)
34
+ .for(TestDoubles::AddsThreeAction)
35
+ .with(:number => 0)
36
+
37
+ expect(ctx.number).to eq(1)
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,40 @@
1
+ require 'spec_helper'
2
+ require 'test_doubles'
3
+
4
+ RSpec.describe 'ContextFactory - used with ReduceUntilOrganizer' do
5
+ let(:organizer) { TestDoubles::ReduceUntilOrganizer }
6
+
7
+ context 'when called with truthy block' do
8
+ it 'creates a context up-to the action defined before the iteration' do
9
+ ctx =
10
+ LightService::Testing::ContextFactory
11
+ .make_from(organizer)
12
+ .for(TestDoubles::AddsTwoAction)
13
+ .with(:number => 1)
14
+
15
+ expect(ctx[:number]).to eq(2)
16
+ end
17
+
18
+ it 'creates a context only to the first step of the loop' do
19
+ ctx =
20
+ LightService::Testing::ContextFactory
21
+ .make_from(organizer)
22
+ .for(TestDoubles::AddsThreeAction)
23
+ .with(:number => 1)
24
+
25
+ expect(ctx.number).to eq(4)
26
+ end
27
+ end
28
+
29
+ context 'when called with falsey block' do
30
+ it 'creates a context up-to the first step' do
31
+ ctx =
32
+ LightService::Testing::ContextFactory
33
+ .make_from(organizer)
34
+ .for(TestDoubles::AddsThreeAction)
35
+ .with(:number => 7)
36
+
37
+ expect(ctx[:number]).to eq(10)
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+ require 'test_doubles'
3
+
4
+ RSpec.describe 'ContextFactory - used with CallbackOrganizer' do
5
+ let(:organizer) { TestDoubles::CallbackOrganizer }
6
+
7
+ context 'when called with the callback action' do
8
+ it 'creates a context up-to the callback action' do
9
+ ctx =
10
+ LightService::Testing::ContextFactory
11
+ .make_from(organizer)
12
+ .for(TestDoubles::AddTenCallbackAction)
13
+ .with(:number => 1)
14
+
15
+ expect(ctx.number).to eq(2)
16
+ end
17
+
18
+ it 'creates a context up-to callback action with empty context steps' do
19
+ ctx =
20
+ LightService::Testing::ContextFactory
21
+ .make_from(organizer)
22
+ .for(TestDoubles::AddsTwoAction)
23
+ .with(:number => 1)
24
+
25
+ expect(ctx.number).to eq(12)
26
+ end
27
+
28
+ it 'creates a context up-to the action defined in context steps' do
29
+ ctx =
30
+ LightService::Testing::ContextFactory
31
+ .make_from(organizer)
32
+ .for(TestDoubles::AddsThreeAction)
33
+ .with(:number => 1)
34
+
35
+ expect(ctx.number).to eq(14)
36
+ end
37
+ end
38
+ end
@@ -2,13 +2,15 @@ require 'spec_helper'
2
2
  require 'test_doubles'
3
3
 
4
4
  describe 'ContextFactory - used with AdditionOrganizer' do
5
+ let(:organizer) { TestDoubles::AdditionOrganizer }
6
+
5
7
  context 'when called with the first action' do
6
8
  it 'does not alter the context' do
7
9
  ctx =
8
10
  LightService::Testing::ContextFactory
9
- .make_from(TestDoubles::AdditionOrganizer)
11
+ .make_from(organizer)
10
12
  .for(TestDoubles::AddsOneAction)
11
- .with(:number => 1)
13
+ .with(1)
12
14
 
13
15
  expect(ctx[:number]).to eq(1)
14
16
  end
@@ -18,9 +20,9 @@ describe 'ContextFactory - used with AdditionOrganizer' do
18
20
  it 'adds one to the number provided' do
19
21
  ctx =
20
22
  LightService::Testing::ContextFactory
21
- .make_from(TestDoubles::AdditionOrganizer)
23
+ .make_from(organizer)
22
24
  .for(TestDoubles::AddsTwoAction)
23
- .with(:number => 1)
25
+ .with(1)
24
26
 
25
27
  expect(ctx.number).to eq(2)
26
28
  end
@@ -30,9 +32,9 @@ describe 'ContextFactory - used with AdditionOrganizer' do
30
32
  it 'creates a context up-to the action defined' do
31
33
  ctx =
32
34
  LightService::Testing::ContextFactory
33
- .make_from(TestDoubles::AdditionOrganizer)
35
+ .make_from(organizer)
34
36
  .for(TestDoubles::AddsThreeAction)
35
- .with(:number => 1)
37
+ .with(1)
36
38
 
37
39
  expect(ctx.number).to eq(4)
38
40
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: light-service
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 0.10.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Attila Domokos
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-29 00:00:00.000000000 Z
11
+ date: 2018-03-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -179,6 +179,10 @@ files:
179
179
  - spec/spec_helper.rb
180
180
  - spec/support.rb
181
181
  - spec/test_doubles.rb
182
+ - spec/testing/context_factory/iterate_spec.rb
183
+ - spec/testing/context_factory/reduce_if_spec.rb
184
+ - spec/testing/context_factory/reduce_until_spec.rb
185
+ - spec/testing/context_factory/with_callback_spec.rb
182
186
  - spec/testing/context_factory_spec.rb
183
187
  homepage: https://github.com/adomokos/light-service
184
188
  licenses:
@@ -252,4 +256,8 @@ test_files:
252
256
  - spec/spec_helper.rb
253
257
  - spec/support.rb
254
258
  - spec/test_doubles.rb
259
+ - spec/testing/context_factory/iterate_spec.rb
260
+ - spec/testing/context_factory/reduce_if_spec.rb
261
+ - spec/testing/context_factory/reduce_until_spec.rb
262
+ - spec/testing/context_factory/with_callback_spec.rb
255
263
  - spec/testing/context_factory_spec.rb