schmurfy-bacon 1.3.2 → 1.3.3
Sign up to get free protection for your applications and to get access to all the features.
- data/examples/em_spec.rb +10 -5
- data/examples/nested_contexts_spec.rb +0 -1
- data/lib/bacon.rb +21 -15
- data/lib/bacon/ext/em.rb +19 -28
- data/lib/bacon/version.rb +1 -1
- metadata +6 -6
data/examples/em_spec.rb
CHANGED
@@ -2,8 +2,8 @@ require 'rubygems'
|
|
2
2
|
|
3
3
|
$LOAD_PATH.unshift << File.expand_path('../../lib/', __FILE__)
|
4
4
|
|
5
|
-
require 'bacon/ext/em'
|
6
5
|
require 'bacon'
|
6
|
+
require 'bacon/ext/em'
|
7
7
|
|
8
8
|
Bacon.summary_on_exit
|
9
9
|
|
@@ -14,10 +14,6 @@ def run_something_later(&block)
|
|
14
14
|
end
|
15
15
|
|
16
16
|
describe 'AsynchronousSpec' do
|
17
|
-
# tell bacon we want to run inside
|
18
|
-
# the EventMachine reactor
|
19
|
-
with_eventmachine!
|
20
|
-
|
21
17
|
before do
|
22
18
|
# Eventmachine is running, yeah !
|
23
19
|
EM::reactor_running?.should == true
|
@@ -48,4 +44,13 @@ describe 'AsynchronousSpec' do
|
|
48
44
|
wait(0.2){ v.should == 2 }
|
49
45
|
end
|
50
46
|
|
47
|
+
# if done is called the test ends early
|
48
|
+
# but the block passed to wait is till called
|
49
|
+
should 'end early' do
|
50
|
+
v = 1
|
51
|
+
EM::add_timer(0.2){ v+= 1; done }
|
52
|
+
EM::add_timer(0.3){ v = 3 }
|
53
|
+
wait(1){ v.should == 2 }
|
54
|
+
end
|
55
|
+
|
51
56
|
end
|
data/lib/bacon.rb
CHANGED
@@ -140,14 +140,15 @@ module Bacon
|
|
140
140
|
end
|
141
141
|
end
|
142
142
|
|
143
|
-
def
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
143
|
+
def create_context(name, &block)
|
144
|
+
Bacon::Context.new(name, &block)
|
145
|
+
end
|
146
|
+
|
147
|
+
def run
|
148
|
+
Counter[:context_depth] += 1
|
149
|
+
Bacon.handle_specification(name) { instance_eval(&block) }
|
150
|
+
Counter[:context_depth] -= 1
|
151
|
+
self
|
151
152
|
end
|
152
153
|
end
|
153
154
|
|
@@ -161,13 +162,6 @@ module Bacon
|
|
161
162
|
@before, @after = [], []
|
162
163
|
@block = block
|
163
164
|
end
|
164
|
-
|
165
|
-
def run
|
166
|
-
Counter[:context_depth] += 1
|
167
|
-
Bacon.handle_specification(name) { instance_eval(&block) }
|
168
|
-
Counter[:context_depth] -= 1
|
169
|
-
self
|
170
|
-
end
|
171
165
|
|
172
166
|
def before(&block); @before << block; end
|
173
167
|
def after(&block); @after << block; end
|
@@ -184,6 +178,18 @@ module Bacon
|
|
184
178
|
end
|
185
179
|
end
|
186
180
|
|
181
|
+
def describe(*args, &block)
|
182
|
+
context = create_context(args.join(' '), &block)
|
183
|
+
|
184
|
+
# define any user methods in the new context so
|
185
|
+
# that helpers defined in main describe can be used in nested contexts
|
186
|
+
(parent_context = self).methods(false).each {|e|
|
187
|
+
class<<context; self end.send(:define_method, e) {|*args| parent_context.send(e, *args)}
|
188
|
+
}
|
189
|
+
@before.each { |b| context.before(&b) }
|
190
|
+
@after.each { |b| context.after(&b) }
|
191
|
+
context.run
|
192
|
+
end
|
187
193
|
|
188
194
|
def focus(spec_str)
|
189
195
|
raise "focused test forbidden" unless Bacon::allow_focused_run?
|
data/lib/bacon/ext/em.rb
CHANGED
@@ -10,49 +10,40 @@ require 'eventmachine'
|
|
10
10
|
# ever be raised.
|
11
11
|
#
|
12
12
|
module Bacon
|
13
|
-
class Context
|
14
|
-
def with_eventmachine!
|
15
|
-
(class << self; self; end).send(:include, EMSpec)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
13
|
module EMSpec # :nodoc:
|
20
14
|
|
21
15
|
def wait(timeout = 0.1, &block)
|
22
|
-
waiting_fiber = Fiber.current
|
16
|
+
@waiting_fiber = Fiber.current
|
23
17
|
EM::cancel_timer(@timeout)
|
24
|
-
@timeout = EM::add_timer(timeout){ waiting_fiber.resume }
|
18
|
+
@timeout = EM::add_timer(timeout){ @waiting_fiber.resume }
|
25
19
|
Fiber.yield
|
26
20
|
|
21
|
+
@waiting_fiber = nil
|
22
|
+
|
27
23
|
block.call if block
|
28
24
|
end
|
29
25
|
|
30
26
|
def done
|
31
27
|
EM.cancel_timer(@timeout)
|
32
|
-
|
33
|
-
end
|
34
|
-
|
35
|
-
def describe(*, &block)
|
36
|
-
super do
|
37
|
-
with_eventmachine!
|
38
|
-
block.call
|
39
|
-
end
|
28
|
+
@waiting_fiber.resume if @waiting_fiber
|
40
29
|
end
|
41
|
-
|
42
|
-
def
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
30
|
+
|
31
|
+
def run(*)
|
32
|
+
subcontext = EM::reactor_running?
|
33
|
+
if subcontext
|
34
|
+
super
|
35
|
+
else
|
36
|
+
EM::run do
|
37
|
+
Fiber.new do
|
38
|
+
super
|
39
|
+
EM::stop_event_loop
|
40
|
+
end.resume
|
41
|
+
end
|
42
|
+
|
52
43
|
end
|
53
44
|
end
|
54
45
|
|
55
46
|
end
|
56
47
|
|
57
|
-
|
48
|
+
Context.send(:include, EMSpec)
|
58
49
|
end
|
data/lib/bacon/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: schmurfy-bacon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-04-
|
12
|
+
date: 2012-04-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: term-ansicolor
|
16
|
-
requirement: &
|
16
|
+
requirement: &70253621968160 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70253621968160
|
25
25
|
description: ! 'Bacon is a small RSpec clone weighing less than 350 LoC but
|
26
26
|
|
27
27
|
nevertheless providing all essential features.
|
@@ -77,7 +77,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
77
77
|
version: '0'
|
78
78
|
segments:
|
79
79
|
- 0
|
80
|
-
hash:
|
80
|
+
hash: 3307888883450251243
|
81
81
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
82
|
none: false
|
83
83
|
requirements:
|
@@ -86,7 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
86
86
|
version: '0'
|
87
87
|
segments:
|
88
88
|
- 0
|
89
|
-
hash:
|
89
|
+
hash: 3307888883450251243
|
90
90
|
requirements: []
|
91
91
|
rubyforge_project:
|
92
92
|
rubygems_version: 1.8.11
|