-
-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathbreadcrumb_buffer_spec.cr
95 lines (76 loc) · 2.44 KB
/
breadcrumb_buffer_spec.cr
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
require "../spec_helper"
private def with_breadcrumb_buffer(&)
breadcrumbs = Raven::BreadcrumbBuffer.new(10)
yield breadcrumbs
end
describe Raven::BreadcrumbBuffer do
it "records breadcrumbs w/a block" do
with_breadcrumb_buffer do |breadcrumbs|
breadcrumbs.empty?.should be_true
crumb = nil
breadcrumbs.record do |breadcrumb|
breadcrumb.message = "test"
crumb = breadcrumb
end
breadcrumbs.empty?.should be_false
breadcrumbs.members.size.should eq(1)
breadcrumbs.members.first.should eq(crumb)
end
end
it "records breadcrumbs w/o block" do
with_breadcrumb_buffer do |breadcrumbs|
crumb = Raven::Breadcrumb.new.tap(&.message=("test"))
breadcrumbs.record(crumb)
breadcrumbs.members.first.should eq(crumb)
end
end
it "records breadcrumbs w/a splat" do
with_breadcrumb_buffer do |breadcrumbs|
breadcrumbs.record(message: "test")
breadcrumbs.members.first.message.should eq("test")
end
end
it "records breadcrumbs w/a NamedTuple" do
with_breadcrumb_buffer do |breadcrumbs|
breadcrumbs.record({message: "test"})
breadcrumbs.members.first.message.should eq("test")
end
end
it "allows peeking" do
with_breadcrumb_buffer do |breadcrumbs|
breadcrumbs.peek.should be_nil
crumb = Raven::Breadcrumb.new.tap(&.message=("test"))
breadcrumbs.record(crumb)
breadcrumbs.peek.should eq(crumb)
end
end
it "is enumerable" do
with_breadcrumb_buffer do |breadcrumbs|
breadcrumbs.should be_a Enumerable(Raven::Breadcrumb)
end
end
it "evicts when buffer exceeded" do
with_breadcrumb_buffer do |breadcrumbs|
(0..30).each do |i|
crumb = Raven::Breadcrumb.new.tap(&.message=(i.to_s))
breadcrumbs.record(crumb)
end
breadcrumbs.members.first.message.should eq("21")
breadcrumbs.members.last.message.should eq("30")
end
end
it "converts to a hash" do
with_breadcrumb_buffer do |breadcrumbs|
breadcrumbs.peek.should be_nil
crumb = Raven::Breadcrumb.new.tap(&.message=("test"))
breadcrumbs.record(crumb)
breadcrumbs.to_hash["values"].should eq([crumb.to_hash])
end
end
it "clears in a threaded context" do
crumb = Raven::Breadcrumb.new.tap(&.message=("test"))
Raven::BreadcrumbBuffer.current.record(crumb)
Raven::BreadcrumbBuffer.clear!
Raven::BreadcrumbBuffer.current.empty?.should be_true
end
end