em-ventually 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/Gemfile +4 -0
- data/README.md +65 -0
- data/Rakefile +33 -0
- data/em-ventually.gemspec +28 -0
- data/lib/em-ventually.rb +48 -0
- data/lib/em-ventually/eventually.rb +71 -0
- data/lib/em-ventually/eventually/minitest.rb +44 -0
- data/lib/em-ventually/eventually/rspec.rb +50 -0
- data/lib/em-ventually/eventually/testunit.rb +44 -0
- data/lib/em-ventually/pool.rb +44 -0
- data/lib/em-ventually/version.rb +5 -0
- data/test/minitest-2.0/Gemfile +7 -0
- data/test/minitest-2.0/Rakefile +9 -0
- data/test/minitest-2.0/helper.rb +2 -0
- data/test/minitest-2.0/test_ventually.rb +45 -0
- data/test/rspec-2.6/Gemfile +6 -0
- data/test/rspec-2.6/Rakefile +6 -0
- data/test/rspec-2.6/helper.rb +1 -0
- data/test/rspec-2.6/ventually_spec.rb +48 -0
- data/test/test-unit/Gemfile +6 -0
- data/test/test-unit/Rakefile +11 -0
- data/test/test-unit/helper.rb +2 -0
- data/test/test-unit/test_ventually.rb +48 -0
- metadata +189 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
# EM::Ventually
|
2
|
+
|
3
|
+
Your tests will eventually pass. You're not sure when, but you know it'll be quick. This is where EM::Ventually can help you!
|
4
|
+
|
5
|
+
Take this trivial example. (It's in Minitest, but you can use whatever test suite you'd like*)
|
6
|
+
|
7
|
+
~~~~~ {ruby}
|
8
|
+
def test_em_simple
|
9
|
+
val = nil
|
10
|
+
EM.add_timer(0.5) { val = 'test' }
|
11
|
+
end
|
12
|
+
~~~~~
|
13
|
+
|
14
|
+
So, you want to test that val is 'test', and as well, you want EM to start on the beginning of your test and shutdown when it's done. The other thing you want is the ability to not let this test run forever, but to shutdown EM and consider it a failure if it doesn't complete.
|
15
|
+
|
16
|
+
**Eventually is here to help!**
|
17
|
+
|
18
|
+
Taking the example above you can enqueue a test.
|
19
|
+
|
20
|
+
~~~~~ {ruby}
|
21
|
+
def test_em_simple
|
22
|
+
val = nil
|
23
|
+
EM.add_timer(0.5) { val = 'test' }
|
24
|
+
eventually('test') { val }
|
25
|
+
end
|
26
|
+
~~~~~
|
27
|
+
|
28
|
+
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:
|
29
|
+
|
30
|
+
~~~~~ {ruby}
|
31
|
+
def test_em_simple
|
32
|
+
val = nil
|
33
|
+
EM.add_timer(0.5) { val = 'test' }
|
34
|
+
eventually('test', :every => 0.2, :total => 10) { val } # check every 0.2 seconds
|
35
|
+
# for a total of 10 seconds.
|
36
|
+
end
|
37
|
+
~~~~~
|
38
|
+
|
39
|
+
You can also parallelize tests if you don't want them to run serially.
|
40
|
+
|
41
|
+
~~~~~ {ruby}
|
42
|
+
def test_em_simple
|
43
|
+
val1, val2 = nil, nil
|
44
|
+
EM.add_timer(0.5) { val1 = 'test1' }
|
45
|
+
EM.add_timer(0.5) { val2 = 'test2' }
|
46
|
+
parallel do
|
47
|
+
eventually('test1') { val1 }
|
48
|
+
eventually('test2') { val2 }
|
49
|
+
end
|
50
|
+
end
|
51
|
+
~~~~~
|
52
|
+
|
53
|
+
As well, simple returning doesn't always cover your test. You can pass values back for equality by doing the following.
|
54
|
+
|
55
|
+
~~~~~ {ruby}
|
56
|
+
def test_em_simple
|
57
|
+
val = nil
|
58
|
+
EM.add_timer(0.5) { val = 'test1' }
|
59
|
+
eventually('test1') { |value| value.call(val1) } # The secret sauce is if you called
|
60
|
+
# `eventually` with a parameter or not.
|
61
|
+
end
|
62
|
+
~~~~~
|
63
|
+
|
64
|
+
Right now, `Test::Unit`, `RSpec` and `MiniTest` are supported. Just do `include EM::Ventually` in your test and you'll get all this for free.
|
65
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
|
3
|
+
task :default => :test
|
4
|
+
|
5
|
+
task :test do
|
6
|
+
matchers = {
|
7
|
+
'minitest-2.0' => [/6 tests, 9 assertions, 1 failures, 0 errors, 0 skips/m],
|
8
|
+
'rspec-2.6' => [/\n\.\.\.\.F\.\n/m],
|
9
|
+
'test-unit' => [/\n\.\.\.F\.\.\n/m, /test_out_of_order\(TestEMVentually\)/m]
|
10
|
+
}
|
11
|
+
|
12
|
+
matchers.each do |type, matcher|
|
13
|
+
STDOUT.sync = true
|
14
|
+
Dir.chdir("./test/#{type}") do
|
15
|
+
print "Testing #{type}#{' ' * (22 - type.size )}"
|
16
|
+
fork {
|
17
|
+
ENV['BUNDLE_GEMFILE'] = File.expand_path("./Gemfile")
|
18
|
+
out = `bundle && bundle exec rake 2>&1`
|
19
|
+
if matcher.all?{|m|out[m]}
|
20
|
+
exit
|
21
|
+
else
|
22
|
+
puts out
|
23
|
+
exit 1
|
24
|
+
end
|
25
|
+
}
|
26
|
+
_, status = Process.wait2
|
27
|
+
puts status.success? ? "PASSED" : "FAILED"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
end
|
33
|
+
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "em-ventually/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "em-ventually"
|
7
|
+
s.version = EventMachine::Ventually::VERSION
|
8
|
+
s.authors = ["Josh Hull"]
|
9
|
+
s.email = ["joshbuddy@gmail.com"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{Eventually, your tests should pass in EventMachine}
|
12
|
+
s.description = %q{Eventually, your tests should pass in EventMachine.}
|
13
|
+
|
14
|
+
s.rubyforge_project = "em-ventually"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
# dependencies
|
22
|
+
s.add_runtime_dependency 'eventmachine'
|
23
|
+
s.add_runtime_dependency 'callsite'
|
24
|
+
s.add_development_dependency 'code_stats'
|
25
|
+
s.add_development_dependency 'rake', '~> 0.8.7'
|
26
|
+
s.add_development_dependency 'phocus'
|
27
|
+
s.add_development_dependency 'bundler', '~> 1.0.0'
|
28
|
+
end
|
data/lib/em-ventually.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'set'
|
2
|
+
require 'eventmachine'
|
3
|
+
require 'callsite'
|
4
|
+
require 'em-ventually/version'
|
5
|
+
require 'em-ventually/eventually'
|
6
|
+
require 'em-ventually/pool'
|
7
|
+
|
8
|
+
module EventMachine
|
9
|
+
module Ventually
|
10
|
+
def _pool
|
11
|
+
@_pool ||= Pool.new
|
12
|
+
end
|
13
|
+
|
14
|
+
def eventually(expectation = true, opts = nil, &block)
|
15
|
+
ancestors = self.class.ancestors.map{|s| s.to_s}
|
16
|
+
cls = if ancestors.include?('MiniTest::Unit::TestCase')
|
17
|
+
Eventually::MiniTest
|
18
|
+
elsif ancestors.include?('Test::Unit::TestCase')
|
19
|
+
Eventually::TestUnit
|
20
|
+
elsif self.class.to_s[/^RSpec::Core/]
|
21
|
+
Eventually::RSpec
|
22
|
+
else
|
23
|
+
nil
|
24
|
+
end
|
25
|
+
cls.new(_pool, self, Callsite.parse(caller.first), expectation, opts, block)
|
26
|
+
end
|
27
|
+
|
28
|
+
def parallel(&blk)
|
29
|
+
_pool.in_parallel do
|
30
|
+
instance_eval(&blk)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.included(o)
|
35
|
+
ancestors = o.ancestors.map{|s| s.to_s}
|
36
|
+
cls = if ancestors.include?('MiniTest::Unit::TestCase')
|
37
|
+
Eventually::MiniTest
|
38
|
+
elsif ancestors.include?('Test::Unit::TestCase')
|
39
|
+
Eventually::TestUnit
|
40
|
+
elsif o.respond_to?(:superclass) && o.superclass.to_s == 'RSpec::Core::ExampleGroup'
|
41
|
+
Eventually::RSpec
|
42
|
+
else
|
43
|
+
raise("I know what testsuite i'm in!")
|
44
|
+
end
|
45
|
+
cls.inject
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
module EventMachine
|
2
|
+
module Ventually
|
3
|
+
class Eventually
|
4
|
+
|
5
|
+
autoload :MiniTest, 'em-ventually/eventually/minitest'
|
6
|
+
autoload :RSpec, 'em-ventually/eventually/rspec'
|
7
|
+
autoload :TestUnit, 'em-ventually/eventually/testunit'
|
8
|
+
|
9
|
+
attr_reader :expectation
|
10
|
+
|
11
|
+
def initialize(pool, runner, caller, expectation, opts, block)
|
12
|
+
@pool, @runner, @caller, @expectation, @opts, @block = pool, runner, caller, expectation, opts, block
|
13
|
+
@count = 0
|
14
|
+
@pool.push self
|
15
|
+
@total_time = opts && opts[:total] || 1
|
16
|
+
@every_time = opts && opts[:every] || 0.1
|
17
|
+
run
|
18
|
+
end
|
19
|
+
|
20
|
+
def assert_equal(got)
|
21
|
+
got == expectation
|
22
|
+
end
|
23
|
+
|
24
|
+
def formatted_message(msg)
|
25
|
+
"#{msg} (#{@caller.filename}:#{@caller.line})"
|
26
|
+
end
|
27
|
+
|
28
|
+
def kill_timer
|
29
|
+
@kill_timer ||= EM.add_timer(@total_time) { stop(formatted_message("Exceeded time, expected #{expectation.inspect}, last value was #{@last_val.inspect}")) }
|
30
|
+
end
|
31
|
+
|
32
|
+
def run
|
33
|
+
if @pool.should_run?(self)
|
34
|
+
kill_timer
|
35
|
+
if @block.arity != 1
|
36
|
+
process_equality(@last_val = @block.call)
|
37
|
+
else
|
38
|
+
@block[proc { |val|
|
39
|
+
@last_val = val
|
40
|
+
process_equality(val)
|
41
|
+
}]
|
42
|
+
end
|
43
|
+
else
|
44
|
+
EM.add_timer(@every_time) { run }
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def process_equality(val)
|
49
|
+
if assert_equal(val)
|
50
|
+
stop
|
51
|
+
else
|
52
|
+
@count += 1
|
53
|
+
EM.add_timer(@every_time) { run }
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def stop(msg = nil)
|
58
|
+
EM.cancel_timer @kill_timer
|
59
|
+
@pool.complete(self)
|
60
|
+
report(msg) if msg
|
61
|
+
if @pool.empty? && EM.reactor_running?
|
62
|
+
EM.stop
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def report(msg)
|
67
|
+
STDERR << "Msg: #{msg}\n"
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module EventMachine
|
2
|
+
module Ventually
|
3
|
+
class Eventually
|
4
|
+
class MiniTest < Eventually
|
5
|
+
def self.inject
|
6
|
+
::MiniTest::Unit::TestCase.class_eval <<-EOT, __FILE__, __LINE__ + 1
|
7
|
+
alias_method :__original__send__, :__send__
|
8
|
+
def __send__(*args, &blk)
|
9
|
+
if Callsite.parse(caller.first).method == 'run'
|
10
|
+
result = nil
|
11
|
+
EM.run do
|
12
|
+
begin
|
13
|
+
result = __original__send__(*args, &blk)
|
14
|
+
ensure
|
15
|
+
EM.stop if (!instance_variable_defined?(:@_pool) || @_pool.nil? || @_pool.empty?) && EM.reactor_running?
|
16
|
+
end
|
17
|
+
result
|
18
|
+
end
|
19
|
+
else
|
20
|
+
__original__send__(*args, &blk)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
EOT
|
24
|
+
end
|
25
|
+
|
26
|
+
def report(msg)
|
27
|
+
@runner.assert false, msg
|
28
|
+
end
|
29
|
+
|
30
|
+
def assert_equal(result)
|
31
|
+
e = expectation
|
32
|
+
if result == expectation
|
33
|
+
@runner.instance_eval do
|
34
|
+
assert_equal result, e
|
35
|
+
end
|
36
|
+
true
|
37
|
+
else
|
38
|
+
false
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module EventMachine
|
2
|
+
module Ventually
|
3
|
+
class Eventually
|
4
|
+
class RSpec < Eventually
|
5
|
+
def self.inject
|
6
|
+
::RSpec::Core::ExampleGroup.class_eval <<-EOT, __FILE__, __LINE__ + 1
|
7
|
+
alias_method :original_instance_eval, :instance_eval
|
8
|
+
def instance_eval(&block)
|
9
|
+
_em do
|
10
|
+
original_instance_eval(&block)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def _em
|
15
|
+
result = nil
|
16
|
+
if EM.reactor_running?
|
17
|
+
result = yield
|
18
|
+
else
|
19
|
+
EM.run do
|
20
|
+
begin
|
21
|
+
result = yield
|
22
|
+
ensure
|
23
|
+
EM.stop if (!instance_variable_defined?(:@_pool) || @_pool.nil? || @_pool.empty?) && EM.reactor_running?
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
result
|
28
|
+
end
|
29
|
+
EOT
|
30
|
+
end
|
31
|
+
|
32
|
+
def report(msg)
|
33
|
+
::RSpec::Expectations.fail_with(msg)
|
34
|
+
end
|
35
|
+
|
36
|
+
def assert_equal(result)
|
37
|
+
e = expectation
|
38
|
+
if result == expectation
|
39
|
+
@runner.instance_eval do
|
40
|
+
result.should == e
|
41
|
+
end
|
42
|
+
true
|
43
|
+
else
|
44
|
+
false
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module EventMachine
|
2
|
+
module Ventually
|
3
|
+
class Eventually
|
4
|
+
class TestUnit < Eventually
|
5
|
+
def self.inject
|
6
|
+
::Test::Unit::TestCase.class_eval <<-EOT, __FILE__, __LINE__ + 1
|
7
|
+
alias_method :__original__send__, :__send__
|
8
|
+
def __send__(*args, &blk)
|
9
|
+
if Callsite.parse(caller.first).method == 'run'
|
10
|
+
result = nil
|
11
|
+
EM.run do
|
12
|
+
begin
|
13
|
+
result = __original__send__(*args, &blk)
|
14
|
+
ensure
|
15
|
+
EM.stop if (!instance_variable_defined?(:@_pool) || @_pool.nil? || @_pool.empty?) && EM.reactor_running?
|
16
|
+
end
|
17
|
+
result
|
18
|
+
end
|
19
|
+
else
|
20
|
+
__original__send__(*args, &blk)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
EOT
|
24
|
+
end
|
25
|
+
|
26
|
+
def report(msg)
|
27
|
+
@runner.assert false, msg
|
28
|
+
end
|
29
|
+
|
30
|
+
def assert_equal(result)
|
31
|
+
e = expectation
|
32
|
+
if result == expectation
|
33
|
+
@runner.instance_eval do
|
34
|
+
assert_equal result, e
|
35
|
+
end
|
36
|
+
true
|
37
|
+
else
|
38
|
+
false
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module EventMachine
|
2
|
+
module Ventually
|
3
|
+
class Pool
|
4
|
+
def initialize
|
5
|
+
@store = []
|
6
|
+
end
|
7
|
+
|
8
|
+
def should_run?(eventually)
|
9
|
+
case @store.first
|
10
|
+
when Array
|
11
|
+
@store.first.include?(eventually)
|
12
|
+
else
|
13
|
+
@store.first == eventually
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def in_parallel
|
18
|
+
@store.push []
|
19
|
+
yield
|
20
|
+
end
|
21
|
+
|
22
|
+
def push(e)
|
23
|
+
if @store.last.is_a?(Array)
|
24
|
+
@store.last.push(e)
|
25
|
+
else
|
26
|
+
@store.push(e)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def complete(e)
|
31
|
+
if @store.first.is_a?(Array)
|
32
|
+
@store.first.delete(e)
|
33
|
+
@store.shift if @store.last.empty?
|
34
|
+
else
|
35
|
+
@store.delete(e)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def empty?
|
40
|
+
@store.empty?
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
class TestMounting < MiniTest::Unit::TestCase
|
2
|
+
include EM::Ventually
|
3
|
+
|
4
|
+
def test_simple
|
5
|
+
assert_equal 1, 1
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_em_simple
|
9
|
+
val = nil
|
10
|
+
EM.add_timer(0.5) { val = 'test' }
|
11
|
+
eventually('test') { val }
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_em_passing
|
15
|
+
val = nil
|
16
|
+
EM.add_timer(0.5) { val = 'test' }
|
17
|
+
eventually('test') {|m| m[val] }
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_multiple
|
21
|
+
val = nil
|
22
|
+
EM.add_timer(0.3) { val = 'test' }
|
23
|
+
EM.add_timer(0.8) { val = 'test2' }
|
24
|
+
eventually('test') {|m| m[val] }
|
25
|
+
eventually('test2') {|m| m[val] }
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_out_of_order # this should fail
|
29
|
+
val = nil
|
30
|
+
EM.add_timer(0.3) { val = 'test2' }
|
31
|
+
EM.add_timer(0.8) { val = 'test' }
|
32
|
+
eventually('test') {|m| m[val] }
|
33
|
+
eventually('test2') {|m| m[val] }
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_out_of_order_with_parallel
|
37
|
+
val = nil
|
38
|
+
EM.add_timer(0.3) { val = 'test2' }
|
39
|
+
EM.add_timer(0.8) { val = 'test' }
|
40
|
+
parallel {
|
41
|
+
eventually('test') {|m| m[val] }
|
42
|
+
eventually('test2') {|m| m[val] }
|
43
|
+
}
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'minitest/autorun'
|
@@ -0,0 +1,48 @@
|
|
1
|
+
$LOAD_PATH << "#{File.dirname(__FILE__)}/../../lib"
|
2
|
+
require 'em-ventually'
|
3
|
+
|
4
|
+
describe EM::Ventually do
|
5
|
+
include EM::Ventually
|
6
|
+
|
7
|
+
it "should allow a normal test" do
|
8
|
+
1.should == 1
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should allow a simple em test" do
|
12
|
+
val = nil
|
13
|
+
EM.add_timer(0.5) { val = 'test' }
|
14
|
+
eventually('test') { val }
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should allow an em test with value passing" do
|
18
|
+
val = nil
|
19
|
+
EM.add_timer(0.5) { val = 'test' }
|
20
|
+
eventually('test') {|m| m[val] }
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should allow multiple eventuallys" do
|
24
|
+
val = nil
|
25
|
+
EM.add_timer(0.3) { val = 'test' }
|
26
|
+
EM.add_timer(0.8) { val = 'test2' }
|
27
|
+
eventually('test') {|m| m[val] }
|
28
|
+
eventually('test2') {|m| m[val] }
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should fail when out of order" do
|
32
|
+
val = nil
|
33
|
+
EM.add_timer(0.3) { val = 'test2' }
|
34
|
+
EM.add_timer(0.8) { val = 'test' }
|
35
|
+
eventually('test') {|m| m[val] }
|
36
|
+
eventually('test2') {|m| m[val] }
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should succeed when out of order using parallel" do
|
40
|
+
val = nil
|
41
|
+
EM.add_timer(0.3) { val = 'test2' }
|
42
|
+
EM.add_timer(0.8) { val = 'test' }
|
43
|
+
parallel {
|
44
|
+
eventually('test') {|m| m[val] }
|
45
|
+
eventually('test2') {|m| m[val] }
|
46
|
+
}
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'rake/testtask'
|
2
|
+
|
3
|
+
desc "Run basic tests"
|
4
|
+
Rake::TestTask.new("test") { |t|
|
5
|
+
t.pattern = File.expand_path("#{File.dirname(__FILE__)}/test_*.rb")
|
6
|
+
t.verbose = true
|
7
|
+
t.warning = true
|
8
|
+
t.libs = [File.expand_path("#{File.dirname(__FILE__)}/../../lib")]
|
9
|
+
}
|
10
|
+
|
11
|
+
task :default => :test
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'em-ventually'
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
class TestEMVentually < Test::Unit::TestCase
|
5
|
+
include EM::Ventually
|
6
|
+
|
7
|
+
def test_simple
|
8
|
+
assert_equal 1, 1
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_em_simple
|
12
|
+
val = nil
|
13
|
+
EM.add_timer(0.5) { val = 'test' }
|
14
|
+
eventually('test') { val }
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_em_passing
|
18
|
+
val = nil
|
19
|
+
EM.add_timer(0.5) { val = 'test' }
|
20
|
+
eventually('test') {|m| m[val] }
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_multiple
|
24
|
+
val = nil
|
25
|
+
EM.add_timer(0.3) { val = 'test' }
|
26
|
+
EM.add_timer(0.8) { val = 'test2' }
|
27
|
+
eventually('test') {|m| m[val] }
|
28
|
+
eventually('test2') {|m| m[val] }
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_out_of_order # this should fail
|
32
|
+
val = nil
|
33
|
+
EM.add_timer(0.3) { val = 'test2' }
|
34
|
+
EM.add_timer(0.8) { val = 'test' }
|
35
|
+
eventually('test') {|m| m[val] }
|
36
|
+
eventually('test2') {|m| m[val] }
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_out_of_order_with_parallel
|
40
|
+
val = nil
|
41
|
+
EM.add_timer(0.3) { val = 'test2' }
|
42
|
+
EM.add_timer(0.8) { val = 'test' }
|
43
|
+
parallel {
|
44
|
+
eventually('test') {|m| m[val] }
|
45
|
+
eventually('test2') {|m| m[val] }
|
46
|
+
}
|
47
|
+
end
|
48
|
+
end
|
metadata
ADDED
@@ -0,0 +1,189 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: em-ventually
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Josh Hull
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-08-07 00:00:00 -07:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 3
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
version: "0"
|
32
|
+
requirement: *id001
|
33
|
+
name: eventmachine
|
34
|
+
type: :runtime
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
hash: 3
|
43
|
+
segments:
|
44
|
+
- 0
|
45
|
+
version: "0"
|
46
|
+
requirement: *id002
|
47
|
+
name: callsite
|
48
|
+
type: :runtime
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
hash: 3
|
57
|
+
segments:
|
58
|
+
- 0
|
59
|
+
version: "0"
|
60
|
+
requirement: *id003
|
61
|
+
name: code_stats
|
62
|
+
type: :development
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ~>
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
hash: 49
|
71
|
+
segments:
|
72
|
+
- 0
|
73
|
+
- 8
|
74
|
+
- 7
|
75
|
+
version: 0.8.7
|
76
|
+
requirement: *id004
|
77
|
+
name: rake
|
78
|
+
type: :development
|
79
|
+
- !ruby/object:Gem::Dependency
|
80
|
+
prerelease: false
|
81
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
hash: 3
|
87
|
+
segments:
|
88
|
+
- 0
|
89
|
+
version: "0"
|
90
|
+
requirement: *id005
|
91
|
+
name: phocus
|
92
|
+
type: :development
|
93
|
+
- !ruby/object:Gem::Dependency
|
94
|
+
prerelease: false
|
95
|
+
version_requirements: &id006 !ruby/object:Gem::Requirement
|
96
|
+
none: false
|
97
|
+
requirements:
|
98
|
+
- - ~>
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
hash: 23
|
101
|
+
segments:
|
102
|
+
- 1
|
103
|
+
- 0
|
104
|
+
- 0
|
105
|
+
version: 1.0.0
|
106
|
+
requirement: *id006
|
107
|
+
name: bundler
|
108
|
+
type: :development
|
109
|
+
description: Eventually, your tests should pass in EventMachine.
|
110
|
+
email:
|
111
|
+
- joshbuddy@gmail.com
|
112
|
+
executables: []
|
113
|
+
|
114
|
+
extensions: []
|
115
|
+
|
116
|
+
extra_rdoc_files: []
|
117
|
+
|
118
|
+
files:
|
119
|
+
- .gitignore
|
120
|
+
- Gemfile
|
121
|
+
- README.md
|
122
|
+
- Rakefile
|
123
|
+
- em-ventually.gemspec
|
124
|
+
- lib/em-ventually.rb
|
125
|
+
- lib/em-ventually/eventually.rb
|
126
|
+
- lib/em-ventually/eventually/minitest.rb
|
127
|
+
- lib/em-ventually/eventually/rspec.rb
|
128
|
+
- lib/em-ventually/eventually/testunit.rb
|
129
|
+
- lib/em-ventually/pool.rb
|
130
|
+
- lib/em-ventually/version.rb
|
131
|
+
- test/minitest-2.0/Gemfile
|
132
|
+
- test/minitest-2.0/Rakefile
|
133
|
+
- test/minitest-2.0/helper.rb
|
134
|
+
- test/minitest-2.0/test_ventually.rb
|
135
|
+
- test/rspec-2.6/Gemfile
|
136
|
+
- test/rspec-2.6/Rakefile
|
137
|
+
- test/rspec-2.6/helper.rb
|
138
|
+
- test/rspec-2.6/ventually_spec.rb
|
139
|
+
- test/test-unit/Gemfile
|
140
|
+
- test/test-unit/Rakefile
|
141
|
+
- test/test-unit/helper.rb
|
142
|
+
- test/test-unit/test_ventually.rb
|
143
|
+
has_rdoc: true
|
144
|
+
homepage: ""
|
145
|
+
licenses: []
|
146
|
+
|
147
|
+
post_install_message:
|
148
|
+
rdoc_options: []
|
149
|
+
|
150
|
+
require_paths:
|
151
|
+
- lib
|
152
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
153
|
+
none: false
|
154
|
+
requirements:
|
155
|
+
- - ">="
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
hash: 3
|
158
|
+
segments:
|
159
|
+
- 0
|
160
|
+
version: "0"
|
161
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
162
|
+
none: false
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
hash: 3
|
167
|
+
segments:
|
168
|
+
- 0
|
169
|
+
version: "0"
|
170
|
+
requirements: []
|
171
|
+
|
172
|
+
rubyforge_project: em-ventually
|
173
|
+
rubygems_version: 1.6.2
|
174
|
+
signing_key:
|
175
|
+
specification_version: 3
|
176
|
+
summary: Eventually, your tests should pass in EventMachine
|
177
|
+
test_files:
|
178
|
+
- test/minitest-2.0/Gemfile
|
179
|
+
- test/minitest-2.0/Rakefile
|
180
|
+
- test/minitest-2.0/helper.rb
|
181
|
+
- test/minitest-2.0/test_ventually.rb
|
182
|
+
- test/rspec-2.6/Gemfile
|
183
|
+
- test/rspec-2.6/Rakefile
|
184
|
+
- test/rspec-2.6/helper.rb
|
185
|
+
- test/rspec-2.6/ventually_spec.rb
|
186
|
+
- test/test-unit/Gemfile
|
187
|
+
- test/test-unit/Rakefile
|
188
|
+
- test/test-unit/helper.rb
|
189
|
+
- test/test-unit/test_ventually.rb
|