strategy 0.1.0 → 0.1.1

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: b6959b8c7099aa8ddaf5c6a868e97ecdc3751c8c
4
- data.tar.gz: f9999439f1e67db5a104b58f83feac6fe85db868
3
+ metadata.gz: 313846f0c19dea154b8ba65298ce28eb79043bc5
4
+ data.tar.gz: ff25f117d25be39dc138c54f230f7512d3b7a48e
5
5
  SHA512:
6
- metadata.gz: 384e90d59bef7a33eb45f678d46b509dae1f3902e1c8d1fc510f72f26164c62f3338817bfabd266a879e5c8e838305d93925b8e2fa04767acebc0f391551f9b0
7
- data.tar.gz: 7b52e70710d073c8c07e609aa7f51a5ba89402e72ae1f68b6f042802960c51b1f7fcfebc4bf9836e8e23a9fbe71d07b2c02222e207ae6267e2e9308f72718e9b
6
+ metadata.gz: eea489e5ae66e91a7d8dc14aa11a3c5ca0166ce485a006fd70c1a3678d5e1e84a7420db23c37e84952fc5399fa2999353c40f87f91b34d3bca619a9ef4727779
7
+ data.tar.gz: ef5e7e701e18ba6749bb5829c1bd90624584419066f9b61076db8fc7418f1ae98799f144d1f3293a49b0dcdf34ff1f4b74b801f14bcd1ecc161c67a3be272e8f
@@ -5,7 +5,7 @@ module Strategy
5
5
  # highest-level container around an execution strategy, and may contain as few
6
6
  # or as many Step objects as required.
7
7
  class Plan
8
- attr_reader :name
8
+ attr_reader :name, :steps
9
9
 
10
10
  # Create a new plan, to which individual execution steps will be added.
11
11
  #
@@ -20,6 +20,9 @@ module Strategy
20
20
  # Adds a new action to the step. Actions are given as a code block, and
21
21
  # will be executed in the order they are added (if the step is executed).
22
22
  def action &block
23
+ if block.nil?
24
+ raise RuntimeError, 'expected a block but none given'
25
+ end
23
26
  @actions << block
24
27
  end
25
28
 
@@ -0,0 +1,8 @@
1
+ require 'simplecov'
2
+
3
+ SimpleCov.formatter = SimpleCov::Formatter::HTMLFormatter
4
+ SimpleCov.start do
5
+ add_filter '/spec/'
6
+ end
7
+
8
+ require 'strategy'
@@ -0,0 +1,49 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Plan' do
4
+ before :all do
5
+ @plan = Strategy::Plan.new 'Test Plan'
6
+
7
+ step = Strategy::Step.new 'Step 1'
8
+ step.action { puts 1 }
9
+ @plan.add step
10
+
11
+ step = Strategy::Step.new 'Step 2'
12
+ step.action { puts 2 }
13
+ @plan.add step
14
+ end
15
+
16
+ it 'should add a description to the plan' do
17
+ expect(@plan.name).to eq('Test Plan')
18
+ end
19
+
20
+ it 'should accept new steps' do
21
+ step = Strategy::Step.new 'Step 3'
22
+ step.action { puts 3 }
23
+ @plan.add step
24
+ expect(@plan.steps.length).to eq(3)
25
+ end
26
+
27
+ it 'should reflect the proper plan name' do
28
+ expect(@plan.describe).to include('Test Plan')
29
+ end
30
+
31
+ it 'should error if a non-step object is passed' do
32
+ expect { @plan.add 0 }.to raise_error
33
+ end
34
+
35
+ it 'should reflect all steps in the plan' do
36
+ expect(@plan.describe).to include('Step 1')
37
+ expect(@plan.describe).to include('Step 2')
38
+ expect(@plan.describe).to include('Step 3')
39
+ end
40
+
41
+ it 'should execute all of the steps' do
42
+ expect { @plan.execute! }.to output("1\n2\n3\n").to_stdout
43
+ end
44
+
45
+ it 'should yield step number and description if block given' do
46
+ expect { @plan.execute! { |n, d| puts "#{n}. #{d}" } }.to \
47
+ output("1. Step 1\n1\n2. Step 2\n2\n3. Step 3\n3\n").to_stdout
48
+ end
49
+ end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Step' do
4
+ before :all do
5
+ @step = Strategy::Step.new 'Test Step'
6
+ end
7
+
8
+ it 'should create a new step with proper name' do
9
+ expect(@step.name).to eq('Test Step')
10
+ end
11
+
12
+ it 'should add an action properly' do
13
+ @step.action { puts 1 }
14
+ expect(@step.actions.length).to eq(1)
15
+ end
16
+
17
+ it 'should allow multiple actions to be added' do
18
+ @step.action { puts 2 }
19
+ expect(@step.actions.length).to eq(2)
20
+ end
21
+
22
+ it 'should raise an error if no block is given for an action' do
23
+ expect { @step.action }.to raise_error
24
+ end
25
+
26
+ it 'should execute all actions in the step in order' do
27
+ expect { @step.execute! }.to output("1\n2\n").to_stdout
28
+ end
29
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: strategy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Uber
@@ -61,6 +61,9 @@ files:
61
61
  - lib/strategy/plan.rb
62
62
  - lib/strategy/step.rb
63
63
  - lib/strategy.rb
64
+ - spec/spec_helper.rb
65
+ - spec/strategy/plan_spec.rb
66
+ - spec/strategy/step_spec.rb
64
67
  homepage: https://github.com/ryanuber/strategy-gem
65
68
  licenses:
66
69
  - MIT
@@ -85,4 +88,7 @@ rubygems_version: 2.0.14
85
88
  signing_key:
86
89
  specification_version: 4
87
90
  summary: Create runnable, stepped execution plans
88
- test_files: []
91
+ test_files:
92
+ - spec/spec_helper.rb
93
+ - spec/strategy/plan_spec.rb
94
+ - spec/strategy/step_spec.rb