-
-
Notifications
You must be signed in to change notification settings - Fork 272
/
crash_checking.rb
78 lines (65 loc) · 1.45 KB
/
crash_checking.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
module Specs
class FakeLogger
class << self
def current
allowed_logger.first
end
attr_accessor :allowed_logger
end
def initialize(real_logger, example)
@mutex = Mutex.new
@real_logger = real_logger
@crashes = Queue.new
@details = nil
@example = example
self.class.allowed_logger = [self, example]
end
def crash(*args)
check
raise "Testing block has already ended!" if @details
@crashes << [args, caller.dup]
end
def debug(*args)
check
@real_logger.debug(*args)
end
def warn(*args)
check
@real_logger.warn(*args)
end
def error(*args)
check
@real_logger.error(*args)
end
def level
check
@real_logger.level
end
def with_backtrace(_backtrace)
check
yield self
end
def crashes
check
@mutex.synchronize do
return @details if @details
@details = []
@details << @crashes.pop until @crashes.empty?
@crashes = nil
@details
end
end
def crashes?
check
!crashes.empty?
end
private
def check
return if self.class.allowed_logger.first == self
raise "Incorrect logger used:"\
" active/allowed: \n#{clas.allowed_logger.inspect},\n"\
" actual/self: \n#{[self, @example].inspect}\n"\
" (maybe an actor from another test is still running?)"
end
end
end