tango 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- tango (0.0.1)
4
+ tango (0.0.2)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
@@ -1,6 +1,5 @@
1
1
  require 'tango/dance'
2
2
  require 'tango/dance_builder'
3
+ require 'tango/errors'
3
4
  require 'tango/step'
4
- require 'tango/step_builder'
5
5
  require 'tango/step_runner'
6
- require 'tango/step_runner_context'
@@ -1,9 +1,6 @@
1
1
  module Tango
2
2
  class Dance
3
3
 
4
- class StepAlreadyDefinedError < RuntimeError; end
5
- class UndefinedStepError < RuntimeError; end
6
-
7
4
  def initialize(&block)
8
5
  @steps = {}
9
6
  DanceBuilder.new(self).instance_eval(&block)
@@ -15,9 +12,9 @@ module Tango
15
12
  @steps[name] = step
16
13
  end
17
14
 
18
- def run(step_name, options = {})
15
+ def run(step_name, *args)
19
16
  raise UndefinedStepError, "Step #{step_name} not defined" unless @steps.has_key?(step_name)
20
- @steps[step_name].run(options)
17
+ @steps[step_name].run(*args)
21
18
  end
22
19
 
23
20
  end
@@ -0,0 +1,6 @@
1
+ module Tango
2
+ class StepAlreadyDefinedError < RuntimeError; end
3
+ class UndefinedStepError < RuntimeError; end
4
+ class CouldNotMeetError < RuntimeError; end
5
+ class MeetWithoutMetError < RuntimeError; end
6
+ end
@@ -1,13 +1,14 @@
1
1
  module Tango
2
2
  class Step
3
3
  def initialize(&block)
4
- StepBuilder.new(self).instance_eval(&block)
4
+ @block = block
5
5
  end
6
6
 
7
- attr_accessor :dance, :met_block, :meet_block
7
+ attr_accessor :dance
8
+ attr_reader :block
8
9
 
9
- def run(options = {})
10
- StepRunner.new(self, options).run
10
+ def run(*args)
11
+ StepRunner.new(self).instance_exec(*args, &block)
11
12
  end
12
13
  end
13
14
  end
@@ -1,39 +1,24 @@
1
1
  module Tango
2
2
  class StepRunner
3
3
 
4
- def initialize(step, options)
5
- @step = step
6
- @options = options
7
- @context = StepRunnerContext.new(@step)
4
+ def initialize(step)
5
+ @step = step
8
6
  end
9
7
 
10
- def run
11
- if @step.met_block
12
- run_with_met_block
13
- else
14
- run_without_met_block
15
- end
8
+ def met?(&met_block)
9
+ @met_block = met_block
16
10
  end
17
11
 
18
- private
19
-
20
- def run_with_met_block
21
- unless met?
22
- meet
23
- raise "Couldn't meet" unless met?
12
+ def meet(&meet_block)
13
+ raise MeetWithoutMetError if @met_block.nil?
14
+ unless instance_eval(&@met_block)
15
+ instance_eval(&meet_block)
16
+ raise CouldNotMeetError unless instance_eval(&@met_block)
24
17
  end
25
18
  end
26
19
 
27
- def run_without_met_block
28
- meet
29
- end
30
-
31
- def met?
32
- @context.instance_exec(@options, &@step.met_block)
33
- end
34
-
35
- def meet
36
- @context.instance_exec(@options, &@step.meet_block)
20
+ def run(step_name, *args)
21
+ @step.dance.run(step_name, *args)
37
22
  end
38
23
 
39
24
  end
@@ -1,3 +1,3 @@
1
1
  module Tango
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -8,7 +8,7 @@ module Tango
8
8
 
9
9
  dance = Dance.new do
10
10
  step "example step" do
11
- meet { step_run = true }
11
+ step_run = true
12
12
  end
13
13
  end
14
14
 
@@ -21,11 +21,11 @@ module Tango
21
21
 
22
22
  dance = Dance.new do
23
23
  step "outer step" do
24
- meet { run "inner step" }
24
+ run "inner step"
25
25
  end
26
26
 
27
27
  step "inner step" do
28
- meet { inner_step_run = true }
28
+ inner_step_run = true
29
29
  end
30
30
  end
31
31
 
@@ -33,29 +33,27 @@ module Tango
33
33
  inner_step_run.should be_true
34
34
  end
35
35
 
36
- context "option passing" do
37
- it "should pass options to a step when running" do
38
- step_options = { :example => "example" }
39
-
36
+ context "passing arguments" do
37
+ it "should pass arguments to a step" do
40
38
  dance = Dance.new do
41
- step "example step" do
42
- meet {|options| options.should == step_options }
39
+ step "example step" do |a, b|
40
+ a.should == 1
41
+ b.should == 2
43
42
  end
44
43
  end
45
44
 
46
- dance.run "example step", step_options
45
+ dance.run "example step", 1, 2
47
46
  end
48
47
 
49
- it "should pass options when running other steps" do
50
- step_options = { :example => "example" }
51
-
48
+ it "should pass arguments when running other steps" do
52
49
  dance = Dance.new do
