/
spec_helper.rb
90 lines (76 loc) · 2.08 KB
/
spec_helper.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
79
80
81
82
83
84
85
86
87
88
89
90
require 'pry'
require 'simplecov'
SimpleCov.start do
project_name "sentry-raven"
root File.join(__FILE__, "../../../")
coverage_dir File.join(__FILE__, "../../coverage")
end
if ENV["CI"] && ENV["CODECOV"] == "1"
require 'codecov'
SimpleCov.formatter = SimpleCov::Formatter::Codecov
end
require 'sentry_raven_without_integrations'
Raven.configure do |config|
config.dsn = "dummy://12345:67890@sentry.localdomain/sentry/42"
config.encoding = "json"
config.silence_ready = true
config.logger = Logger.new(nil)
end
if ENV["RAILS_VERSION"] && (ENV["RAILS_VERSION"].to_i == 0)
RSpec.configure do |config|
config.filter_run_excluding :rails => true
end
else
require File.dirname(__FILE__) + "/support/test_rails_app/app.rb"
require "rspec/rails"
end
RSpec.configure do |config|
config.mock_with(:rspec) { |mocks| mocks.verify_partial_doubles = true }
config.raise_errors_for_deprecations!
config.disable_monkey_patching!
Kernel.srand config.seed
end
RSpec.shared_examples "Raven default capture behavior" do
it "captures exceptions" do
expect { block }.to raise_error(captured_class)
expect(Raven.client.transport.events.size).to eq(1)
event = JSON.parse!(Raven.client.transport.events.first[1])
expect(event["exception"]["values"][0]["type"]).to eq(captured_class.name)
expect(event["exception"]["values"][0]["value"]).to eq(captured_message)
end
end
def build_exception
1 / 0
rescue ZeroDivisionError => e
e
end
def build_exception_with_cause(cause = "exception a")
begin
raise cause
rescue
raise "exception b"
end
rescue RuntimeError => e
e
end
def build_exception_with_two_causes
begin
begin
raise "exception a"
rescue
raise "exception b"
end
rescue
raise "exception c"
end
rescue RuntimeError => e
e
end
def build_exception_with_recursive_cause
backtrace = []
exception = double("Exception")
allow(exception).to receive(:cause).and_return(exception)
allow(exception).to receive(:message).and_return("example")
allow(exception).to receive(:backtrace).and_return(backtrace)
exception
end