hero 0.1.3 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,6 +1,8 @@
1
1
  source :rubygems
2
2
 
3
- gem "rspec", :group => :test
4
- gem "grumpy_old_man", :group => :test
5
- gem "pry", :groups => [:development, :test]
6
- gem "pry_debug", :groups => [:development, :test]
3
+ group :development do
4
+ gem "micro_test", "0.3.0.rc4"
5
+ gem "micro_mock"
6
+ gem "pry"
7
+ gem "pry-stack_explorer"
8
+ end
data/Gemfile.lock CHANGED
@@ -1,31 +1,30 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
+ binding_of_caller (0.6.8)
5
+ celluloid (0.12.3)
6
+ facter (>= 1.6.12)
7
+ timers (>= 1.0.0)
4
8
  coderay (1.0.7)
5
- diff-lcs (1.1.3)
6
- grumpy_old_man (0.1.2)
9
+ facter (1.6.14)
7
10
  method_source (0.8)
11
+ micro_mock (0.0.8)
12
+ micro_test (0.3.0.rc4)
13
+ celluloid
8
14
  pry (0.9.10)
9
15
  coderay (~> 1.0.5)
10
16
  method_source (~> 0.8)
11
17
  slop (~> 3.3.1)
12
- pry_debug (0.0.1)
13
- pry (~> 0.9.0)
14
- rspec (2.11.0)
15
- rspec-core (~> 2.11.0)
16
- rspec-expectations (~> 2.11.0)
17
- rspec-mocks (~> 2.11.0)
18
- rspec-core (2.11.1)
19
- rspec-expectations (2.11.2)
20
- diff-lcs (~> 1.1.3)
21
- rspec-mocks (2.11.2)
18
+ pry-stack_explorer (0.4.7)
19
+ binding_of_caller (~> 0.6.8)
22
20
  slop (3.3.2)
21
+ timers (1.0.1)
23
22
 
24
23
  PLATFORMS
25
24
  ruby
26
25
 
27
26
  DEPENDENCIES
28
- grumpy_old_man
27
+ micro_mock
28
+ micro_test (= 0.3.0.rc4)
29
29
  pry
30
- pry_debug
31
- rspec
30
+ pry-stack_explorer
data/README.md CHANGED
@@ -213,3 +213,13 @@ Hero::Formula[:log_example].run([])
213
213
  # I, [2012-08-26T11:37:22.267282 #76676] INFO -- : HERO before log_example -> third_step Context: [1, 2] Options: {}
214
214
  # I, [2012-08-26T11:37:22.267333 #76676] INFO -- : HERO after log_example -> third_step Context: [1, 2, 3] Options: {}
