File tree Expand file tree Collapse file tree
sentry-rails/spec/active_job/shared_examples 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 "an ActiveJob backend that captures errors" do
4+ let ( :failing_job ) do
5+ job_fixture do
6+ def perform
7+ raise "boom from failing_job spec"
8+ end
9+ end
10+ end
11+
12+ it "captures an error event when a job fails" do
13+ expect do
14+ failing_job . perform_later
15+ drain
16+ end . to raise_error ( RuntimeError , /boom from failing_job spec/ )
17+
18+ expect ( sentry_events . size ) . to eq ( 1 )
19+
20+ exception = extract_sentry_exceptions ( sentry_events . last ) . first
21+ expect ( exception . value ) . to match ( /boom from failing_job spec/ )
22+ end
23+ end
Original file line number Diff line number Diff line change 1+ # frozen_string_literal: true
2+
3+ RSpec . shared_examples "an ActiveJob backend that respects retry semantics" do
4+ let ( :retryable_job ) do
5+ job_fixture do
6+ retry_on StandardError , attempts : 3 , wait : 0
7+
8+ def perform
9+ raise "boom from retryable_job spec"
10+ end
11+ end
12+ end
13+
14+ it "captures one error event after retries are exhausted" do
15+ expect do
16+ retryable_job . perform_later
17+ 3 . times { drain }
18+ end . to raise_error ( RuntimeError , /boom from retryable_job spec/ )
19+
20+ expect ( sentry_events . size ) . to eq ( 1 )
21+
22+ exception = extract_sentry_exceptions ( sentry_events . last ) . first
23+ expect ( exception . value ) . to match ( /boom from retryable_job spec/ )
24+ end
25+ end
Original file line number Diff line number Diff line change 11# frozen_string_literal: true
22
33RSpec . shared_examples "a Sentry-instrumented ActiveJob backend" do
4- let ( :failing_job ) do
5- job_fixture do
6- def perform
7- raise "boom from failing_job spec"
8- end
9- end
10- end
11-
12- it "captures an error event when a job fails" do
13- expect do
14- failing_job . perform_later
15- drain
16- end . to raise_error ( RuntimeError , /boom from failing_job spec/ )
17-
18- event = last_sentry_event
19- expect ( event ) . not_to be_nil
20-
21- exception = extract_sentry_exceptions ( event ) . first
22- expect ( exception . value ) . to match ( /boom from failing_job spec/ )
23- end
4+ it_behaves_like "an ActiveJob backend that captures errors"
5+ it_behaves_like "an ActiveJob backend that respects retry semantics"
246end
You can’t perform that action at this time.
0 commit comments