schmurfy-bacon 1.3.2 → 1.3.3

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/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
@@ -9,7 +9,6 @@ Bacon.summary_on_exit
9
9
 
10
10
 
11
11
  describe 'Main context' do
12
- with_eventmachine!
13
12
 
14
13
  before do
15
14
  # EM::reactor_running?.should == true
data/lib/bacon.rb CHANGED
@@ -140,14 +140,15 @@ module Bacon
140
140
  end
141
141
  end
142
142
 
143
- def describe(*args, &block)
144
- context = Bacon::Context.new(args.join(' '), &block)
145
- (parent_context = self).methods(false).each {|e|
146
- class<<context; self end.send(:define_method, e) {|*args| parent_context.send(e, *args)}
147
- }
148
- @before.each { |b| context.before(&b) }
149
- @after.each { |b| context.after(&b) }
150
- context.run
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
- EM.stop
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 run_requirement(desc, spec)
43
- raise "block required" unless block
44
-
45
- @timeout_interval = nil
46
-
47
- EM.run do
48
- Fiber.new do
49
- super
50
- done
51
- end.resume
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
@@ -1,3 +1,3 @@
1
1
  module Bacon
2
- VERSION = "1.3.2"
2
+ VERSION = "1.3.3"
3
3
  end
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.2
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-03 00:00:00.000000000 Z
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: &70215709703120 !ruby/object:Gem::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: *70215709703120
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: 414404718689880390
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: 414404718689880390
89
+ hash: 3307888883450251243
90
90
  requirements: []
91
91
  rubyforge_project:
92
92
  rubygems_version: 1.8.11