Skip to content

Commit

Permalink
Merge pull request airbrake#666 from airbrake/extra-tests
Browse files Browse the repository at this point in the history
spec/integration/rails: add a few extra specs for airbrake#665
  • Loading branch information
kyrylo authored Feb 8, 2017
2 parents c45bd6e + 697c430 commit 1fab6e0
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Airbrake Changelog

* Fixed version reporting for Rack applications with Rails-related dependencies
([#660](https://github.com/airbrake/airbrake/pull/660))
* Fixed unwanted exceptions for Sidekiq, DelayedJob & Resque when Airbrake is
unconfigured ([#665](https://github.com/airbrake/airbrake/pull/665))

### [v5.7.0][v5.7.0] (January 26, 2017)

Expand Down
1 change: 1 addition & 0 deletions lib/airbrake/delayed_job/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class Airbrake < ::Delayed::Plugin

::Airbrake.notify(notice)
end

raise exception
end
end
Expand Down
55 changes: 50 additions & 5 deletions spec/integration/rails/rails_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,32 @@
end

describe "Resque workers" do
it "reports exceptions occurring in Resque workers" do
with_resque { get '/resque' }
context "when Airbrake is configured" do
it "reports exceptions occurring in Resque workers" do
with_resque { get '/resque' }

wait_for_a_request_with_body(
/"message":"resque\serror".*"params":{.*
wait_for_a_request_with_body(
/"message":"resque\serror".*"params":{.*
"class":"BingoWorker","args":\["bango","bongo"\].*}/x
)
)
end
end

context "when Airbrake is not configured" do
it "doesn't report errors" do
allow(Airbrake).to receive(:build_notice).and_return(nil)
allow(Airbrake).to receive(:notify)

with_resque { get '/resque' }

wait_for(
a_request(:post, endpoint).
with(body: /"message":"resque error"/)
).not_to have_been_made

expect(Airbrake).to have_received(:build_notice)
expect(Airbrake).not_to have_received(:notify)
end
end
end

Expand All @@ -195,6 +214,32 @@
# elsewhere.
sleep 2
end

context "when Airbrake is not configured" do
it "doesn't report errors" do
allow(Airbrake).to receive(:build_notice).and_return(nil)
allow(Airbrake).to receive(:notify)

# Make sure we don't call `build_notice` more than 1 time. Rack
# integration will try to handle error 500 and we want to prevent
# that: https://github.com/airbrake/airbrake/pull/583
allow_any_instance_of(Airbrake::Rack::Middleware).to(
receive(:notify_airbrake).
and_return(nil)
)

get '/delayed_job'
sleep 2

wait_for(
a_request(:post, endpoint).
with(body: /"message":"delayed_job error"/)
).not_to have_been_made

expect(Airbrake).to have_received(:build_notice)
expect(Airbrake).not_to have_received(:notify)
end
end
end

describe "notice payload when a user is authenticated without Warden" do
Expand Down

0 comments on commit 1fab6e0

Please sign in to comment.