light-service 0.3.3 → 0.3.4
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/.travis.yml +1 -1
 - data/README.md +4 -0
 - data/lib/light-service/action.rb +13 -4
 - data/lib/light-service/context_key_verifier.rb +6 -6
 - data/lib/light-service/organizer.rb +4 -0
 - data/lib/light-service/version.rb +1 -1
 - data/light-service.gemspec +2 -1
 - data/spec/action_expected_keys_spec.rb +20 -2
 - data/spec/action_promised_keys_spec.rb +1 -1
 - data/spec/action_spec.rb +5 -5
 - data/spec/context_spec.rb +4 -4
 - data/spec/organizer_spec.rb +23 -5
 - data/spec/sample/calculates_order_tax_action_spec.rb +2 -2
 - data/spec/sample/calculates_tax_spec.rb +5 -5
 - data/spec/sample/looks_up_tax_percentage_action_spec.rb +13 -13
 - data/spec/sample/provides_free_shipping_action_spec.rb +4 -4
 - data/spec/spec_helper.rb +1 -0
 - metadata +18 -4
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 713a827193e2ac90169a99251cbb9d9745ed4394
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 91400a943609efb9e0a811437b73d30faf1090cb
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 4ceecbf3154d271ead7dfb8105dc38100589b0e0158943c3994a1f1649b30b9e5d65725b7d3416311b1975b5a8a5a0a181a2c26e4843689637b88a873d2792a3
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 6f44c67e69cd032a46320d75ab6a7188f3d177e090207abdcbed34a1db984b914367d2ba6a9eeb3aaa881d3f4e9f91a59207323993db8984d7024b754ab387bc
         
     | 
    
        data/.travis.yml
    CHANGED
    
    
    
        data/README.md
    CHANGED
    
    | 
         @@ -273,6 +273,10 @@ 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.4
         
     | 
