Sha256: cc4f0c9bba9fe28c1be9220ffa0a34ef3f28ad81c27c995451d330277fadcc64

Contents?: true

Size: 1.02 KB

Versions: 3

Compression:

Stored size: 1.02 KB

Contents

require 'spec_helper'

class LoggedDummy
  extend ResqueMods::LoggedJob 

  class << self 
    def perform(a, b, c)
    end 
  end 
end 

class DummyExcepion < RuntimeError
end 


describe ResqueMods::LoggedJob do 
  def do_job 
    Resque::Job.new(:jobs, {'class' => "LoggedDummy", 'args' => [1, 2, 3]}).perform
  end 

  def last_logged
    Librato.log_reporter.log.rewind
    Librato.log_reporter.log.readlines[-1].to_s.chomp
  end

  before do
    Librato.log_reporter.log = StringIO.new 
  end

  it "should call the nested perform method" do 
    LoggedDummy.should_receive(:perform).with(1, 2, 3) 
    do_job
  end 

  it "should measure the run time with librato-logreporter" do
    do_job
    last_logged.should =~ /resque_mods\.logged_job\.LoggedDummy\.run_time=[-+]?([0-9]*\.[0-9]+|[0-9]+)/
  end
  
  context "when an error occurs" do 
    it "should not swallow the error" do 
      LoggedDummy.stub(:perform).and_raise(DummyExcepion.new)
      lambda {
        do_job
      }.should raise_error(DummyExcepion)
    end 
  end 
end 

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
resque-mods-1.0.4 spec/resque-mods/logged_job_spec.rb
resque-mods-1.0.3 spec/resque-mods/logged_job_spec.rb
resque-mods-1.0.2 spec/resque-mods/logged_job_spec.rb