This repository has been archived by the owner on Oct 17, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add spec helper and resque integration
- Loading branch information
Showing
4 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |