Skip to content

Commit

Permalink
Tests for Sidekiq handler
Browse files Browse the repository at this point in the history
This covers the core functionality of the handler.

Here are ways the tests could be further improved, which I deemed not worth the effort:

1. Testing if the handler is attached properly for Rails < 3 vs. >=3. I have tested it manually for the >=3 case and it works.

2. higher level functional test in the style of how DelayedJob is tested, where actual failing jobs are queued up:
  https://github.com/rollbar/rollbar-gem/blob/master/spec/rollbar/delayed_job_spec.rb

I didn't do this because it's more difficult to do with Sidekiq, for reasons explored here:
  sidekiq/sidekiq#2128
  • Loading branch information
jjb committed Feb 3, 2015
1 parent 93fc5d8 commit c76588a
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions spec/rollbar/sidekiq_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
require 'spec_helper'

unless RUBY_VERSION == '1.8.7'
require 'sidekiq'
require 'rollbar/sidekiq'
end

describe Rollbar::Sidekiq, :reconfigure_notifier => false do
before{ skip if RUBY_VERSION == '1.8.7' }

describe "Rollbar::Sidekiq.handle_exception" do
let(:msg_or_context){["hello", "error_backtrace", "backtrace", "goodbye"]}
let(:exception){StandardError.new("oh noes")}
let(:rollbar){double}
subject do
Rollbar::Sidekiq.handle_exception(msg_or_context, exception)
end

it "constructs scope from filtered params" do
rollbar.stub(:error)
Rollbar.should_receive(:scope).with(
{ :request => { :params => ["hello", "goodbye"] } }
){rollbar}
subject
end
it "sends the passed-in error to rollbar" do
Rollbar.stub(:scope){rollbar}
rollbar.should_receive(:error).with(exception, :use_exception_level_filters => true)
subject
end
end

describe "middleware" do
let(:middleware){Rollbar::Sidekiq.new}
let(:msg){["hello"]}
let(:exception){StandardError.new("oh noes")}
subject do
middleware.call(nil, msg, nil) do
raise exception
end
end

it "sends the error to Rollbar::Sidekiq.handle_exception" do
Rollbar::Sidekiq.should_receive(:handle_exception).with(msg, exception)
subject rescue nil
end

it "re-raises the exception" do
assert_raises StandardError do
subject
end
end
end
end

0 comments on commit c76588a

Please sign in to comment.