53
50
  step "outer step" do
54
- meet { run "inner step", step_options }
51
+ run "inner step", 1, 2
55
52
  end
56
53
 
57
- step "inner step" do
58
- meet {|options| options.should == step_options }
54
+ step "inner step" do |a, b|
55
+ a.should == 1
56
+ b.should == 2
59
57
  end
60
58
  end
61
59
 
@@ -70,7 +68,7 @@ module Tango
70
68
  step "example step" do; end
71
69
  step "example step" do; end
72
70
  end
73
- end.should raise_error(Dance::StepAlreadyDefinedError)
71
+ end.should raise_error(StepAlreadyDefinedError)
74
72
  end
75
73
 
76
74
  it "should raise an error on an attempt to run an undefined step" do
@@ -78,7 +76,7 @@ module Tango
78
76
 
79
77
  expect do
80
78
  dance.run "undefined step"
81
- end.should raise_error(Dance::UndefinedStepError)
79
+ end.should raise_error(UndefinedStepError)
82
80
  end
83
81
  end
84
82
 
@@ -3,15 +3,15 @@ require 'tango'
3
3
  module Tango
4
4
  describe Step do
5
5
 
6
- context "with just a meet block" do
7
- it "should run the meet block" do
8
- meet_block_calls = 0
6
+ context "with just a plain block" do
7
+ it "should run the block" do
8
+ block_calls = 0
9
9
  step = Step.new do
10
- meet { meet_block_calls += 1 }
10
+ block_calls += 1
11
11
  end
12
12
 
13
13
  step.run
14
- meet_block_calls.should == 1
14
+ block_calls.should == 1
15
15
  end
16
16
  end
17
17
 
@@ -59,34 +59,48 @@ module Tango
59
59
  meet { meet_block_calls += 1 }
60
60
  end
61
61
 
62
- expect { step.run }.should raise_error
62
+ expect { step.run }.should raise_error(CouldNotMeetError)
63
63
  met_block_calls.should == 2
64
64
  meet_block_calls.should == 1
65
65
  end
66
- end
67
-
68
- context "run with options" do
69
- it "should pass the options to the met block" do
70
- step_options = { :example => "example" }
71
66
 
67
+ it "should raise an error if there's a meet block without a met block" do
72
68
  step = Step.new do
73
- met? do |options|
74
- options.should == step_options
75
- true
76
- end
69
+ meet { }
77
70
  end
78
71
 
79
- step.run(step_options)
72
+ expect { step.run }.should raise_error(MeetWithoutMetError)
80
73
  end
74
+ end
81
75
 
82
- it "should pass the options to the meet block" do
83
- step_options = { :example => "example" }
76
+ context "step arguments" do
77
+ it "should pass a single argument to the step" do
78
+ step = Step.new do |a|
79
+ a.should == 1
80
+ end
84
81
 
85
- step = Step.new do
86
- meet {|options| options.should == step_options }
82
+ step.run(1)
83
+ end
84
+
85
+ it "should pass multiple arguments to the step" do
86
+ step = Step.new do |a, b|
87
+ a.should == 1
88
+ b.should == 2
89
+ end
90
+
91
+ step.run(1, 2)
92
+ end
93
+
94
+ it "should capture arguments in the met? and meet blocks" do
95
+ step = Step.new do |argument|
96
+ met? do
97
+ argument.should == 1
98
+ false
99
+ end
100
+ meet { argument.should == 1 }
87
101
  end
88
102
 
89
- step.run(step_options)
103
+ expect { step.run(1) }.should raise_error(CouldNotMeetError)
90
104
  end
91
105
  end
92
106
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 1
9
- version: 0.0.1
8
+ - 2
9
+ version: 0.0.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Pete Yandell
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-01-17 00:00:00 +11:00
17
+ date: 2011-01-21 00:00:00 +11:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -48,10 +48,9 @@ files:
48
48
  - lib/tango.rb
49
49
  - lib/tango/dance.rb
50
50
  - lib/tango/dance_builder.rb
51
+ - lib/tango/errors.rb
51
52
  - lib/tango/step.rb
52
- - lib/tango/step_builder.rb
53
53
  - lib/tango/step_runner.rb
54
- - lib/tango/step_runner_context.rb
55
54
  - lib/tango/version.rb
56
55
  - spec/dance_spec.rb
57
56
  - spec/step_spec.rb
@@ -1,17 +0,0 @@
1
- module Tango
2
- class StepBuilder
3
-
4
- def initialize(step)
5
- @step = step
6
- end
7
-
8
- def met?(&block)
9
- @step.met_block = block
10
- end
11
-
12
- def meet(&block)
13
- @step.meet_block = block
14
- end
15
-
16
- end
17
- end
@@ -1,13 +0,0 @@
1
- module Tango
2
- class StepRunnerContext
3
-
4
- def initialize(step)
5
- @step = step
6
- end
7
-
8
- def run(step_name, options = {})
9
- @step.dance.run(step_name, options)
10
- end
11
-
12
- end
13
- end