Class: EventMachine::Ventually::Eventually
- Inherits:
-
Object
- Object
- EventMachine::Ventually::Eventually
show all
- Defined in:
- lib/em-ventually/eventually.rb,
lib/em-ventually/eventually/rspec.rb,
lib/em-ventually/eventually/minitest.rb,
lib/em-ventually/eventually/testunit.rb
Defined Under Namespace
Classes: MiniTest, RSpec, TestUnit
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(pool, runner, caller, expectation, opts, block) ⇒ Eventually
Returns a new instance of Eventually.
11
12
13
14
15
16
17
18
19
|
# File 'lib/em-ventually/eventually.rb', line 11
def initialize(pool, runner, caller, expectation, opts, block)
@pool, @runner, @caller, @expectation, @opts, @block = pool, runner, caller, expectation, opts, block
@count = 0
@pool.push(self)
@total_time = opts && opts[:total] || EventMachine::Ventually.total_default
@every_time = opts && opts[:every] || EventMachine::Ventually.every_default
@test_blk = expectation.nil? ? proc{|r| r } : proc{|r| expectation == r}
@run_timer = EM.add_timer(0.05) { run }
end
|
Instance Attribute Details
#expectation ⇒ Object
Returns the value of attribute expectation.
9
10
11
|
# File 'lib/em-ventually/eventually.rb', line 9
def expectation
@expectation
end
|
Instance Method Details
#assert_test(got) ⇒ Object
25
26
27
|
# File 'lib/em-ventually/eventually.rb', line 25
def assert_test(got)
@test_blk[got]
end
|
29
30
31
|
# File 'lib/em-ventually/eventually.rb', line 29
def formatted_message(msg)
"#{msg} (#{@caller.filename}:#{@caller.line})"
end
|
#kill_timer ⇒ Object
33
34
35
|
# File 'lib/em-ventually/eventually.rb', line 33
def kill_timer
@kill_timer ||= EM.add_timer(@total_time) { stop(formatted_message("Exceeded time#{", expected #{expectation.inspect}" unless expectation.nil?}, last value was #{@last_val.inspect}")) }
end
|
#process_test(val) ⇒ Object
54
55
56
57
58
59
60
61
|
# File 'lib/em-ventually/eventually.rb', line 54
def process_test(val)
if assert_test(val)
stop
else
@count += 1
EM.add_timer(@every_time) { run }
end
end
|
#report(msg) ⇒ Object
72
73
74
|
# File 'lib/em-ventually/eventually.rb', line 72
def report(msg)
STDERR << "Msg: #{msg}\n"
end
|
#run ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/em-ventually/eventually.rb', line 37
def run
EM.cancel_timer(@run_timer)
if @pool.should_run?(self)
kill_timer
if @block.arity != 1
process_test(@last_val = @block.call)
else
@block[proc { |val|
@last_val = val
process_test(val)
}]
end
else
EM.add_timer(@every_time) { run }
end
end
|
#stop(msg = nil) ⇒ Object
63
64
65
66
67
68
69
70
|
# File 'lib/em-ventually/eventually.rb', line 63
def stop(msg = nil)
EM.cancel_timer @kill_timer
@pool.complete(self)
report(msg) if msg
if @pool.empty? && EM.reactor_running?
EM.stop
end
end
|
#test(&blk) ⇒ Object
21
22
23
|
# File 'lib/em-ventually/eventually.rb', line 21
def test(&blk)
@test_blk = blk
end
|