light-service 0.3.5 → 0.3.6

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: c74e129f4aa196c42077e14704239de1e3cdafec
4
- data.tar.gz: 47f5b3dd133c2ceec5b66ecf513a9dbd78559708
3
+ metadata.gz: fc46d59ad8bc4839942dc2977961ce978bae275f
4
+ data.tar.gz: a2ca45e8cb9987ab44dfe5af7080dd45a943efc7
5
5
  SHA512:
6
- metadata.gz: 496f22c177d5b14d0ba7d33fb6b54700e1a150e6a8683d29be30b7ec0304b24fb9daa8adac00f934c6b1f956e94d0330d020014a18450cbf89b98751b184f7f6
7
- data.tar.gz: 24f9965dcf22ec98ed9ebb9a3083111cce43f30e438d607ccecf2d7290ee1a61c0a6e400f935ea318708b883c0eefc56bd87c86dcf94bfb6830af7021f6e91bd
6
+ metadata.gz: 061d0554efd265aa95e83cd7197e24aa12207ea3c4119d297bbd036bc9ed15c5be44af52bcb9b00975b3d0a779f039a1008d6efae6d2ceffa562b65ce9f0cbf0
7
+ data.tar.gz: 66fe3f85032dc702b60edcb69cab36a2c6a6bd088f2f04a92a2554aff016d58889092f49baded959e6b161a3bd0490285ce0cc95de54647218cfb6d642ad7087
data/README.md CHANGED
@@ -273,6 +273,9 @@ For further examples, please visit the project's [Wiki](https://github.com/adomo
273
273
  Huge thanks to the [contributors](https://github.com/adomokos/light-service/graphs/contributors)!
274
274
 
275
275
  ## Release Notes
276
+ ### 0.3.6
277
+ * [Collecting](https://github.com/adomokos/light-service/commit/29817de3ad589441788077368ad1d7e723286def) the `expects` and `promises` keys when they are called multiple times in an action
278
+
276
279
  ### 0.3.5
277
280
  * remove previously deprecated method Context#context_hash
278
281
  * [Skipping](https://github.com/adomokos/light-service/commit/d2bd05455a7e4f78aa448db1ea1d692f7b8b67d3) the promised keys check in the context when the context is in failure state
@@ -7,11 +7,13 @@ module LightService
7
7
 
8
8
  module Macros
9
9
  def expects(*args)
10
- @_expected_keys = args
10
+ @_expected_keys ||= []
11
+ @_expected_keys.concat(args)
11
12
  end
12
13
 
13
14
  def promises(*args)
14
- @_promised_keys = args
15
+ @_promised_keys ||= []
16
+ @_promised_keys.concat(args)
15
17
  end
16
18
 
17
19
  def expected_keys
@@ -1,3 +1,3 @@
1
1
  module LightService
2
- VERSION = "0.3.5"
2
+ VERSION = "0.3.6"
3
3
  end
@@ -11,15 +11,6 @@ module LightService
11
11
  context.milk_tea = "#{context.tea} - #{context.milk}"
12
12
  end
13
13
  end
14
- class DummyActionForKeysToPromiseWithError
15
- include LightService::Action
16
- expects :tea, :milk
17
- promises :milk_tea
18
-
19
- executed do |context|
20
- context[:some_tea] = "#{context.tea} - #{context.milk}"
21
- end
22
- end
23
14
 
24
15
  context "when expected keys are in the context" do
25
16
  it "can access the keys as class methods" do
@@ -32,7 +23,7 @@ module LightService
32
23
  end
33
24
  end
34
25
 
35
- context "when expected key is not in the context" do
26
+ context "when an expected key is not in the context" do
36
27
  it "raises an error" do
37
28
  exception_error_text = "expected :milk to be in the context during LightService::DummyActionForKeysToExpect"
38
29
  expect {
@@ -41,13 +32,24 @@ module LightService
41
32
  end
42
33
  end
43
34
 
44
- context "when promised key is not in context" do
45
- it "raises an error" do
46
- exception_error_text = "promised :milk_tea to be in the context during LightService::DummyActionForKeysToPromiseWithError"
47
- expect {
48
- DummyActionForKeysToPromiseWithError.execute(:tea => "black", :milk => "2%")
49
- }.to raise_error(PromisedKeysNotInContextError, exception_error_text)
35
+ it "can collect expected keys when the `expects` macro is called multiple times" do
36
+ class DummyActionWithMultipleExpects
37
+ include LightService::Action
38
+ expects :tea
39
+ expects :milk, :chocolate
40
+ promises :milk_tea
41
+
42
+ executed do |context|
43
+ context.milk_tea = "#{context.tea} - #{context.milk} - with #{context.chocolate}"
44
+ end
50
45
  end
46
+ resulting_context = DummyActionWithMultipleExpects.execute(
47
+ :tea => "black",
48
+ :milk => "full cream",
49
+ :chocolate => "dark chocolate"
50
+ )
51
+ expect(resulting_context[:milk_tea]).to eq("black - full cream - with dark chocolate")
51
52
  end
53
+
52
54
  end
53
55
  end
@@ -23,7 +23,7 @@ module LightService
23
23
  }.to raise_error(PromisedKeysNotInContextError, exception_error_text)
24
24
  end
25
25
 
26
- it "fails the context without fulfilling its promise" do
26
+ it "can fail the context without fulfilling its promise" do
27
27
  class DummyActionForKeysToPromise
28
28
  executed do |context|
29
29
  context.fail!("Sorry, something bad has happened.")
@@ -39,7 +39,7 @@ module LightService
39
39
  end
40
40
 
41
41
  context "when the promised key is in the context" do
42
- it "sets in the context if it was set with not nil" do
42
+ it "can be set with an actual value" do
43
43
  class DummyActionForKeysToPromise
44
44
  executed do |context|
45
45
  context.milk_tea = "#{context.tea} - #{context.milk}"
@@ -48,12 +48,12 @@ module LightService
48
48
  end
49
49
 
50
50
  result_context = DummyActionForKeysToPromise.execute(:tea => "black",
51
- :milk => "full cream")
51
+ :milk => "full cream")
52
52
  expect(result_context).to be_success
53
53
  expect(result_context[:milk_tea]).to eq("black - full cream hello")
54
54
  end
55
55
 
56
- it "sets in the context if it was set with nil" do
56
+ it "can be set with nil" do
57
57
  class DummyActionForKeysToPromise
58
58
  executed do |context|
59
59
  context.milk_tea = nil
@@ -64,7 +64,25 @@ module LightService
64
64
  expect(result_context).to be_success
65
65
  expect(result_context[:milk_tea]).to be_nil
66
66
  end
67
+ end
67
68
 
69
+ it "can collect promised keys when the `promised` macro is called multiple times" do
70
+ class DummyActionWithMultiplePromises
71
+ include LightService::Action
72
+ expects :coffee
73
+ promises :cappuccino
74
+ promises :latte
75
+
76
+ executed do |context|
77
+ context.cappuccino = "Cappucino needs #{context.coffee} and a little milk"
78
+ context.latte = "Latte needs #{context.coffee} and a lot of milk"
79
+ end
80
+ end
81
+ resulting_context = DummyActionWithMultiplePromises.execute(:coffee => "espresso")
82
+
83
+ expect(resulting_context.cappuccino).to eq("Cappucino needs espresso and a little milk")
84
+ expect(resulting_context.latte).to eq("Latte needs espresso and a lot of milk")
68
85
  end
86
+
69
87
  end
70
88
  end
data/spec/action_spec.rb CHANGED
@@ -18,11 +18,6 @@ module LightService
18
18
  end
19
19
  end
20
20
 
21
- class PromisingAction
22
- include LightService::Action
23
- promises :milk_tea
24
- end
25
-
26
21
  let(:context) { ::LightService::Context.make }
27
22
 
28
23
  context "when the action context has failure" do
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.3.5
4
+ version: 0.3.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Attila Domokos
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-13 00:00:00.000000000 Z
11
+ date: 2014-07-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec