Skip to content

Commit 6ca13f1

Browse files
solnicclaude
andcommitted
test: Add active_job spec harness scaffolding
Introduce sentry-rails/spec/active_job/ with the adapter-agnostic harness, FailingJob fixture, and composing shared example. No backend wiring yet — that lands in a follow-up. Refs #2933. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 8635dbc commit 6ca13f1

4 files changed

Lines changed: 78 additions & 0 deletions

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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

sentry-rails/spec/spec_helper.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
end
2828

2929
Dir["#{__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

3133
RAILS_VERSION = Rails.version.to_f
3234

0 commit comments

Comments
 (0)