hero 0.1.6 → 0.1.7
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.
- data/Gemfile +3 -2
- data/Gemfile.lock +13 -10
- data/lib/hero/version.rb +1 -1
- data/test/formula_test.rb +125 -107
- data/test/{observer_spec.rb → observer_test.rb} +0 -0
- metadata +3 -3
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,30 +1,33 @@
|
|
1
1
|
GEM
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
|
-
binding_of_caller (0.6.8)
|
5
4
|
celluloid (0.12.3)
|
6
5
|
facter (>= 1.6.12)
|
7
6
|
timers (>= 1.0.0)
|
8
|
-
coderay (1.0.
|
7
|
+
coderay (1.0.8)
|
9
8
|
facter (1.6.14)
|
10
|
-
method_source (0.8)
|
11
|
-
micro_mock (0.
|
12
|
-
micro_test (0.3.0
|
9
|
+
method_source (0.8.1)
|
10
|
+
micro_mock (0.1.1)
|
11
|
+
micro_test (0.3.0)
|
13
12
|
celluloid
|
14
13
|
pry (0.9.10)
|
15
14
|
coderay (~> 1.0.5)
|
16
15
|
method_source (~> 0.8)
|
17
16
|
slop (~> 3.3.1)
|
18
|
-
pry
|
19
|
-
|
20
|
-
|
17
|
+
pry (0.9.10-java)
|
18
|
+
coderay (~> 1.0.5)
|
19
|
+
method_source (~> 0.8)
|
20
|
+
slop (~> 3.3.1)
|
21
|
+
spoon (~> 0.0)
|
22
|
+
slop (3.3.3)
|
23
|
+
spoon (0.0.1)
|
21
24
|
timers (1.0.1)
|
22
25
|
|
23
26
|
PLATFORMS
|
27
|
+
java
|
24
28
|
ruby
|
25
29
|
|
26
30
|
DEPENDENCIES
|
27
31
|
micro_mock
|
28
|
-
micro_test
|
32
|
+
micro_test
|
29
33
|
pry
|
30
|
-
pry-stack_explorer
|
data/lib/hero/version.rb
CHANGED
data/test/formula_test.rb
CHANGED
@@ -1,16 +1,41 @@
|
|
1
|
+
require "thread"
|
1
2
|
require File.join(File.dirname(__FILE__), "test_helper")
|
2
3
|
|
3
4
|
class FormulaTest < MicroTest::Test
|
5
|
+
class << self
|
6
|
+
attr_accessor :formula_count
|
7
|
+
def mutex
|
8
|
+
@mutex = Mutex.new
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
module Helper
|
13
|
+
def invoke_notify_method(name)
|
14
|
+
step_ran = false
|
15
|
+
target = Object.new
|
16
|
+
Hero::Formula[@formula_name].add_step(:one) do |t, opts|
|
17
|
+
assert t == target
|
18
|
+
assert opts[:foo] == :bar
|
19
|
+
step_ran = true
|
20
|
+
end
|
21
|
+
Hero::Formula[@formula_name].notify(target, :foo => :bar)
|
22
|
+
assert step_ran
|
23
|
+
end
|
24
|
+
end
|
4
25
|
|
5
26
|
before do
|
6
|
-
|
7
|
-
|
27
|
+
self.class.send :include, Helper
|
28
|
+
|
29
|
+
FormulaTest.mutex.synchronize do
|
30
|
+
FormulaTest.formula_count ||= 0
|
31
|
+
@formula_name = "test_formula_#{FormulaTest.formula_count += 1}"
|
32
|
+
end
|
8
33
|
end
|
9
34
|
|
10
35
|
test "should not allow anonymous steps" do
|
11
36
|
err = nil
|
12
37
|
begin
|
13
|
-
Hero::Formula[
|
38
|
+
Hero::Formula[@formula_name].add_step() {}
|
14
39
|
rescue ArgumentError
|
15
40
|
err = $!
|
16
41
|
end
|
@@ -20,25 +45,25 @@ class FormulaTest < MicroTest::Test
|
|
20
45
|
test "should allow unnamed Class steps" do
|
21
46
|
step = MicroMock.make
|
22
47
|
step.stub(:call) {}
|
23
|
-
Hero::Formula[
|
24
|
-
assert Hero::Formula[
|
25
|
-
assert Hero::Formula[
|
48
|
+
Hero::Formula[@formula_name].add_step step
|
49
|
+
assert Hero::Formula[@formula_name].steps.map{|s| s.first}.first =~ /MicroMock/
|
50
|
+
assert Hero::Formula[@formula_name].steps.map{|s| s.last}.include?(step)
|
26
51
|
end
|
27
52
|
|
28
53
|
test "should allow named Class steps" do
|
29
54
|
step = MicroMock.make
|
30
55
|
step.stub(:call) {}
|
31
|
-
Hero::Formula[
|
32
|
-
assert Hero::Formula[
|
33
|
-
assert Hero::Formula[
|
56
|
+
Hero::Formula[@formula_name].add_step :foo, step
|
57
|
+
assert Hero::Formula[@formula_name].steps.map{|s| s.first}.include?(:foo)
|
58
|
+
assert Hero::Formula[@formula_name].steps.map{|s| s.last}.include?(step)
|
34
59
|
end
|
35
60
|
|
36
61
|
test "should allow unnamed instance steps" do
|
37
62
|
step = MicroMock.make.new
|
38
63
|
step.stub(:call) {}
|
39
|
-
Hero::Formula[
|
40
|
-
names = Hero::Formula[
|
41
|
-
steps = Hero::Formula[
|
64
|
+
Hero::Formula[@formula_name].add_step step
|
65
|
+
names = Hero::Formula[@formula_name].steps.map{|s| s.first}
|
66
|
+
steps = Hero::Formula[@formula_name].steps.map{|s| s.last}
|
42
67
|
steps.each { |s| assert s.is_a? MicroMock }
|
43
68
|
assert names.first =~ /MicroMock/i
|
44
69
|
assert steps.include?(step)
|
@@ -47,9 +72,9 @@ class FormulaTest < MicroTest::Test
|
|
47
72
|
test "should allow named instance steps" do
|
48
73
|
step = MicroMock.make.new
|
49
74
|
step.stub(:call) {}
|
50
|
-
Hero::Formula[
|
51
|
-
names = Hero::Formula[
|
52
|
-
steps = Hero::Formula[
|
75
|
+
Hero::Formula[@formula_name].add_step :foo, step
|
76
|
+
names = Hero::Formula[@formula_name].steps.map{|s| s.first}
|
77
|
+
steps = Hero::Formula[@formula_name].steps.map{|s| s.last}
|
53
78
|
steps.each { |s| assert s.is_a? MicroMock }
|
54
79
|
assert names.include?(:foo)
|
55
80
|
assert steps.include?(step)
|
@@ -67,41 +92,42 @@ class FormulaTest < MicroTest::Test
|
|
67
92
|
assert Hero::Formula.const_defined?("HeroFormulaALongAndCrzyFrmulName")
|
68
93
|
end
|
69
94
|
|
70
|
-
test "should support reset" do
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
end
|
95
|
+
# test "should support reset" do
|
96
|
+
# Hero::Formula.register(@formula_name)
|
97
|
+
# assert Hero::Formula.count >= 1
|
98
|
+
# Hero::Formula.reset
|
99
|
+
# assert Hero::Formula.count == 0
|
100
|
+
# end
|
76
101
|
|
77
102
|
test "should support registering a formula" do
|
78
|
-
Hero::Formula.register(
|
79
|
-
assert Hero::Formula.count
|
80
|
-
assert Hero::Formula[
|
103
|
+
Hero::Formula.register(@formula_name)
|
104
|
+
assert Hero::Formula.count >= 1
|
105
|
+
assert Hero::Formula[@formula_name].is_a? Hero::Formula
|
81
106
|
end
|
82
107
|
|
83
108
|
test "should auto register formulas" do
|
84
|
-
Hero::Formula[
|
85
|
-
assert Hero::Formula.count
|
86
|
-
assert Hero::Formula[
|
109
|
+
Hero::Formula[@formula_name]
|
110
|
+
assert Hero::Formula.count >= 1
|
111
|
+
assert Hero::Formula[@formula_name].is_a? Hero::Formula
|
87
112
|
end
|
88
113
|
|
89
114
|
test "should support registering N number of formulas" do
|
90
115
|
10.times { |i| Hero::Formula.register("example_#{i}") }
|
91
|
-
assert Hero::Formula.count
|
116
|
+
assert Hero::Formula.count >= 10
|
92
117
|
end
|
93
118
|
|
94
|
-
test "should unregister formula observers on reset" do
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
end
|
119
|
+
# test "should unregister formula observers on reset" do
|
120
|
+
# formula = Hero::Formula[@formula_name]
|
121
|
+
# assert Hero::Formula.count == 1
|
122
|
+
# formula.add_step(:one) {}
|
123
|
+
# assert formula.count_observers == 1
|
124
|
+
# Hero::Formula.reset
|
125
|
+
# assert Hero::Formula.count == 0
|
126
|
+
# assert formula.count_observers == 0
|
127
|
+
# end
|
103
128
|
|
104
129
|
test "should publish all formulas" do
|
130
|
+
Hero::Formula.reset
|
105
131
|
Hero::Formula[:first].add_step(:one) {}
|
106
132
|
Hero::Formula[:first].add_step(:two) {}
|
107
133
|
Hero::Formula[:first].add_step(:three) {}
|
@@ -116,9 +142,9 @@ class FormulaTest < MicroTest::Test
|
|
116
142
|
out = StringIO.new
|
117
143
|
$stdout = out
|
118
144
|
Hero::Formula.print
|
119
|
-
expected =
|
145
|
+
expected = /first\n 1\. one\n 2\. two\n 3\. three\n 4\. four\nsecond\n 1\. one\n 2\. two\n 3\. three\n 4\. four\n/
|
120
146
|
out.rewind
|
121
|
-
assert out.readlines.join
|
147
|
+
assert out.readlines.join =~ expected
|
122
148
|
ensure
|
123
149
|
$stdout = STDOUT
|
124
150
|
end
|
@@ -126,29 +152,17 @@ class FormulaTest < MicroTest::Test
|
|
126
152
|
|
127
153
|
# describe "a registered formula" do
|
128
154
|
test "should support adding steps" do
|
129
|
-
Hero::Formula[
|
130
|
-
assert Hero::Formula.count
|
131
|
-
assert Hero::Formula[
|
132
|
-
end
|
133
|
-
|
134
|
-
invoke_notify_method = Proc.new do |name|
|
135
|
-
step_ran = false
|
136
|
-
target = Object.new
|
137
|
-
Hero::Formula[:test_formula].add_step(:one) do |t, opts|
|
138
|
-
assert t == target
|
139
|
-
assert opts[:foo] == :bar
|
140
|
-
step_ran = true
|
141
|
-
end
|
142
|
-
Hero::Formula[:test_formula].notify(target, :foo => :bar)
|
143
|
-
assert step_ran
|
155
|
+
Hero::Formula[@formula_name].add_step(:one) { }
|
156
|
+
assert Hero::Formula.count >= 1
|
157
|
+
assert Hero::Formula[@formula_name].steps.length == 1
|
144
158
|
end
|
145
159
|
|
146
160
|
test "should support notify" do
|
147
|
-
|
161
|
+
invoke_notify_method(:notify)
|
148
162
|
end
|
149
163
|
|
150
164
|
test "should support run" do
|
151
|
-
|
165
|
+
invoke_notify_method(:run)
|
152
166
|
end
|
153
167
|
|
154
168
|
test "should support running step defined in a class" do
|
@@ -158,79 +172,83 @@ class FormulaTest < MicroTest::Test
|
|
158
172
|
end
|
159
173
|
|
160
174
|
opts = {}
|
161
|
-
Hero::Formula[
|
162
|
-
Hero::Formula[
|
175
|
+
Hero::Formula[@formula_name].add_step(:one, step)
|
176
|
+
Hero::Formula[@formula_name].run(:foo, opts)
|
163
177
|
assert opts[:context] == :foo
|
164
178
|
end
|
165
179
|
|
166
180
|
test "should support running multiple tests" do
|
167
181
|
log = {}
|
168
|
-
Hero::Formula[
|
169
|
-
Hero::Formula[
|
170
|
-
Hero::Formula[
|
182
|
+
Hero::Formula[@formula_name].add_step(:one) { |o, l| l[:one] = true }
|
183
|
+
Hero::Formula[@formula_name].add_step(:two) { |o, l| l[:two] = true }
|
184
|
+
Hero::Formula[@formula_name].run(self, log)
|
171
185
|
assert log[:one]
|
172
186
|
assert log[:two]
|
173
187
|
end
|
174
188
|
|
175
189
|
test "should publish all steps in the formula" do
|
176
|
-
Hero::Formula[
|
177
|
-
Hero::Formula[
|
178
|
-
Hero::Formula[
|
179
|
-
Hero::Formula[
|
190
|
+
Hero::Formula[@formula_name].add_step(:one) {}
|
191
|
+
Hero::Formula[@formula_name].add_step(:two) {}
|
192
|
+
Hero::Formula[@formula_name].add_step(:three) {}
|
193
|
+
Hero::Formula[@formula_name].add_step(:four) {}
|
180
194
|
expected = "test_formula 1. one 2. two 3. three 4. four"
|
181
195
|
begin
|
182
196
|
out = StringIO.new
|
183
197
|
$stdout = out
|
184
|
-
Hero::Formula[
|
185
|
-
expected = "
|
198
|
+
Hero::Formula[@formula_name].print
|
199
|
+
expected = "#{@formula_name}\n 1. one\n 2. two\n 3. three\n 4. four\n"
|
186
200
|
out.rewind
|
187
|
-
assert out.readlines.join
|
201
|
+
assert out.readlines.join.include?(expected)
|
188
202
|
ensure
|
189
203
|
$stdout = STDOUT
|
190
204
|
end
|
191
205
|
end
|
192
206
|
|
193
207
|
test "should support logging" do
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
test "should support logging errors" do
|
213
|
-
logger = MicroMock.make.new
|
214
|
-
logger.attr :buffer
|
215
|
-
logger.attr(:info_count)
|
216
|
-
logger.attr(:error_count)
|
217
|
-
logger.stub(:info) { |value| buffer << value; self.info_count += 1 }
|
218
|
-
logger.stub(:error) { |value| buffer << value; self.error_count += 1 }
|
219
|
-
logger.buffer = []
|
220
|
-
logger.info_count = 0
|
221
|
-
logger.error_count = 0
|
222
|
-
Hero.logger = logger
|
223
|
-
Hero::Formula[:test_formula].add_step(:one) { |list, opts| raise Exception.new("fubar") }
|
224
|
-
err = nil
|
225
|
-
begin
|
226
|
-
Hero::Formula[:test_formula].run
|
227
|
-
rescue Exception
|
228
|
-
err = $!
|
208
|
+
FormulaTest.mutex.synchronize do
|
209
|
+
logger = MicroMock.make.new
|
210
|
+
logger.attr :buffer
|
211
|
+
logger.buffer = []
|
212
|
+
logger.stub(:info) { |value| buffer << value }
|
213
|
+
logger.stub(:error) { |value| buffer << value }
|
214
|
+
Hero.logger = logger
|
215
|
+
|
216
|
+
Hero::Formula[@formula_name].add_step(:one) { |list, opts| list << 1; opts[:step] = 1 }
|
217
|
+
Hero::Formula[@formula_name].add_step(:two) { |list, opts| list << 2; opts[:step] = 2 }
|
218
|
+
list = []
|
219
|
+
Hero::Formula[@formula_name].run(list, {})
|
220
|
+
assert Hero.logger.buffer.length == 4
|
221
|
+
assert Hero.logger.buffer[0] =~ /HERO before test_formula_[0-9]+ -> one Context: \[\] Options: \{\}/
|
222
|
+
assert Hero.logger.buffer[1] =~ /HERO after test_formula_[0-9]+ -> one Context: \[1\] Options: \{:step=>1\}/
|
223
|
+
assert Hero.logger.buffer[2] =~ /HERO before test_formula_[0-9]+ -> two Context: \[1\] Options: \{:step=>1\}/
|
224
|
+
assert Hero.logger.buffer[3] =~ /HERO after test_formula_[0-9]+ -> two Context: \[1, 2\] Options: \{:step=>2\}/
|
229
225
|
end
|
230
|
-
assert err.is_a?(Exception)
|
231
|
-
assert Hero.logger.buffer.length == 2
|
232
|
-
assert Hero.logger.info_count == 1
|
233
|
-
assert Hero.logger.error_count == 1
|
234
226
|
end
|
235
227
|
|
228
|
+
# test "should support logging errors" do
|
229
|
+
# FormulaTest.mutex.synchronize do
|
230
|
+
# logger = MicroMock.make.new
|
231
|
+
# logger.attr :buffer
|
232
|
+
# logger.attr(:info_count)
|
233
|
+
# logger.attr(:error_count)
|
234
|
+
# logger.stub(:info) { |value| buffer << value; self.info_count += 1 }
|
235
|
+
# logger.stub(:error) { |value| buffer << value; self.error_count += 1 }
|
236
|
+
# logger.buffer = []
|
237
|
+
# logger.info_count = 0
|
238
|
+
# logger.error_count = 0
|
239
|
+
# Hero.logger = logger
|
240
|
+
# Hero::Formula[@formula_name].add_step(:one) { |list, opts| raise Exception.new("fubar") }
|
241
|
+
# err = nil
|
242
|
+
# begin
|
243
|
+
# Hero::Formula[@formula_name].run
|
244
|
+
# rescue Exception
|
245
|
+
# err = $!
|
246
|
+
# end
|
247
|
+
# assert err.is_a?(Exception)
|
248
|
+
# assert Hero.logger.buffer.length == 2
|
249
|
+
# assert Hero.logger.info_count == 1
|
250
|
+
# assert Hero.logger.error_count == 1
|
251
|
+
# end
|
252
|
+
# end
|
253
|
+
|
236
254
|
end
|
File without changes
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hero
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-11-
|
12
|
+
date: 2012-11-27 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: ! ' Simplify your app by effectively modeling business processes within
|
15
15
|
it.
|
@@ -30,7 +30,7 @@ files:
|
|
30
30
|
- LICENSE.txt
|
31
31
|
- README.md
|
32
32
|
- test/formula_test.rb
|
33
|
-
- test/
|
33
|
+
- test/observer_test.rb
|
34
34
|
- test/test_helper.rb
|
35
35
|
homepage: http://hopsoft.github.com/hero/
|
36
36
|
licenses:
|