215
215
  ```
216
+
217
+ ## Run the Tests
218
+
219
+ ```bash
220
+ $ gem install hero
221
+ $ gem unpack hero
222
+ $ cd hero-VERSION
223
+ $ bundle
224
+ $ mt
225
+ ```
data/lib/hero/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Hero
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.5"
3
3
  end
@@ -0,0 +1,236 @@
1
+ require File.join(File.dirname(__FILE__), "test_helper")
2
+
3
+ class FormulaTest < MicroTest::Test
4
+
5
+ before do
6
+ Hero.logger = nil
7
+ Hero::Formula.reset
8
+ end
9
+
10
+ test "should not allow anonymous steps" do
11
+ err = nil
12
+ begin
13
+ Hero::Formula[:test_formula].add_step() {}
14
+ rescue ArgumentError
15
+ err = $!
16
+ end
17
+ assert err.is_a?(ArgumentError)
18
+ end
19
+
20
+ test "should allow unnamed Class steps" do
21
+ step = MicroMock.make
22
+ step.stub(:call) {}
23
+ Hero::Formula[:test_formula].add_step step
24
+ assert Hero::Formula[:test_formula].steps.map{|s| s.first}.first =~ /MicroMock/
25
+ assert Hero::Formula[:test_formula].steps.map{|s| s.last}.include?(step)
26
+ end
27
+
28
+ test "should allow named Class steps" do
29
+ step = MicroMock.make
30
+ step.stub(:call) {}
31
+ Hero::Formula[:test_formula].add_step :foo, step
32
+ assert Hero::Formula[:test_formula].steps.map{|s| s.first}.include?(:foo)
33
+ assert Hero::Formula[:test_formula].steps.map{|s| s.last}.include?(step)
34
+ end
35
+
36
+ test "should allow unnamed instance steps" do
37
+ step = MicroMock.make.new
38
+ step.stub(:call) {}
39
+ Hero::Formula[:test_formula].add_step step
40
+ names = Hero::Formula[:test_formula].steps.map{|s| s.first}
41
+ steps = Hero::Formula[:test_formula].steps.map{|s| s.last}
42
+ steps.each { |s| assert s.is_a? MicroMock }
43
+ assert names.first =~ /MicroMock/i
44
+ assert steps.include?(step)
45
+ end
46
+
47
+ test "should allow named instance steps" do
48
+ step = MicroMock.make.new
49
+ step.stub(:call) {}
50
+ Hero::Formula[:test_formula].add_step :foo, step
51
+ names = Hero::Formula[:test_formula].steps.map{|s| s.first}
52
+ steps = Hero::Formula[:test_formula].steps.map{|s| s.last}
53
+ steps.each { |s| assert s.is_a? MicroMock }
54
+ assert names.include?(:foo)
55
+ assert steps.include?(step)
56
+ end
57
+
58
+ test "should create a named class" do
59
+ Hero::Formula[:my_formula]
60
+ assert Object.const_defined?("HeroFormulaMyFormula")
61
+ assert Hero::Formula[:my_formula].class.name == "HeroFormulaMyFormula"
62
+ assert Hero::Formula[:my_formula].is_a? HeroFormulaMyFormula
63
+ end
64
+
65
+ test "should safely create a named class" do
66
+ Hero::Formula["A long and cr@zy f0rmul@ name ~12$%"]
67
+ assert Hero::Formula.const_defined?("HeroFormulaALongAndCrzyFrmulName")
68
+ end
69
+
70
+ test "should support reset" do
71
+ Hero::Formula.register(:test_formula)
72
+ assert Hero::Formula.count == 1
73
+ Hero::Formula.reset
74
+ assert Hero::Formula.count == 0
75
+ end
76
+
77
+ test "should support registering a formula" do
78
+ Hero::Formula.register(:test_formula)
79
+ assert Hero::Formula.count == 1
80
+ assert Hero::Formula[:test_formula].is_a? Hero::Formula
81
+ end
82
+
83
+ test "should auto register formulas" do
84
+ Hero::Formula[:test_formula]
85
+ assert Hero::Formula.count == 1
86
+ assert Hero::Formula[:test_formula].is_a? Hero::Formula
87
+ end
88
+
89
+ test "should support registering N number of formulas" do
90
+ 10.times { |i| Hero::Formula.register("example_#{i}") }
91
+ assert Hero::Formula.count == 10
92
+ end
93
+
94
+ test "should unregister formula observers on reset" do
95
+ formula = Hero::Formula[:test_formula]
96
+ assert Hero::Formula.count == 1
97
+ formula.add_step(:one) {}
98
+ assert formula.count_observers == 1
99
+ Hero::Formula.reset
100
+ assert Hero::Formula.count == 0
101
+ assert formula.count_observers == 0
102
+ end
103
+
104
+ test "should publish all formulas" do
105
+ Hero::Formula[:first].add_step(:one) {}
106
+ Hero::Formula[:first].add_step(:two) {}
107
+ Hero::Formula[:first].add_step(:three) {}
108
+ Hero::Formula[:first].add_step(:four) {}
109
+
110
+ Hero::Formula[:second].add_step(:one) {}
111
+ Hero::Formula[:second].add_step(:two) {}
112
+ Hero::Formula[:second].add_step(:three) {}
113
+ Hero::Formula[:second].add_step(:four) {}
114
+
115
+ begin
116
+ out = StringIO.new
117
+ $stdout = out
118
+ Hero::Formula.print
119
+ 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
+ out.rewind
121
+ assert out.readlines.join == expected
122
+ ensure
123
+ $stdout = STDOUT
124
+ end
125
+ end
126
+
127
+ # describe "a registered formula" do
128
+ test "should support adding steps" do
129
+ Hero::Formula[:test_formula].add_step(:one) { }
130
+ assert Hero::Formula.count == 1
131
+ assert Hero::Formula[:test_formula].steps.length == 1
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
144
+ end
145
+
146
+ test "should support notify" do
147
+ instance_exec(:notify, &invoke_notify_method)
148
+ end
149
+
150
+ test "should support run" do
151
+ instance_exec(:run, &invoke_notify_method)
152
+ end
153
+
154
+ test "should support running step defined in a class" do
155
+ step = MicroMock.make.new
156
+ step.stub(:call) do |context, options|
157
+ options[:context] = context
158
+ end
159
+
160
+ opts = {}
161
+ Hero::Formula[:test_formula].add_step(:one, step)
162
+ Hero::Formula[:test_formula].run(:foo, opts)
163
+ assert opts[:context] == :foo
164
+ end
165
+
166
+ test "should support running multiple tests" do
167
+ log = {}
168
+ Hero::Formula[:test_formula].add_step(:one) { |o, l| l[:one] = true }
169
+ Hero::Formula[:test_formula].add_step(:two) { |o, l| l[:two] = true }
170
+ Hero::Formula[:test_formula].run(self, log)
171
+ assert log[:one]
172
+ assert log[:two]
173
+ end
174
+
175
+ test "should publish all steps in the formula" do
176
+ Hero::Formula[:test_formula].add_step(:one) {}
177
+ Hero::Formula[:test_formula].add_step(:two) {}
178
+ Hero::Formula[:test_formula].add_step(:three) {}
179
+ Hero::Formula[:test_formula].add_step(:four) {}
180
+ expected = "test_formula 1. one 2. two 3. three 4. four"
181
+ begin
182
+ out = StringIO.new
183
+ $stdout = out
184
+ Hero::Formula[:test_formula].print
185
+ expected = "test_formula\n 1. one\n 2. two\n 3. three\n 4. four\n"
186
+ out.rewind
187
+ assert out.readlines.join == expected
188
+ ensure
189
+ $stdout = STDOUT
190
+ end
191
+ end
192
+
193
+ test "should support logging" do
194
+ logger = MicroMock.make.new
195
+ logger.attr :buffer
196
+ logger.buffer = []
197
+ logger.stub(:info) { |value| buffer << value }
198
+ logger.stub(:error) { |value| buffer << value }
199
+ Hero.logger = logger
200
+
201
+ Hero::Formula[:test_formula].add_step(:one) { |list, opts| list << 1; opts[:step] = 1 }
202
+ Hero::Formula[:test_formula].add_step(:two) { |list, opts| list << 2; opts[:step] = 2 }
203
+ list = []
204
+ Hero::Formula[:test_formula].run(list, {})
205
+ assert Hero.logger.buffer.length == 4
206
+ assert "HERO before test_formula -> one Context: [] Options: {}" == Hero.logger.buffer[0]
207
+ assert "HERO after test_formula -> one Context: [1] Options: {:step=>1}" == Hero.logger.buffer[1]
208
+ assert "HERO before test_formula -> two Context: [1] Options: {:step=>1}" == Hero.logger.buffer[2]
209
+ assert "HERO after test_formula -> two Context: [1, 2] Options: {:step=>2}" == Hero.logger.buffer[3]
210
+ end
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 = $!
229
+ 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
+ end
235
+
236
+ end
@@ -0,0 +1,37 @@
1
+ require File.join(File.dirname(__FILE__), "test_helper")
2
+
3
+ class ObserverTest < MicroTest::Test
4
+ test "should support add_step" do
5
+ step = lambda {}
6
+ o = Hero::Observer.new(:example)
7
+ o.add_step(:one, step)
8
+ assert o.steps.length == 1
9
+ assert o.steps[0].first == :one
10
+ assert o.steps[0].last == step
11
+ end
12
+
13
+ test "should support properly handle a double add" do
14
+ step1 = lambda {}
15
+ step2 = lambda {}
16
+ o = Hero::Observer.new(:example)
17
+ o.add_step(:one, step1)
18
+ o.add_step(:one, step2)
19
+ assert o.steps.length == 1
20
+ assert o.steps[0].first == :one
21
+ assert o.steps[0].last == step2
22
+ end
23
+
24
+ test "should properly sort steps based on the order they were added" do
25
+ o = Hero::Observer.new(:example)
26
+ o.add_step(:one) {}
27
+ o.add_step(:two) {}
28
+ o.add_step(:three) {}
29
+ o.add_step(:four) {}
30
+ o.add_step(:one) {}
31
+ assert o.steps.length == 4
32
+ assert o.steps[0].first == :two
33
+ assert o.steps[1].first == :three
34
+ assert o.steps[2].first == :four
35
+ assert o.steps[3].first == :one
36
+ end
37
+ end
@@ -1,5 +1,6 @@
1
- require "pry"
2
- require "grumpy_old_man"
1
+ require "bundler"
2
+ Bundler.require :default, :development
3
+
3
4
  Dir[File.join(File.dirname(__FILE__), "..", "lib", "*.rb")].each do |file|
4
5
  require file
5
6
  end
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.3
4
+ version: 0.1.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -29,9 +29,9 @@ files:
29
29
  - Gemfile.lock
30
30
  - LICENSE.txt
31
31
  - README.md
32
- - spec/formula_spec.rb
33
- - spec/observer_spec.rb
34
- - spec/spec_helper.rb
32
+ - test/formula_test.rb
33
+ - test/observer_spec.rb
34
+ - test/test_helper.rb
35
35
  homepage: http://hopsoft.github.com/hero/
36
36
  licenses:
37
37
  - MIT
@@ -56,6 +56,6 @@ rubyforge_project:
56
56
  rubygems_version: 1.8.23
57
57
  signing_key:
58
58
  specification_version: 3
59
- summary: You can think of Hero as a simplified state machine.
59
+ summary: Think of Hero as a simplified state machine.
60
60
  test_files: []
61
61
  has_rdoc:
data/spec/formula_spec.rb DELETED
@@ -1,235 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Hero::Formula do
4
- include GrumpyOldMan
5
-
6
- before :each do
7
- Hero.logger = nil
8
- Hero::Formula.reset
9
- end
10
-
11
- it "should not allow anonymous steps" do
12
- assert_raise ArgumentError do
13
- Hero::Formula[:test_formula].add_step() {}
14
- end
15
- end
16
-
17
- it "should allow unnamed Class steps" do
18
- class MyStep
19
- def self.call(*args); end
20
- end
21
- Hero::Formula[:test_formula].add_step MyStep
22
- assert Hero::Formula[:test_formula].steps.map{|s| s.first}.include?("MyStep")
23
- assert Hero::Formula[:test_formula].steps.map{|s| s.last}.include?(MyStep)
24
- end
25
-
26
- it "should allow named Class steps" do
27
- class MyStep
28
- def self.call(*args); end
29
- end
30
- Hero::Formula[:test_formula].add_step :foo, MyStep
31
- assert Hero::Formula[:test_formula].steps.map{|s| s.first}.include?(:foo)
32
- assert Hero::Formula[:test_formula].steps.map{|s| s.last}.include?(MyStep)
33
- end
34
-
35
- it "should allow unnamed instance steps" do
36
- class MyStep
37
- def call(*args); end
38
- end
39
- step = MyStep.new
40
- Hero::Formula[:test_formula].add_step step
41
- names = Hero::Formula[:test_formula].steps.map{|s| s.first}
42
- steps = Hero::Formula[:test_formula].steps.map{|s| s.last}
43
- steps.each { |s| assert s.is_a? MyStep }
44
- assert names.include?("MyStep")
45
- assert steps.include?(step)
46
- end
47
-
48
- it "should allow named instance steps" do
49
- class MyStep
50
- def call(*args); end
51
- end
52
- step = MyStep.new
53
- Hero::Formula[:test_formula].add_step :foo, step
54
- names = Hero::Formula[:test_formula].steps.map{|s| s.first}
55
- steps = Hero::Formula[:test_formula].steps.map{|s| s.last}
56
- steps.each { |s| assert s.is_a? MyStep }
57
- assert names.include?(:foo)
58
- assert steps.include?(step)
59
- end
60
-
61
- it "should create a named class" do
62
- Hero::Formula[:my_formula]
63
- assert Object.const_defined?("HeroFormulaMyFormula")
64
- assert_equal Hero::Formula[:my_formula].class.name, "HeroFormulaMyFormula"
65
- assert Hero::Formula[:my_formula].is_a? HeroFormulaMyFormula
66
- end
67
-
68
- it "should safely create a named class" do
69
- Hero::Formula["A long and cr@zy f0rmul@ name ~12$%"]
70
- assert Hero::Formula.const_defined?("HeroFormulaALongAndCrzyFrmulName")
71
- end
72
-
73
- it "should support reset" do
74
- Hero::Formula.register(:test_formula)
75
- assert_equal Hero::Formula.count, 1
76
- Hero::Formula.reset
77
- assert_equal Hero::Formula.count, 0
78
- end
79
-
80
- it "should support registering a formula" do
81
- Hero::Formula.register(:test_formula)
82
- assert_equal Hero::Formula.count, 1
83
- assert Hero::Formula[:test_formula].is_a? Hero::Formula
84
- end
85
-
86
- it "should auto register formulas" do
87
- Hero::Formula[:test_formula]
88
- assert_equal Hero::Formula.count, 1
89
- assert Hero::Formula[:test_formula].is_a? Hero::Formula
90
- end
91
-
92
- it "should support registering N number of formulas" do
93
- 10.times { |i| Hero::Formula.register("example_#{i}") }
94
- assert_equal Hero::Formula.count, 10
95
- end
96
-
97
- it "should unregister formula observers on reset" do
98
- formula = Hero::Formula[:test_formula]
99
- assert_equal Hero::Formula.count, 1
100
- formula.add_step(:one) {}
101
- assert_equal formula.count_observers, 1
102
- Hero::Formula.reset
103
- assert_equal Hero::Formula.count, 0
104
- assert_equal formula.count_observers, 0
105
- end
106
-
107
- it "should publish all formulas" do
108
- Hero::Formula[:first].add_step(:one) {}
109
- Hero::Formula[:first].add_step(:two) {}
110
- Hero::Formula[:first].add_step(:three) {}
111
- Hero::Formula[:first].add_step(:four) {}
112
-
113
- Hero::Formula[:second].add_step(:one) {}
114
- Hero::Formula[:second].add_step(:two) {}
115
- Hero::Formula[:second].add_step(:three) {}
116
- Hero::Formula[:second].add_step(:four) {}
117
-
118
- begin
119
- out = StringIO.new
120
- $stdout = out
121
- Hero::Formula.print
122
- 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"
123
- out.rewind
124
- assert_equal out.readlines.join, expected
125
- ensure
126
- $stdout = STDOUT
127
- end
128
- end
129
-
130
- describe "a registered formula" do
131
- it "should support adding steps" do
132
- Hero::Formula[:test_formula].add_step(:one) { }
133
- assert_equal Hero::Formula.count, 1
134
- assert_equal Hero::Formula[:test_formula].steps.length, 1
135
- end
136
-
137
- def invoke_notify_method(name)
138
- step_ran = false
139
- target = Object.new
140
- Hero::Formula[:test_formula].add_step(:one) do |t, opts|
141
- assert_equal t, target
142
- assert_equal opts[:foo], :bar
143
- step_ran = true
144
- end
145
- Hero::Formula[:test_formula].notify(target, :foo => :bar)
146
- assert step_ran
147
- end
148
-
149
- it "should support notify" do
150
- invoke_notify_method(:notify)
151
- end
152
-
153
- it "should support run" do
154
- invoke_notify_method(:run)
155
- end
156
-
157
- it "should support running step defined in a class" do
158
- class Step
159
- def call(context, options)
160
- options[:context] = context
161
- end
162
- end
163
-
164
- opts = {}
165
- Hero::Formula[:test_formula].add_step(:one, Step.new)
166
- Hero::Formula[:test_formula].run(:foo, opts)
167
- assert_equal opts[:context], :foo
168
- end
169
-
170
- it "should support running multiple tests" do
171
- log = {}
172
- Hero::Formula[:test_formula].add_step(:one) { |o, l| l[:one] = true }
173
- Hero::Formula[:test_formula].add_step(:two) { |o, l| l[:two] = true }
174
- Hero::Formula[:test_formula].run(self, log)
175
- assert log[:one]
176
- assert log[:two]
177
- end
178
-
179
- it "should publish all steps in the formula" do
180
- Hero::Formula[:test_formula].add_step(:one) {}
181
- Hero::Formula[:test_formula].add_step(:two) {}
182
- Hero::Formula[:test_formula].add_step(:three) {}
183
- Hero::Formula[:test_formula].add_step(:four) {}
184
- expected = "test_formula 1. one 2. two 3. three 4. four"
185
- begin
186
- out = StringIO.new
187
- $stdout = out
188
- Hero::Formula[:test_formula].print
189
- expected = "test_formula\n 1. one\n 2. two\n 3. three\n 4. four\n"
190
- out.rewind
191
- assert_equal out.readlines.join, expected
192
- ensure
193
- $stdout = STDOUT
194
- end
195
- end
196
-
197
- it "should support logging" do
198
- class TestLogger
199
- attr_reader :buffer
200
- def initialize; @buffer = []; end
201
- def info(value); @buffer << value; end
202
- alias :error :info
203
- end
204
- Hero.logger = TestLogger.new
205
-
206
- Hero::Formula[:test_formula].add_step(:one) { |list, opts| list << 1; opts[:step] = 1 }
207
- Hero::Formula[:test_formula].add_step(:two) { |list, opts| list << 2; opts[:step] = 2 }
208
- list = []
209
- Hero::Formula[:test_formula].run(list, {})
210
- assert_equal Hero.logger.buffer.length, 4
211
- assert_equal "HERO before test_formula -> one Context: [] Options: {}", Hero.logger.buffer[0]
212
- assert_equal "HERO after test_formula -> one Context: [1] Options: {:step=>1}", Hero.logger.buffer[1]
213
- assert_equal "HERO before test_formula -> two Context: [1] Options: {:step=>1}", Hero.logger.buffer[2]
214
- assert_equal "HERO after test_formula -> two Context: [1, 2] Options: {:step=>2}", Hero.logger.buffer[3]
215
- end
216
-
217
- it "should support logging errors" do
218
- class TestLogger
219
- attr_reader :info_count, :error_count, :buffer
220
- def initialize; @info_count = 0; @error_count = 0; @buffer = []; end
221
- def info(value); @info_count += 1; @buffer << value; end
222
- def error(value); @error_count += 1; @buffer << value; end
223
- end
224
- Hero.logger = TestLogger.new
225
- Hero::Formula[:test_formula].add_step(:one) { |list, opts| raise Exception.new("fubar") }
226
- assert_raise(Exception) { Hero::Formula[:test_formula].run }
227
- assert_equal Hero.logger.buffer.length, 2
228
- assert_equal Hero.logger.info_count, 1
229
- assert_equal Hero.logger.error_count, 1
230
- end
231
-
232
- end
233
-
234
- end
235
-
@@ -1,39 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe "Hero::Observer instance" do
4
- include GrumpyOldMan
5
-
6
- it "should support add_step" do
7
- step = lambda {}
8
- o = Hero::Observer.new(:example)
9
- o.add_step(:one, step)
10
- assert_equal o.steps.length, 1
11
- assert_equal o.steps[0].first, :one
12
- assert_equal o.steps[0].last, step
13
- end
14
-
15
- it "should support properly handle a double add" do
16
- step1 = lambda {}
17
- step2 = lambda {}
18
- o = Hero::Observer.new(:example)
19
- o.add_step(:one, step1)
20
- o.add_step(:one, step2)
21
- assert_equal o.steps.length, 1
22
- assert_equal o.steps[0].first, :one
23
- assert_equal o.steps[0].last, step2
24
- end
25
-
26
- it "should properly sort steps based on the order they were added" do
27
- o = Hero::Observer.new(:example)
28
- o.add_step(:one) {}
29
- o.add_step(:two) {}
30
- o.add_step(:three) {}
31
- o.add_step(:four) {}
32
- o.add_step(:one) {}
33
- assert_equal o.steps.length, 4
34
- assert_equal o.steps[0].first, :two
35
- assert_equal o.steps[1].first, :three
36
- assert_equal o.steps[2].first, :four
37
- assert_equal o.steps[3].first, :one
38
- end
39
- end