| 
      
 277 
     | 
    
         
            +
            * The method call `with` is [now optional](https://github.com/adomokos/light-service/blob/master/spec/organizer_spec.rb#L18) in case you have nothing to put into the context.
         
     | 
| 
      
 278 
     | 
    
         
            +
            * Action name is being displayed in the error message when the expected or promised key is not in the context.
         
     | 
| 
      
 279 
     | 
    
         
            +
             
     | 
| 
       276 
280 
     | 
    
         
             
            ### 0.3.3
         
     | 
| 
       277 
281 
     | 
    
         
             
            * Switching the promises and expects keys accessors from Action to Context
         
     | 
| 
       278 
282 
     | 
    
         | 
    
        data/lib/light-service/action.rb
    CHANGED
    
    | 
         @@ -14,19 +14,28 @@ module LightService 
     | 
|
| 
       14 
14 
     | 
    
         
             
                    @_promised_keys = args
         
     | 
| 
       15 
15 
     | 
    
         
             
                  end
         
     | 
| 
       16 
16 
     | 
    
         | 
| 
      
 17 
     | 
    
         
            +
                  def expected_keys
         
     | 
| 
      
 18 
     | 
    
         
            +
                    @_expected_keys
         
     | 
| 
      
 19 
     | 
    
         
            +
                  end
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
                  def promised_keys
         
     | 
| 
      
 22 
     | 
    
         
            +
                    @_promised_keys
         
     | 
| 
      
 23 
     | 
    
         
            +
                  end
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
       17 
25 
     | 
    
         
             
                  def executed
         
     | 
| 
       18 
26 
     | 
    
         
             
                    define_singleton_method "execute" do |context = {}|
         
     | 
| 
       19 
27 
     | 
    
         
             
                      action_context = create_action_context(context)
         
     | 
| 
       20 
28 
     | 
    
         
             
                      return action_context if action_context.stop_processing?
         
     | 
| 
      
 29 
     | 
    
         
            +
                      action = self
         
     | 
| 
       21 
30 
     | 
    
         | 
| 
       22 
     | 
    
         
            -
                      ContextKeyVerifier.verify_expected_keys_are_in_context(action_context,  
     | 
| 
      
 31 
     | 
    
         
            +
                      ContextKeyVerifier.verify_expected_keys_are_in_context(action_context, action)
         
     | 
| 
       23 
32 
     | 
    
         | 
| 
       24 
     | 
    
         
            -
                      action_context.define_accessor_methods_for_keys( 
     | 
| 
       25 
     | 
    
         
            -
                      action_context.define_accessor_methods_for_keys( 
     | 
| 
      
 33 
     | 
    
         
            +
                      action_context.define_accessor_methods_for_keys(expected_keys)
         
     | 
| 
      
 34 
     | 
    
         
            +
                      action_context.define_accessor_methods_for_keys(promised_keys)
         
     | 
| 
       26 
35 
     | 
    
         | 
| 
       27 
36 
     | 
    
         
             
                      yield(action_context)
         
     | 
| 
       28 
37 
     | 
    
         | 
| 
       29 
     | 
    
         
            -
                      ContextKeyVerifier.verify_promised_keys_are_in_context(action_context,  
     | 
| 
      
 38 
     | 
    
         
            +
                      ContextKeyVerifier.verify_promised_keys_are_in_context(action_context, action)
         
     | 
| 
       30 
39 
     | 
    
         
             
                    end
         
     | 
| 
       31 
40 
     | 
    
         
             
                  end
         
     | 
| 
       32 
41 
     | 
    
         | 
| 
         @@ -4,15 +4,15 @@ module LightService 
     | 
|
| 
       4 
4 
     | 
    
         | 
| 
       5 
5 
     | 
    
         
             
              class ContextKeyVerifier
         
     | 
| 
       6 
6 
     | 
    
         
             
                class << self
         
     | 
| 
       7 
     | 
    
         
            -
                  def verify_expected_keys_are_in_context(context,  
     | 
| 
       8 
     | 
    
         
            -
                    verify_keys_are_in_context(context, expected_keys) do |not_found_keys|
         
     | 
| 
       9 
     | 
    
         
            -
                      fail ExpectedKeysNotInContextError, "expected #{format_keys(not_found_keys)} to be in the context"
         
     | 
| 
      
 7 
     | 
    
         
            +
                  def verify_expected_keys_are_in_context(context, action)
         
     | 
| 
      
 8 
     | 
    
         
            +
                    verify_keys_are_in_context(context, action.expected_keys) do |not_found_keys|
         
     | 
| 
      
 9 
     | 
    
         
            +
                      fail ExpectedKeysNotInContextError, "expected #{format_keys(not_found_keys)} to be in the context during #{action.to_s}"
         
     | 
| 
       10 
10 
     | 
    
         
             
                    end
         
     | 
| 
       11 
11 
     | 
    
         
             
                  end
         
     | 
| 
       12 
12 
     | 
    
         | 
| 
       13 
     | 
    
         
            -
                  def verify_promised_keys_are_in_context(context,  
     | 
| 
       14 
     | 
    
         
            -
                    verify_keys_are_in_context(context, promised_keys) do |not_found_keys|
         
     | 
| 
       15 
     | 
    
         
            -
                      fail PromisedKeysNotInContextError, "promised #{format_keys(not_found_keys)} to be in the context"
         
     | 
| 
      
 13 
     | 
    
         
            +
                  def verify_promised_keys_are_in_context(context, action)
         
     | 
| 
      
 14 
     | 
    
         
            +
                    verify_keys_are_in_context(context, action.promised_keys) do |not_found_keys|
         
     | 
| 
      
 15 
     | 
    
         
            +
                      fail PromisedKeysNotInContextError, "promised #{format_keys(not_found_keys)} to be in the context during #{action.to_s}"
         
     | 
| 
       16 
16 
     | 
    
         
             
                    end
         
     | 
| 
       17 
17 
     | 
    
         
             
                  end
         
     | 
| 
       18 
18 
     | 
    
         | 
    
        data/light-service.gemspec
    CHANGED
    
    | 
         @@ -16,7 +16,8 @@ Gem::Specification.new do |gem| 
     | 
|
| 
       16 
16 
     | 
    
         
             
              gem.require_paths = ["lib"]
         
     | 
| 
       17 
17 
     | 
    
         
             
              gem.version       = LightService::VERSION
         
     | 
| 
       18 
18 
     | 
    
         | 
| 
       19 
     | 
    
         
            -
              gem.add_development_dependency("rspec", "~>  
     | 
| 
      
 19 
     | 
    
         
            +
              gem.add_development_dependency("rspec", "~> 3.0")
         
     | 
| 
      
 20 
     | 
    
         
            +
              gem.add_development_dependency("rspec-its", "~> 1.0")
         
     | 
| 
       20 
21 
     | 
    
         
             
              gem.add_development_dependency("simplecov", "~> 0.7.1")
         
     | 
| 
       21 
22 
     | 
    
         
             
              gem.add_development_dependency("pry", "0.9.12.2")
         
     | 
| 
       22 
23 
     | 
    
         
             
            end
         
     | 
| 
         @@ -11,6 +11,15 @@ 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
         
     | 
| 
       14 
23 
     | 
    
         | 
| 
       15 
24 
     | 
    
         
             
                context "when expected keys are in the context" do
         
     | 
| 
       16 
25 
     | 
    
         
             
                  it "can access the keys as class methods" do
         
     | 
| 
         @@ -23,13 +32,22 @@ module LightService 
     | 
|
| 
       23 
32 
     | 
    
         
             
                  end
         
     | 
| 
       24 
33 
     | 
    
         
             
                end
         
     | 
| 
       25 
34 
     | 
    
         | 
| 
       26 
     | 
    
         
            -
                context "when expected  
     | 
| 
      
 35 
     | 
    
         
            +
                context "when expected key is not in the context" do
         
     | 
| 
       27 
36 
     | 
    
         
             
                  it "raises an error" do
         
     | 
| 
       28 
     | 
    
         
            -
                    exception_error_text = "expected :milk to be in the context"
         
     | 
| 
      
 37 
     | 
    
         
            +
                    exception_error_text = "expected :milk to be in the context during LightService::DummyActionForKeysToExpect"
         
     | 
| 
       29 
38 
     | 
    
         
             
                    expect {
         
     | 
| 
       30 
39 
     | 
    
         
             
                      DummyActionForKeysToExpect.execute(:tea => "black")
         
     | 
| 
       31 
40 
     | 
    
         
             
                    }.to raise_error(ExpectedKeysNotInContextError, exception_error_text)
         
     | 
| 
       32 
41 
     | 
    
         
             
                  end
         
     | 
| 
       33 
42 
     | 
    
         
             
                end
         
     | 
| 
      
 43 
     | 
    
         
            +
             
     | 
| 
      
 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)
         
     | 
| 
      
 50 
     | 
    
         
            +
                  end
         
     | 
| 
      
 51 
     | 
    
         
            +
                end
         
     | 
| 
       34 
52 
     | 
    
         
             
              end
         
     | 
| 
       35 
53 
     | 
    
         
             
            end
         
     | 
| 
         @@ -14,7 +14,7 @@ module LightService 
     | 
|
| 
       14 
14 
     | 
    
         | 
| 
       15 
15 
     | 
    
         
             
                context "when the promised key is not in the context" do
         
     | 
| 
       16 
16 
     | 
    
         
             
                  it "raises an ArgumentError" do
         
     | 
| 
       17 
     | 
    
         
            -
                    exception_error_text = "promised :milk_tea, :something_else to be in the context"
         
     | 
| 
      
 17 
     | 
    
         
            +
                    exception_error_text = "promised :milk_tea, :something_else to be in the context during LightService::DummyActionForKeysToPromise"
         
     | 
| 
       18 
18 
     | 
    
         
             
                    expect {
         
     | 
| 
       19 
19 
     | 
    
         
             
                      DummyActionForKeysToPromise.execute(:tea => "black", :milk => "full cream")
         
     | 
| 
       20 
20 
     | 
    
         
             
                    }.to raise_error(PromisedKeysNotInContextError, exception_error_text)
         
     | 
    
        data/spec/action_spec.rb
    CHANGED
    
    | 
         @@ -31,7 +31,7 @@ module LightService 
     | 
|
| 
       31 
31 
     | 
    
         | 
| 
       32 
32 
     | 
    
         
             
                    DummyAction.execute(context)
         
     | 
| 
       33 
33 
     | 
    
         | 
| 
       34 
     | 
    
         
            -
                    context.to_hash.keys. 
     | 
| 
      
 34 
     | 
    
         
            +
                    expect(context.to_hash.keys).to be_empty
         
     | 
| 
       35 
35 
     | 
    
         
             
                  end
         
     | 
| 
       36 
36 
     | 
    
         
             
                end
         
     | 
| 
       37 
37 
     | 
    
         | 
| 
         @@ -39,7 +39,7 @@ module LightService 
     | 
|
| 
       39 
39 
     | 
    
         
             
                  it "executes the block" do
         
     | 
| 
       40 
40 
     | 
    
         
             
                    DummyAction.execute(context)
         
     | 
| 
       41 
41 
     | 
    
         | 
| 
       42 
     | 
    
         
            -
                    context.to_hash.keys. 
     | 
| 
      
 42 
     | 
    
         
            +
                    expect(context.to_hash.keys).to eq [:test_key]
         
     | 
| 
       43 
43 
     | 
    
         
             
                  end
         
     | 
| 
       44 
44 
     | 
    
         
             
                end
         
     | 
| 
       45 
45 
     | 
    
         | 
| 
         @@ -49,7 +49,7 @@ module LightService 
     | 
|
| 
       49 
49 
     | 
    
         | 
| 
       50 
50 
     | 
    
         
             
                    DummyAction.execute(context)
         
     | 
| 
       51 
51 
     | 
    
         | 
| 
       52 
     | 
    
         
            -
                    context.to_hash.keys. 
     | 
| 
      
 52 
     | 
    
         
            +
                    expect(context.to_hash.keys).to be_empty
         
     | 
| 
       53 
53 
     | 
    
         
             
                  end
         
     | 
| 
       54 
54 
     | 
    
         | 
| 
       55 
55 
     | 
    
         
             
                  it "does not execute skipped actions" do
         
     | 
| 
         @@ -59,14 +59,14 @@ module LightService 
     | 
|
| 
       59 
59 
     | 
    
         | 
| 
       60 
60 
     | 
    
         
             
                    SkippedAction.execute(context)
         
     | 
| 
       61 
61 
     | 
    
         | 
| 
       62 
     | 
    
         
            -
                    context.to_hash. 
     | 
| 
      
 62 
     | 
    
         
            +
                    expect(context.to_hash).to eq ({:test_key => "test_value"})
         
     | 
| 
       63 
63 
     | 
    
         
             
                  end
         
     | 
| 
       64 
64 
     | 
    
         
             
                end
         
     | 
| 
       65 
65 
     | 
    
         | 
| 
       66 
66 
     | 
    
         
             
                it "returns the context" do
         
     | 
| 
       67 
67 
     | 
    
         
             
                  result = DummyAction.execute(context)
         
     | 
| 
       68 
68 
     | 
    
         | 
| 
       69 
     | 
    
         
            -
                  result.to_hash. 
     | 
| 
      
 69 
     | 
    
         
            +
                  expect(result.to_hash).to eq ({:test_key => "test_value"})
         
     | 
| 
       70 
70 
     | 
    
         
             
                end
         
     | 
| 
       71 
71 
     | 
    
         | 
| 
       72 
72 
     | 
    
         
             
                context "when invoked with hash" do
         
     | 
    
        data/spec/context_spec.rb
    CHANGED
    
    | 
         @@ -6,7 +6,7 @@ module LightService 
     | 
|
| 
       6 
6 
     | 
    
         
             
                describe "can be made" do
         
     | 
| 
       7 
7 
     | 
    
         
             
                  context "with no arguments" do
         
     | 
| 
       8 
8 
     | 
    
         
             
                    subject { Context.make }
         
     | 
| 
       9 
     | 
    
         
            -
                    it {  
     | 
| 
      
 9 
     | 
    
         
            +
                    it { is_expected.to be_success }
         
     | 
| 
       10 
10 
     | 
    
         
             
                    its(:message) { should be_empty }
         
     | 
| 
       11 
11 
     | 
    
         
             
                  end
         
     | 
| 
       12 
12 
     | 
    
         | 
| 
         @@ -49,7 +49,7 @@ module LightService 
     | 
|
| 
       49 
49 
     | 
    
         
             
                  context = Context.make
         
     | 
| 
       50 
50 
     | 
    
         
             
                  context.skip_all!
         
     | 
| 
       51 
51 
     | 
    
         | 
| 
       52 
     | 
    
         
            -
                  expect(context.skip_all?).to  
     | 
| 
      
 52 
     | 
    
         
            +
                  expect(context.skip_all?).to be_truthy
         
     | 
| 
       53 
53 
     | 
    
         
             
                end
         
     | 
| 
       54 
54 
     | 
    
         | 
| 
       55 
55 
     | 
    
         
             
                it "can be pushed into a SUCCESS state" do
         
     | 
| 
         @@ -112,12 +112,12 @@ module LightService 
     | 
|
| 
       112 
112 
     | 
    
         | 
| 
       113 
113 
     | 
    
         
             
                  it "flags processing to stop on failure" do
         
     | 
| 
       114 
114 
     | 
    
         
             
                    context.fail!("on purpose")
         
     | 
| 
       115 
     | 
    
         
            -
                    expect(context.stop_processing?).to  
     | 
| 
      
 115 
     | 
    
         
            +
                    expect(context.stop_processing?).to be_truthy
         
     | 
| 
       116 
116 
     | 
    
         
             
                  end
         
     | 
| 
       117 
117 
     | 
    
         | 
| 
       118 
118 
     | 
    
         
             
                  it "flags processing to stop when remaining actions should be skipped" do
         
     | 
| 
       119 
119 
     | 
    
         
             
                    context.skip_all!
         
     | 
| 
       120 
     | 
    
         
            -
                    expect(context.stop_processing?).to  
     | 
| 
      
 120 
     | 
    
         
            +
                    expect(context.stop_processing?).to be_truthy
         
     | 
| 
       121 
121 
     | 
    
         
             
                  end
         
     | 
| 
       122 
122 
     | 
    
         
             
                end
         
     | 
| 
       123 
123 
     | 
    
         | 
    
        data/spec/organizer_spec.rb
    CHANGED
    
    | 
         @@ -14,6 +14,10 @@ describe LightService::Organizer do 
     | 
|
| 
       14 
14 
     | 
    
         
             
                def self.do_something_with_no_actions(action_arguments)
         
     | 
| 
       15 
15 
     | 
    
         
             
                  with(action_arguments).reduce
         
     | 
| 
       16 
16 
     | 
    
         
             
                end
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
                def self.do_something_with_no_starting_context
         
     | 
| 
      
 19 
     | 
    
         
            +
                  reduce([AnAction, AnotherAction])
         
     | 
| 
      
 20 
     | 
    
         
            +
                end
         
     | 
| 
       17 
21 
     | 
    
         
             
              end
         
     | 
| 
       18 
22 
     | 
    
         | 
| 
       19 
23 
     | 
    
         
             
              let(:context) { ::LightService::Context.make(user: user) }
         
     | 
| 
         @@ -21,10 +25,10 @@ describe LightService::Organizer do 
     | 
|
| 
       21 
25 
     | 
    
         | 
| 
       22 
26 
     | 
    
         
             
              context "when #with is called with hash" do
         
     | 
| 
       23 
27 
     | 
    
         
             
                before do
         
     | 
| 
       24 
     | 
    
         
            -
                  AnAction. 
     | 
| 
      
 28 
     | 
    
         
            +
                  expect(AnAction).to receive(:execute) \
         
     | 
| 
       25 
29 
     | 
    
         
             
                          .with(context) \
         
     | 
| 
       26 
30 
     | 
    
         
             
                          .and_return context
         
     | 
| 
       27 
     | 
    
         
            -
                  AnotherAction. 
     | 
| 
      
 31 
     | 
    
         
            +
                  expect(AnotherAction).to receive(:execute) \
         
     | 
| 
       28 
32 
     | 
    
         
             
                          .with(context) \
         
     | 
| 
       29 
33 
     | 
    
         
             
                          .and_return context
         
     | 
| 
       30 
34 
     | 
    
         
             
                end
         
     | 
| 
         @@ -37,10 +41,10 @@ describe LightService::Organizer do 
     | 
|
| 
       37 
41 
     | 
    
         | 
| 
       38 
42 
     | 
    
         
             
              context "when #with is called with Context" do
         
     | 
| 
       39 
43 
     | 
    
         
             
                before do
         
     | 
| 
       40 
     | 
    
         
            -
                  AnAction. 
     | 
| 
      
 44 
     | 
    
         
            +
                  expect(AnAction).to receive(:execute) \
         
     | 
| 
       41 
45 
     | 
    
         
             
                          .with(context) \
         
     | 
| 
       42 
46 
     | 
    
         
             
                          .and_return context
         
     | 
| 
       43 
     | 
    
         
            -
                  AnotherAction. 
     | 
| 
      
 47 
     | 
    
         
            +
                  expect(AnotherAction).to receive(:execute) \
         
     | 
| 
       44 
48 
     | 
    
         
             
                          .with(context) \
         
     | 
| 
       45 
49 
     | 
    
         
             
                          .and_return context
         
     | 
| 
       46 
50 
     | 
    
         
             
                end
         
     | 
| 
         @@ -54,7 +58,21 @@ describe LightService::Organizer do 
     | 
|
| 
       54 
58 
     | 
    
         
             
              context "when no Actions are specified" do
         
     | 
| 
       55 
59 
     | 
    
         
             
                it "throws a Runtime error" do
         
     | 
| 
       56 
60 
     | 
    
         
             
                  expect { AnOrganizer.do_something_with_no_actions(context) }.to \
         
     | 
| 
       57 
     | 
    
         
            -
             
     | 
| 
      
 61 
     | 
    
         
            +
                    raise_error RuntimeError, "No action(s) were provided"
         
     | 
| 
      
 62 
     | 
    
         
            +
                end
         
     | 
| 
      
 63 
     | 
    
         
            +
              end
         
     | 
| 
      
 64 
     | 
    
         
            +
             
     | 
| 
      
 65 
     | 
    
         
            +
              context "when no starting context is specified" do
         
     | 
| 
      
 66 
     | 
    
         
            +
                it "creates one implicitly" do
         
     | 
| 
      
 67 
     | 
    
         
            +
                  expect(AnAction).to receive(:execute) \
         
     | 
| 
      
 68 
     | 
    
         
            +
                    .with({}) \
         
     | 
| 
      
 69 
     | 
    
         
            +
                    .and_return(context)
         
     | 
| 
      
 70 
     | 
    
         
            +
                  expect(AnotherAction).to receive(:execute) \
         
     | 
| 
      
 71 
     | 
    
         
            +
                    .with(context) \
         
     | 
| 
      
 72 
     | 
    
         
            +
                    .and_return(context)
         
     | 
| 
      
 73 
     | 
    
         
            +
             
     | 
| 
      
 74 
     | 
    
         
            +
                  expect { AnOrganizer.do_something_with_no_starting_context } \
         
     | 
| 
      
 75 
     | 
    
         
            +
                    .not_to raise_error
         
     | 
| 
       58 
76 
     | 
    
         
             
                end
         
     | 
| 
       59 
77 
     | 
    
         
             
              end
         
     | 
| 
       60 
78 
     | 
    
         
             
            end
         
     | 
| 
         @@ -9,8 +9,8 @@ describe CalculatesOrderTaxAction do 
     | 
|
| 
       9 
9 
     | 
    
         
             
              end
         
     | 
| 
       10 
10 
     | 
    
         | 
| 
       11 
11 
     | 
    
         
             
              it "calculates the tax based on the tax percentage" do
         
     | 
| 
       12 
     | 
    
         
            -
                order. 
     | 
| 
       13 
     | 
    
         
            -
                order. 
     | 
| 
      
 12 
     | 
    
         
            +
                allow(order).to receive_messages(:total => 100)
         
     | 
| 
      
 13 
     | 
    
         
            +
                expect(order).to receive(:tax=).with 7.2
         
     | 
| 
       14 
14 
     | 
    
         
             
                CalculatesOrderTaxAction.execute(context)
         
     | 
| 
       15 
15 
     | 
    
         
             
              end
         
     | 
| 
       16 
16 
     | 
    
         
             
            end
         
     | 
| 
         @@ -9,16 +9,16 @@ describe CalculatesTax do 
     | 
|
| 
       9 
9 
     | 
    
         
             
              let(:context) { double('context') }
         
     | 
| 
       10 
10 
     | 
    
         | 
| 
       11 
11 
     | 
    
         
             
              it "calls the actions in order" do
         
     | 
| 
       12 
     | 
    
         
            -
                ::LightService::Context. 
     | 
| 
      
 12 
     | 
    
         
            +
                allow(::LightService::Context).to receive(:make) \
         
     | 
| 
       13 
13 
     | 
    
         
             
                                        .with(:order => order) \
         
     | 
| 
       14 
14 
     | 
    
         
             
                                        .and_return context
         
     | 
| 
       15 
15 
     | 
    
         | 
| 
       16 
     | 
    
         
            -
                LooksUpTaxPercentageAction. 
     | 
| 
       17 
     | 
    
         
            -
                CalculatesOrderTaxAction. 
     | 
| 
       18 
     | 
    
         
            -
                ProvidesFreeShippingAction. 
     | 
| 
      
 16 
     | 
    
         
            +
                allow(LooksUpTaxPercentageAction).to receive(:execute).with(context).and_return context
         
     | 
| 
      
 17 
     | 
    
         
            +
                allow(CalculatesOrderTaxAction).to receive(:execute).with(context).and_return context
         
     | 
| 
      
 18 
     | 
    
         
            +
                allow(ProvidesFreeShippingAction).to receive(:execute).with(context).and_return context
         
     | 
| 
       19 
19 
     | 
    
         | 
| 
       20 
20 
     | 
    
         
             
                result = CalculatesTax.for_order(order)
         
     | 
| 
       21 
21 
     | 
    
         | 
| 
       22 
     | 
    
         
            -
                result. 
     | 
| 
      
 22 
     | 
    
         
            +
                expect(result).to eq context
         
     | 
| 
       23 
23 
     | 
    
         
             
              end
         
     | 
| 
       24 
24 
     | 
    
         
             
            end
         
     | 
| 
         @@ -7,8 +7,8 @@ describe LooksUpTaxPercentageAction do 
     | 
|
| 
       7 
7 
     | 
    
         
             
              let(:region) { double('region') }
         
     | 
| 
       8 
8 
     | 
    
         
             
              let(:order) do
         
     | 
| 
       9 
9 
     | 
    
         
             
                order = double('order')
         
     | 
| 
       10 
     | 
    
         
            -
                order. 
     | 
| 
       11 
     | 
    
         
            -
                order. 
     | 
| 
      
 10 
     | 
    
         
            +
                allow(order).to receive_messages(:region => region)
         
     | 
| 
      
 11 
     | 
    
         
            +
                allow(order).to receive_messages(:total => 200)
         
     | 
| 
       12 
12 
     | 
    
         
             
                order
         
     | 
| 
       13 
13 
     | 
    
         
             
              end
         
     | 
| 
       14 
14 
     | 
    
         
             
              let(:context) do
         
     | 
| 
         @@ -19,35 +19,35 @@ describe LooksUpTaxPercentageAction do 
     | 
|
| 
       19 
19 
     | 
    
         | 
| 
       20 
20 
     | 
    
         
             
              context "when the tax_ranges were not found" do
         
     | 
| 
       21 
21 
     | 
    
         
             
                it "sets the context to failure" do
         
     | 
| 
       22 
     | 
    
         
            -
                  TaxRange. 
     | 
| 
      
 22 
     | 
    
         
            +
                  allow(TaxRange).to receive(:for_region).with(region).and_return nil
         
     | 
| 
       23 
23 
     | 
    
         
             
                  LooksUpTaxPercentageAction.execute(context)
         
     | 
| 
       24 
24 
     | 
    
         | 
| 
       25 
     | 
    
         
            -
                  context. 
     | 
| 
       26 
     | 
    
         
            -
                  context.message. 
     | 
| 
      
 25 
     | 
    
         
            +
                  expect(context).to be_failure
         
     | 
| 
      
 26 
     | 
    
         
            +
                  expect(context.message).to eq "The tax ranges were not found"
         
     | 
| 
       27 
27 
     | 
    
         
             
                end
         
     | 
| 
       28 
28 
     | 
    
         
             
              end
         
     | 
| 
       29 
29 
     | 
    
         | 
| 
       30 
30 
     | 
    
         
             
              context "when the tax_percentage is not found" do
         
     | 
| 
       31 
31 
     | 
    
         
             
                it "sets the context to failure" do
         
     | 
| 
       32 
     | 
    
         
            -
                  TaxRange. 
     | 
| 
       33 
     | 
    
         
            -
                  tax_ranges. 
     | 
| 
      
 32 
     | 
    
         
            +
                  allow(TaxRange).to receive(:for_region).with(region).and_return tax_ranges
         
     | 
| 
      
 33 
     | 
    
         
            +
                  allow(tax_ranges).to receive_messages(:for_total => nil)
         
     | 
| 
       34 
34 
     | 
    
         | 
| 
       35 
35 
     | 
    
         
             
                  LooksUpTaxPercentageAction.execute(context)
         
     | 
| 
       36 
36 
     | 
    
         | 
| 
       37 
     | 
    
         
            -
                  context. 
     | 
| 
       38 
     | 
    
         
            -
                  context.message. 
     | 
| 
      
 37 
     | 
    
         
            +
                  expect(context).to be_failure
         
     | 
| 
      
 38 
     | 
    
         
            +
                  expect(context.message).to eq "The tax percentage was not found"
         
     | 
| 
       39 
39 
     | 
    
         
             
                end
         
     | 
| 
       40 
40 
     | 
    
         
             
              end
         
     | 
| 
       41 
41 
     | 
    
         | 
| 
       42 
42 
     | 
    
         
             
              context "when the tax_percentage is found" do
         
     | 
| 
       43 
43 
     | 
    
         
             
                it "sets the tax_percentage in context" do
         
     | 
| 
       44 
     | 
    
         
            -
                  TaxRange. 
     | 
| 
       45 
     | 
    
         
            -
                  tax_ranges. 
     | 
| 
      
 44 
     | 
    
         
            +
                  allow(TaxRange).to receive(:for_region).with(region).and_return tax_ranges
         
     | 
| 
      
 45 
     | 
    
         
            +
                  allow(tax_ranges).to receive_messages(:for_total => 25)
         
     | 
| 
       46 
46 
     | 
    
         | 
| 
       47 
47 
     | 
    
         
             
                  LooksUpTaxPercentageAction.execute(context)
         
     | 
| 
       48 
48 
     | 
    
         | 
| 
       49 
     | 
    
         
            -
                  context. 
     | 
| 
       50 
     | 
    
         
            -
                  context.fetch(:tax_percentage). 
     | 
| 
      
 49 
     | 
    
         
            +
                  expect(context).to be_success
         
     | 
| 
      
 50 
     | 
    
         
            +
                  expect(context.fetch(:tax_percentage)).to eq 25
         
     | 
| 
       51 
51 
     | 
    
         
             
                end
         
     | 
| 
       52 
52 
     | 
    
         
             
              end
         
     | 
| 
       53 
53 
     | 
    
         
             
            end
         
     | 
| 
         @@ -10,8 +10,8 @@ describe ProvidesFreeShippingAction do 
     | 
|
| 
       10 
10 
     | 
    
         | 
| 
       11 
11 
     | 
    
         
             
              context "when the order total with tax is > 200" do
         
     | 
| 
       12 
12 
     | 
    
         
             
                specify "order gets free shipping" do
         
     | 
| 
       13 
     | 
    
         
            -
                  order. 
     | 
| 
       14 
     | 
    
         
            -
                  order. 
     | 
| 
      
 13 
     | 
    
         
            +
                  allow(order).to receive_messages(:total_with_tax => 201)
         
     | 
| 
      
 14 
     | 
    
         
            +
                  expect(order).to receive(:provide_free_shipping!)
         
     | 
| 
       15 
15 
     | 
    
         | 
| 
       16 
16 
     | 
    
         
             
                  ProvidesFreeShippingAction.execute(context)
         
     | 
| 
       17 
17 
     | 
    
         
             
                end
         
     | 
| 
         @@ -19,8 +19,8 @@ describe ProvidesFreeShippingAction do 
     | 
|
| 
       19 
19 
     | 
    
         | 
| 
       20 
20 
     | 
    
         
             
              context "when the order total with tax is <= 200" do
         
     | 
| 
       21 
21 
     | 
    
         
             
                specify "order gets free shipping" do
         
     | 
| 
       22 
     | 
    
         
            -
                  order. 
     | 
| 
       23 
     | 
    
         
            -
                  order. 
     | 
| 
      
 22 
     | 
    
         
            +
                  allow(order).to receive_messages(:total_with_tax => 200)
         
     | 
| 
      
 23 
     | 
    
         
            +
                  expect(order).not_to receive(:provide_free_shipping!)
         
     | 
| 
       24 
24 
     | 
    
         | 
| 
       25 
25 
     | 
    
         
             
                  ProvidesFreeShippingAction.execute(context)
         
     | 
| 
       26 
26 
     | 
    
         
             
                end
         
     | 
    
        data/spec/spec_helper.rb
    CHANGED
    
    
    
        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. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.3.4
         
     | 
| 
       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- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2014-06-10 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: rspec
         
     | 
| 
         @@ -16,14 +16,28 @@ dependencies: 
     | 
|
| 
       16 
16 
     | 
    
         
             
                requirements:
         
     | 
| 
       17 
17 
     | 
    
         
             
                - - ~>
         
     | 
| 
       18 
18 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       19 
     | 
    
         
            -
                    version: ' 
     | 
| 
      
 19 
     | 
    
         
            +
                    version: '3.0'
         
     | 
| 
       20 
20 
     | 
    
         
             
              type: :development
         
     | 
| 
       21 
21 
     | 
    
         
             
              prerelease: false
         
     | 
| 
       22 
22 
     | 
    
         
             
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
       23 
23 
     | 
    
         
             
                requirements:
         
     | 
| 
       24 
24 
     | 
    
         
             
                - - ~>
         
     | 
| 
       25 
25 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       26 
     | 
    
         
            -
                    version: ' 
     | 
| 
      
 26 
     | 
    
         
            +
                    version: '3.0'
         
     | 
| 
      
 27 
     | 
    
         
            +
            - !ruby/object:Gem::Dependency
         
     | 
| 
      
 28 
     | 
    
         
            +
              name: rspec-its
         
     | 
| 
      
 29 
     | 
    
         
            +
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
      
 30 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 31 
     | 
    
         
            +
                - - ~>
         
     | 
| 
      
 32 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 33 
     | 
    
         
            +
                    version: '1.0'
         
     | 
| 
      
 34 
     | 
    
         
            +
              type: :development
         
     | 
| 
      
 35 
     | 
    
         
            +
              prerelease: false
         
     | 
| 
      
 36 
     | 
    
         
            +
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
      
 37 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 38 
     | 
    
         
            +
                - - ~>
         
     | 
| 
      
 39 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 40 
     | 
    
         
            +
                    version: '1.0'
         
     | 
| 
       27 
41 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       28 
42 
     | 
    
         
             
              name: simplecov
         
     | 
| 
       29 
43 
     | 
    
         
             
              requirement: !ruby/object:Gem::Requirement
         
     |