schmurfy-bacon 1.6.3 → 1.6.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 40352ac430d0653d081ffb4b2867ab1844fc5af3
4
- data.tar.gz: 7e9be3f09fe57cea202f7dca7b617f76d9abe56f
3
+ metadata.gz: dcb5050ddc789d1701bcaa4cc59876c6682bf543
4
+ data.tar.gz: a7c957e1d0f290bc56bd3052bcd7608c16e4291e
5
5
  SHA512:
6
- metadata.gz: ff30a132f89a89082f34990100548e4f504501964faebad93536c12f962558036555a16efc3e64bc6cf2d6e933618f5369ba4fdc794d4471fa0841d12ae18f26
7
- data.tar.gz: f2dfa88bcaafeace9022a53df14c2c2f9bd6ae66800ba995538b107f5694d7c61866940a584cc8f002db71040598cccd7fbb9139c3f76f9236f0e184244352d5
6
+ metadata.gz: b4bdf591f249b011a10f30723628eea564097e48a82c65cd6a4e48c0c105c725a32c825819530880d8a7c65ca69d2b2a3c7dc7898f09879311688c751051deea
7
+ data.tar.gz: cafad2ea51723e3e961257df8f772d734acbe2ce61235f6fba011f49d8af303fdb023f645f5e7cbab8a7cc2250846668d484a210aef6894db8a8f1af5bbe3148
data/Gemfile CHANGED
@@ -4,4 +4,5 @@ gemspec
4
4
 
5
5
  group(:test) do
6
6
  gem 'rake'
7
+ gem 'async'
7
8
  end
@@ -0,0 +1,63 @@
1
+ require 'rubygems'
2
+
3
+ $LOAD_PATH.unshift << File.expand_path('../../lib/', __FILE__)
4
+
5
+ require 'bacon'
6
+ require 'bacon/ext/async'
7
+
8
+ Bacon.summary_on_exit
9
+
10
+ def run_something_later(&block)
11
+ Async::Task.current.reactor.after(0.1) do
12
+ block.call("something")
13
+ end
14
+ end
15
+
16
+ describe 'AsynchronousSpec' do
17
+ before do
18
+ # Eventmachine is running, yeah !
19
+ # Async::Task.current.reactor.stopped.should == false
20
+ end
21
+
22
+ it 'ends immediately' do
23
+ # Async::Task.current.reactor.stopped.should == false
24
+ 1.should == 1
25
+ # without action EM::stop is called after our code
26
+ end
27
+
28
+ it 'requires time (simple)' do
29
+ executed = false
30
+
31
+ Async::Task.current.reactor.after(0.1) do
32
+ executed = true
33
+ end
34
+
35
+ wait(0.2)
36
+ executed.should == true
37
+ end
38
+
39
+
40
+ it 'requires time (less simple)' do
41
+ v = 1
42
+ Async::Task.current.reactor.after(0.1){ v = 2 }
43
+
44
+ # wait 0.2s and then execute the passed block
45
+ wait(0.2)
46
+ v.should == 2
47
+ end
48
+
49
+ # if done is called the test ends early
50
+ # but the block passed to wait is till called
51
+ should 'end early' do
52
+ v = 1
53
+ Async::Task.current.reactor.after(0.2) do
54
+ v+= 1
55
+ done
56
+ end
57
+
58
+ Async::Task.current.reactor.after(0.3){ v = 3 }
59
+ wait(1)
60
+ v.should == 2
61
+ end
62
+
63
+ end
@@ -0,0 +1,78 @@
1
+ require 'async'
2
+
3
+
4
+
5
+ module Bacon
6
+ module AsyncSpec
7
+ class <<self
8
+ attr_accessor :top_task
9
+ end
10
+
11
+ def wakeup
12
+ if @waiting_task
13
+ t = @waiting_task
14
+
15
+ @waiting_task.reactor.after(0) do
16
+ t.fiber.resume()
17
+ end
18
+
19
+ @waiting_task = nil
20
+ end
21
+ end
22
+
23
+ def cancel_timer()
24
+ if @timeout_timer
25
+ @timeout_timer.cancel()
26
+ @timeout_timer = nil
27
+ end
28
+ end
29
+
30
+ def wait(timeout = 0.1)
31
+ cancel_timer()
32
+
33
+ @waiting_task = Async::Task.current
34
+ @timeout_timer = @waiting_task.reactor.after(timeout) do
35
+ wakeup()
36
+ end
37
+
38
+ Async::Task.yield()
39
+ # Fiber.yield()
40
+
41
+ ensure
42
+ cancel_timer()
43
+ @waiting_task = nil
44
+ end
45
+
46
+
47
+ def done
48
+ wakeup()
49
+ end
50
+
51
+ # def run_requirement(title, *args)
52
+ # p [:RUN_START, title]
53
+ # super(title, *args)
54
+ # p [:RUN_END]
55
+ # end
56
+
57
+ def run(*)
58
+ if AsyncSpec.top_task && (AsyncSpec.top_task == Async::Task.current?)
59
+ super
60
+ else
61
+ Async::Reactor.run do |task|
62
+ task.async do |reactor|
63
+ AsyncSpec.top_task = Async::Task.current?
64
+ begin
65
+ super
66
+ reactor.stop()
67
+ ensure
68
+ AsyncSpec.top_task = nil
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
74
+
75
+ end
76
+
77
+ Context.send(:include, AsyncSpec)
78
+ end
@@ -1,3 +1,3 @@
1
1
  module Bacon
2
- VERSION = "1.6.3"
2
+ VERSION = "1.6.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: schmurfy-bacon
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.3
4
+ version: 1.6.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Neukirchen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-05 00:00:00.000000000 Z
11
+ date: 2018-02-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: term-ansicolor
@@ -56,6 +56,7 @@ files:
56
56
  - Rakefile
57
57
  - bacon.gemspec
58
58
  - bin/bacon
59
+ - examples/async_spec.rb
59
60
  - examples/em_spec.rb
60
61
  - examples/focus_spec.rb
61
62
  - examples/http_spec.rb
@@ -65,6 +66,7 @@ files:
65
66
  - lib/autotest/bacon_rspec.rb
66
67
  - lib/autotest/discover.rb
67
68
  - lib/bacon.rb
69
+ - lib/bacon/ext/async.rb
68
70
  - lib/bacon/ext/em.rb
69
71
  - lib/bacon/ext/http.rb
70
72
  - lib/bacon/ext/mocha.rb
@@ -98,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
98
100
  version: '0'
99
101
  requirements: []
100
102
  rubyforge_project:
101
- rubygems_version: 2.5.1
103
+ rubygems_version: 2.6.8
102
104
  signing_key:
103
105
  specification_version: 4
104
106
  summary: a small RSpec clone