Skip to content
This repository has been archived by the owner on Oct 17, 2018. It is now read-only.

Commit

Permalink
Add spec helper and resque integration
Browse files Browse the repository at this point in the history
  • Loading branch information
luqman committed Dec 12, 2012
1 parent 85cd389 commit 43f71a1
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 0 deletions.
21 changes: 21 additions & 0 deletions lib/resque/failure/coalmine.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module Resque
module Failure
class Coalmine < Base
def self.configure(&block)
::Coalmine.configure(&block)
end

def self.count
# We can't get the total # of errors from Coalmine so we fake it
# by asking Resque how many errors it has seen.
Stat[:failed]
end

def save
::Coalmine.custom_variables[:payload_class] = payload['class']
::Coalmine.custom_variables[:payload_args] = payload['args'].inspect
::Coalmine.notify(exception)
end
end
end
end
3 changes: 3 additions & 0 deletions lib/resque_coalmine.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
require 'resque'
require 'coalmine'

require 'coalmine/version'
require 'resque/failure/coalmine'
47 changes: 47 additions & 0 deletions spec/resque/failure/coalmine_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
describe Resque::Failure::Coalmine do

describe '.configure block' do
let(:signature) { 'my_secret_signature' }
before do
Resque::Failure::Coalmine.configure do |config|
config.signature = signature
end
end
subject { ::Coalmine.config }
it "sets signature" do
expect(Coalmine.config.signature).to eql signature
end
end

describe "#count" do
let(:failed) { 0 }
before { Resque::Stat.expects(:[]).with(:failed).returns(failed) }
it 'should be zero' do
expect(Resque::Failure::Coalmine.count).to eq 0
end
end

describe "#save" do
let(:exception) { StandardError.new("ka boom") }
let(:worker) { Resque::Worker.new(:coalmine) }
let(:queue) { "coalmine" }
let(:klass) { Object }
let(:args) { 2012 }
let(:payload) { {'class' => klass, 'args' => args } }
let(:backend) { Resque::Failure::Coalmine.new(exception, worker, queue, payload) }

it "notifies coaline with exception" do
Coalmine.expects(:notify).with(exception)
backend.save
end

describe Coalmine do
subject { Coalmine.custom_variables }
it 'has custom variables set to "Object", "2012"' do
expect(subject[:payload_class]).to eq payload['class']
expect(subject[:payload_args]).to eq payload['args'].inspect
end
end
end

end
8 changes: 8 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))

require "bundler/setup"
require 'resque_coalmine'

RSpec.configure do |config|
config.mock_with :mocha
end

0 comments on commit 43f71a1

Please sign in to comment.