tango 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/lib/tango.rb +1 -2
- data/lib/tango/dance.rb +2 -5
- data/lib/tango/errors.rb +6 -0
- data/lib/tango/step.rb +5 -4
- data/lib/tango/step_runner.rb +11 -26
- data/lib/tango/version.rb +1 -1
- data/spec/dance_spec.rb +16 -18
- data/spec/step_spec.rb +35 -21
- metadata +4 -5
- data/lib/tango/step_builder.rb +0 -17
- data/lib/tango/step_runner_context.rb +0 -13
data/Gemfile.lock
CHANGED
data/lib/tango.rb
CHANGED
data/lib/tango/dance.rb
CHANGED
@@ -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,
|
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(
|
17
|
+
@steps[step_name].run(*args)
|
21
18
|
end
|
22
19
|
|
23
20
|
end
|
data/lib/tango/errors.rb
ADDED
data/lib/tango/step.rb
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
module Tango
|
2
2
|
class Step
|
3
3
|
def initialize(&block)
|
4
|
-
|
4
|
+
@block = block
|
5
5
|
end
|
6
6
|
|
7
|
-
attr_accessor :dance
|
7
|
+
attr_accessor :dance
|
8
|
+
attr_reader :block
|
8
9
|
|
9
|
-
def run(
|
10
|
-
StepRunner.new(self,
|
10
|
+
def run(*args)
|
11
|
+
StepRunner.new(self).instance_exec(*args, &block)
|
11
12
|
end
|
12
13
|
end
|
13
14
|
end
|
data/lib/tango/step_runner.rb
CHANGED
@@ -1,39 +1,24 @@
|
|
1
1
|
module Tango
|
2
2
|
class StepRunner
|
3
3
|
|
4
|
-
def initialize(step
|
5
|
-
@step
|
6
|
-
@options = options
|
7
|
-
@context = StepRunnerContext.new(@step)
|
4
|
+
def initialize(step)
|
5
|
+
@step = step
|
8
6
|
end
|
9
7
|
|
10
|
-
def
|
11
|
-
|
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
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
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
|
28
|
-
|
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
|
data/lib/tango/version.rb
CHANGED
data/spec/dance_spec.rb
CHANGED
@@ -8,7 +8,7 @@ module Tango
|
|
8
8
|
|
9
9
|
dance = Dance.new do
|
10
10
|
step "example step" do
|
11
|
-
|
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
|
-
|
24
|
+
run "inner step"
|
25
25
|
end
|
26
26
|
|
27
27
|
step "inner step" do
|
28
|
-
|
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 "
|
37
|
-
it "should pass
|
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
|
-
|
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",
|
45
|
+
dance.run "example step", 1, 2
|
47
46
|
end
|
48
47
|
|
49
|
-
it "should pass
|
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
|
-
|
51
|
+
run "inner step", 1, 2
|
55
52
|
end
|
56
53
|
|
57
|
-
step "inner step" do
|
58
|
-
|
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(
|
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(
|
79
|
+
end.should raise_error(UndefinedStepError)
|
82
80
|
end
|
83
81
|
end
|
84
82
|
|
data/spec/step_spec.rb
CHANGED
@@ -3,15 +3,15 @@ require 'tango'
|
|
3
3
|
module Tango
|
4
4
|
describe Step do
|
5
5
|
|
6
|
-
context "with just a
|
7
|
-
it "should run the
|
8
|
-
|
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
|
-
|
10
|
+
block_calls += 1
|
11
11
|
end
|
12
12
|
|
13
13
|
step.run
|
14
|
-
|
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
|
-
|
74
|
-
options.should == step_options
|
75
|
-
true
|
76
|
-
end
|
69
|
+
meet { }
|
77
70
|
end
|
78
71
|
|
79
|
-
step.run(
|
72
|
+
expect { step.run }.should raise_error(MeetWithoutMetError)
|
80
73
|
end
|
74
|
+
end
|
81
75
|
|
82
|
-
|
83
|
-
|
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
|
86
|
-
|
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(
|
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
|
-
-
|
9
|
-
version: 0.0.
|
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
|
+
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
|
data/lib/tango/step_builder.rb
DELETED