File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ # frozen_string_literal: true
2+
3+ RSpec . shared_examples "a Sentry-instrumented ActiveJob backend" do
4+ it "captures an error event when a job fails" do
5+ expect do
6+ Sentry ::Specs ::ActiveJob ::FailingJob . perform_later
7+ drain
8+ end . to raise_error ( Sentry ::Specs ::ActiveJob ::FailingJob ::Boom )
9+
10+ event = last_sentry_event
11+ expect ( event ) . not_to be_nil
12+
13+ exception = extract_sentry_exceptions ( event ) . first
14+ expect ( exception . type ) . to eq ( "Sentry::Specs::ActiveJob::FailingJob::Boom" )
15+ end
16+ end
Original file line number Diff line number Diff line change 1+ # frozen_string_literal: true
2+
3+ RSpec . shared_context "active_job backend harness" do |adapter :|
4+ before do
5+ make_basic_app
6+ setup_sentry_test
7+
8+ @previous_queue_adapter = ::ActiveJob ::Base . queue_adapter
9+ ::ActiveJob ::Base . queue_adapter = adapter
10+
11+ boot_adapter ( adapter )
12+ end
13+
14+ after do
15+ reset_adapter ( adapter )
16+
17+ ::ActiveJob ::Base . queue_adapter = @previous_queue_adapter
18+
19+ teardown_sentry_test
20+ end
21+
22+ def boot_adapter ( _adapter )
23+ # Per-adapter setup hook. Backends extend this when they need to load
24+ # schemas, start supervisors, or otherwise prepare the environment.
25+ end
26+
27+ def reset_adapter ( _adapter )
28+ # Per-adapter teardown hook. Backends extend this to truncate tables
29+ # or otherwise clean up state between examples.
30+ end
31+
32+ define_method ( :drain ) do
33+ case adapter
34+ when :test
35+ perform_enqueued_jobs
36+ else
37+ raise NotImplementedError , "active_job backend harness has no drain strategy for adapter: #{ adapter . inspect } "
38+ end
39+ end
40+ end
Original file line number Diff line number Diff line change 1+ # frozen_string_literal: true
2+
3+ require "active_job/railtie"
4+
5+ module Sentry
6+ module Specs
7+ module ActiveJob
8+ class FailingJob < ::ActiveJob ::Base
9+ self . logger = nil
10+
11+ class Boom < RuntimeError
12+ end
13+
14+ def perform
15+ raise Boom , "Boom!"
16+ end
17+ end
18+ end
19+ end
20+ end
Original file line number Diff line number Diff line change 2727end
2828
2929Dir [ "#{ __dir__ } /support/**/*.rb" ] . each { |file | require file }
30+ Dir [ "#{ __dir__ } /active_job/support/**/*.rb" ] . each { |file | require file }
31+ Dir [ "#{ __dir__ } /active_job/shared_examples/**/*.rb" ] . each { |file | require file }
3032
3133RAILS_VERSION = Rails . version . to_f
3234
You can’t perform that action at this time.
0 commit comments