em-ventually 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +20 -8
- data/Rakefile +12 -0
- data/em-ventually.gemspec +1 -0
- data/lib/em-ventually.rb +1 -0
- data/lib/em-ventually/eventually.rb +3 -2
- data/lib/em-ventually/eventually/minitest.rb +3 -0
- data/lib/em-ventually/eventually/testunit.rb +3 -0
- data/lib/em-ventually/pool.rb +2 -0
- data/lib/em-ventually/version.rb +1 -1
- metadata +19 -3
data/README.md
CHANGED
@@ -7,7 +7,7 @@ Your tests will eventually pass. You're not sure when, but you know it'll be qui
|
|
7
7
|
Take this trivial example. (It's in Minitest, but you can use whatever test suite you'd like*)
|
8
8
|
|
9
9
|
~~~~~ {ruby}
|
10
|
-
def
|
10
|
+
def test_em_simple1
|
11
11
|
val = nil
|
12
12
|
EM.add_timer(0.5) { val = 'test' }
|
13
13
|
end
|
@@ -22,7 +22,7 @@ So, you want to test that val is 'test', and as well, you want EM to start on th
|
|
22
22
|
Taking the example above you can enqueue a test.
|
23
23
|
|
24
24
|
~~~~~ {ruby}
|
25
|
-
def
|
25
|
+
def test_em_simple2
|
26
26
|
val = nil
|
27
27
|
EM.add_timer(0.5) { val = 'test' }
|
28
28
|
eventually('test') { val }
|
@@ -32,7 +32,7 @@ Taking the example above you can enqueue a test.
|
|
32
32
|
This will poll your block every 0.1 seconds to see if the condition is true. After one second, if it's still not true, it will fail. You can mess with both values by passing in `:every` and `:total`. For example:
|
33
33
|
|
34
34
|
~~~~~ {ruby}
|
35
|
-
def
|
35
|
+
def test_em_simple3
|
36
36
|
val = nil
|
37
37
|
EM.add_timer(0.5) { val = 'test' }
|
38
38
|
eventually('test', :every => 0.2, :total => 10) { val } # check every 0.2 seconds
|
@@ -43,7 +43,7 @@ This will poll your block every 0.1 seconds to see if the condition is true. Aft
|
|
43
43
|
You can also parallelize tests if you don't want them to run serially.
|
44
44
|
|
45
45
|
~~~~~ {ruby}
|
46
|
-
def
|
46
|
+
def test_em_simple4
|
47
47
|
val1, val2 = nil, nil
|
48
48
|
EM.add_timer(0.5) { val1 = 'test1' }
|
49
49
|
EM.add_timer(0.5) { val2 = 'test2' }
|
@@ -57,10 +57,10 @@ You can also parallelize tests if you don't want them to run serially.
|
|
57
57
|
As well, simple returning doesn't always cover your test. You can pass values back for equality by doing the following.
|
58
58
|
|
59
59
|
~~~~~ {ruby}
|
60
|
-
def
|
60
|
+
def test_em_simple5
|
61
61
|
val = nil
|
62
62
|
EM.add_timer(0.5) { val = 'test1' }
|
63
|
-
eventually('test1') { |
|
63
|
+
eventually('test1') { |with| with[val] } # The secret sauce is if you called
|
64
64
|
# `eventually` with a block that takes a parameter or not.
|
65
65
|
end
|
66
66
|
~~~~~
|
@@ -74,7 +74,19 @@ There are a couple of global options you can mess with too. `EM::Ventually.every
|
|
74
74
|
If you don't pass a value to eventually, it will test that your value is true (in the ruby sense). Optionally, you can call `.test` to pass a custom tester.
|
75
75
|
|
76
76
|
~~~~~ {ruby}
|
77
|
-
def
|
78
|
-
|
77
|
+
def test_em_with_test6
|
78
|
+
count = 0
|
79
|
+
EM.add_periodic_timer(0.01) { count += 0.5 }
|
80
|
+
eventually { count }.test{ |v| v >= 3 }
|
81
|
+
end
|
82
|
+
~~~~~
|
83
|
+
|
84
|
+
of course, you're gonna be writing so many of these we've aliased it to make your tests stylish and classy.
|
85
|
+
|
86
|
+
~~~~~ {ruby}
|
87
|
+
def test_em_with_test6
|
88
|
+
count = 0
|
89
|
+
EM.add_periodic_timer(0.01) { count += 0.5 }
|
90
|
+
ly { count }.test{ |v| v >= 3 }
|
79
91
|
end
|
80
92
|
~~~~~
|
data/Rakefile
CHANGED
@@ -28,6 +28,18 @@ task :test do
|
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
+
# test README.md
|
32
|
+
require 'minitest/autorun'
|
33
|
+
require 'eventmachine'
|
34
|
+
$LOAD_PATH << 'lib'
|
35
|
+
require 'em-ventually'
|
36
|
+
class ReadmeTest < MiniTest::Unit::TestCase
|
37
|
+
include EM::Ventually
|
31
38
|
|
39
|
+
readme = File.read('./README.md')
|
40
|
+
readme.scan(/~~~~~ \{ruby\}\n(.*?)~~~~~/m).each do |block|
|
41
|
+
class_eval(block.join)
|
42
|
+
end
|
43
|
+
end
|
32
44
|
end
|
33
45
|
|
data/em-ventually.gemspec
CHANGED
data/lib/em-ventually.rb
CHANGED
@@ -11,11 +11,11 @@ module EventMachine
|
|
11
11
|
def initialize(pool, runner, caller, expectation, opts, block)
|
12
12
|
@pool, @runner, @caller, @expectation, @opts, @block = pool, runner, caller, expectation, opts, block
|
13
13
|
@count = 0
|
14
|
-
@pool.push
|
14
|
+
@pool.push(self)
|
15
15
|
@total_time = opts && opts[:total] || EventMachine::Ventually.total_default
|
16
16
|
@every_time = opts && opts[:every] || EventMachine::Ventually.every_default
|
17
17
|
@test_blk = expectation.nil? ? proc{|r| r } : proc{|r| expectation == r}
|
18
|
-
EM.add_timer(0.05) { run }
|
18
|
+
@run_timer = EM.add_timer(0.05) { run }
|
19
19
|
end
|
20
20
|
|
21
21
|
def test(&blk)
|
@@ -35,6 +35,7 @@ module EventMachine
|
|
35
35
|
end
|
36
36
|
|
37
37
|
def run
|
38
|
+
EM.cancel_timer(@run_timer)
|
38
39
|
if @pool.should_run?(self)
|
39
40
|
kill_timer
|
40
41
|
if @block.arity != 1
|
@@ -7,6 +7,8 @@ module EventMachine
|
|
7
7
|
::MiniTest::Unit::TestCase.class_eval <<-EOT, __FILE__, __LINE__ + 1
|
8
8
|
include EM::Ventually::Emify
|
9
9
|
alias_method :__original__send__, :__send__
|
10
|
+
old_warning_level = $VERBOSE
|
11
|
+
$VERBOSE = nil
|
10
12
|
def __send__(*args, &blk)
|
11
13
|
if Callsite.parse(caller.first).method == 'run'
|
12
14
|
_em { __original__send__(*args, &blk) }
|
@@ -14,6 +16,7 @@ module EventMachine
|
|
14
16
|
__original__send__(*args, &blk)
|
15
17
|
end
|
16
18
|
end
|
19
|
+
$VERBOSE = old_warning_level
|
17
20
|
EOT
|
18
21
|
end
|
19
22
|
end
|
@@ -7,6 +7,8 @@ module EventMachine
|
|
7
7
|
::Test::Unit::TestCase.class_eval <<-EOT, __FILE__, __LINE__ + 1
|
8
8
|
include EM::Ventually::Emify
|
9
9
|
alias_method :__original__send__, :__send__
|
10
|
+
old_warning_level = $VERBOSE
|
11
|
+
$VERBOSE = nil
|
10
12
|
def __send__(*args, &blk)
|
11
13
|
if Callsite.parse(caller.first).method == 'run'
|
12
14
|
_em { __original__send__(*args, &blk) }
|
@@ -14,6 +16,7 @@ module EventMachine
|
|
14
16
|
__original__send__(*args, &blk)
|
15
17
|
end
|
16
18
|
end
|
19
|
+
$VERBOSE = old_warning_level
|
17
20
|
EOT
|
18
21
|
end
|
19
22
|
end
|
data/lib/em-ventually/pool.rb
CHANGED
data/lib/em-ventually/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: em-ventually
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Josh Hull
|
@@ -108,6 +108,22 @@ dependencies:
|
|
108
108
|
version: 1.0.0
|
109
109
|
type: :development
|
110
110
|
version_requirements: *id006
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: minitest
|
113
|
+
prerelease: false
|
114
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
115
|
+
none: false
|
116
|
+
requirements:
|
117
|
+
- - ~>
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
hash: 15
|
120
|
+
segments:
|
121
|
+
- 2
|
122
|
+
- 0
|
123
|
+
- 0
|
124
|
+
version: 2.0.0
|
125
|
+
type: :development
|
126
|
+
version_requirements: *id007
|
111
127
|
description: Eventually, your tests should pass in EventMachine.
|
112
128
|
email:
|
113
129
|
- joshbuddy@gmail.com
|