/
spec_helper.rb
97 lines (80 loc) · 2.27 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
91
92
93
94
95
96
97
require "bundler/setup"
require "debug"
require "pry"
require "sentry-ruby"
require 'rspec/retry'
require 'simplecov'
SimpleCov.start do
project_name "sentry-rails"
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
# this already requires the sdk
require "support/test_rails_app/app"
# need to be required after rails is loaded from the above
require "rspec/rails"
DUMMY_DSN = 'http://12345:67890@sentry.localdomain/sentry/42'
RSpec.configure do |config|
# Enable flags like --only-failures and --next-failure
config.example_status_persistence_file_path = ".rspec_status"
# Disable RSpec exposing methods globally on `Module` and `main`
config.disable_monkey_patching!
config.expect_with :rspec do |c|
c.syntax = :expect
end
config.before :each do
Sentry::Rails::Tracing.patch_active_support_notifications
end
config.after :each do
Sentry::Rails::Tracing.unsubscribe_tracing_events
Sentry::Rails::Tracing.remove_active_support_notifications_patch
end
config.before :each do
# Make sure we reset the env in case something leaks in
ENV.delete('SENTRY_DSN')
ENV.delete('SENTRY_CURRENT_ENV')
ENV.delete('SENTRY_ENVIRONMENT')
ENV.delete('SENTRY_RELEASE')
ENV.delete('RAILS_ENV')
ENV.delete('RACK_ENV')
end
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
def reload_send_event_job
Sentry.send(:remove_const, "SendEventJob") if defined?(Sentry::SendEventJob)
expect(defined?(Sentry::SendEventJob)).to eq(nil)
load File.join(Dir.pwd, "app", "jobs", "sentry", "send_event_job.rb")
end