light-service 0.10.1 → 0.10.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1f6b68783827acc1479c9728d2483dcba8c9c0e7
4
- data.tar.gz: 0446e28166fd582394cb74819e855d26241e0393
3
+ metadata.gz: 839bc255742513ba7c0cabc80bd8f72e35d4a442
4
+ data.tar.gz: 5957a2d95ac83d37cb9ba40629446ba4952ab835
5
5
  SHA512:
6
- metadata.gz: 6ac7178a1ea5e9fa7cd22a16de9533c953b504b5a999c26912fbb512e578cd1dcde66fc44d4414b56bf6e0c5be4d679b85b595bdc4e708cc6ac1bbd177a61e94
7
- data.tar.gz: 5a881eca505d834cbf1b270215c0134f9b6d831fa37c29ca2737dec6d3fec6de9e224d0683f704e635301d6c9b47eb545e6e165d0c5a6aa69fd8f2b621e34376
6
+ metadata.gz: 2c992973e9289bbf41dd73f77f9ee2e12d1e6bc2f55ad0d6af293e026a785931ee52dabe6ce2b5d85cf00afb86ffdf1218087a3cb1bdb6b525fa102ddd800a8c
7
+ data.tar.gz: 7663059f0fad0ee5235306928110b6f7c5d77a057e0c34055fa9ac5eaae5756308855532023348c1a968120d8ed6b8a97649e8db5a7a3e973f3b69cc98dc1f7a
@@ -1,5 +1,8 @@
1
1
  A brief list of new features and changes introduced with the specified version.
2
2
 
3
+ ### 0.10.2
4
+ * [Revert 0.10.1](https://github.com/adomokos/light-service/pull/146), it breaks tests in our apps :-(.
5
+
3
6
  ### 0.10.1
4
7
  * [Fixing ContextFactory](https://github.com/adomokos/light-service/pull/141) for orchestrator methods in Organizers.
5
8
 
@@ -1,6 +1,17 @@
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
+
4
15
  attr_reader :organizer
5
16
 
6
17
  def self.make_from(organizer)
@@ -8,28 +19,25 @@ module LightService
8
19
  end
9
20
 
10
21
  def for(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
-
22
+ ContextFactoryOrganizer.actions = find_up_to(action)
19
23
  self
20
24
  end
21
25
 
22
26
  def with(ctx)
23
- escaped = catch(:return_ctx_from_execution) do
24
- @organizer.call(ctx)
25
- end
26
-
27
- escaped
27
+ ContextFactoryOrganizer.call(ctx)
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
33
41
  end
34
42
  end
35
43
  end
@@ -1,3 +1,3 @@
1
1
  module LightService
2
- VERSION = "0.10.1".freeze
2
+ VERSION = "0.10.2".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)
11
+ .with(:number => number)
12
12
  end
13
13
  end
14
14
 
@@ -26,20 +26,8 @@ RSpec.describe TestDoubles::AddsThreeAction do
26
26
  LightService::Testing::ContextFactory
27
27
  .make_from(TestDoubles::AdditionOrganizer)
28
28
  .for(TestDoubles::AddsThreeAction)
29
- .with(4) # Context is a "glorified" hash
29
+ .with(:number => 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
@@ -251,99 +251,6 @@ 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
-
347
254
  class MakesTeaExpectingReservedKey
348
255
  extend LightService::Action
349
256
  expects :tea, :message
@@ -2,15 +2,13 @@ require 'spec_helper'
2
2
  require 'test_doubles'
3
3
 
4
4
  describe 'ContextFactory - used with AdditionOrganizer' do
5
- let(:organizer) { TestDoubles::AdditionOrganizer }
6
-
7
5
  context 'when called with the first action' do
8
6
  it 'does not alter the context' do
9
7
  ctx =
10
8
  LightService::Testing::ContextFactory
11
- .make_from(organizer)
9
+ .make_from(TestDoubles::AdditionOrganizer)
12
10
  .for(TestDoubles::AddsOneAction)
13
- .with(1)
11
+ .with(:number => 1)
14
12
 
15
13
  expect(ctx[:number]).to eq(1)
16
14
  end
@@ -20,9 +18,9 @@ describe 'ContextFactory - used with AdditionOrganizer' do
20
18
  it 'adds one to the number provided' do
21
19
  ctx =
22
20
  LightService::Testing::ContextFactory
23
- .make_from(organizer)
21
+ .make_from(TestDoubles::AdditionOrganizer)
24
22
  .for(TestDoubles::AddsTwoAction)
25
- .with(1)
23
+ .with(:number => 1)
26
24
 
27
25
  expect(ctx.number).to eq(2)
28
26
  end
@@ -32,9 +30,9 @@ describe 'ContextFactory - used with AdditionOrganizer' do
32
30
  it 'creates a context up-to the action defined' do
33
31
  ctx =
34
32
  LightService::Testing::ContextFactory
35
- .make_from(organizer)
33
+ .make_from(TestDoubles::AdditionOrganizer)
36
34
  .for(TestDoubles::AddsThreeAction)
37
- .with(1)
35
+ .with(:number => 1)
38
36
 
39
37
  expect(ctx.number).to eq(4)
40
38
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: light-service
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.1
4
+ version: 0.10.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Attila Domokos
@@ -179,10 +179,6 @@ 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
186
182
  - spec/testing/context_factory_spec.rb
187
183
  homepage: https://github.com/adomokos/light-service
188
184
  licenses:
@@ -256,8 +252,4 @@ test_files:
256
252
  - spec/spec_helper.rb
257
253
  - spec/support.rb
258
254
  - 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
263
255
  - spec/testing/context_factory_spec.rb
@@ -1,39 +0,0 @@
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
@@ -1,40 +0,0 @@
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
@@ -1,40 +0,0 @@
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
@@ -1,38 +0,0 @@
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