mloughran / job_queue

JobQueue means you don't have to worry about your queue no more!

This URL has Read+Write access

job_queue / spec / beanstalk_adapter_spec.rb
100644 61 lines (47 sloc) 1.456 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
require File.dirname(__FILE__) + '/spec_helper'
 
describe JobQueue::BeanstalkAdapter do
  before :all do
    JobQueue.adapter = JobQueue::BeanstalkAdapter.new
  end
 
  describe '#new' do
    it "should default to localhost:11300" do
      Beanstalk::Pool.should_receive(:new).with(['localhost:11300'])
      JobQueue::BeanstalkAdapter.new
    end
 
    it "should use options provided" do
      Beanstalk::Pool.should_receive(:new).with(['12.34.56.78:12345'])
      JobQueue::BeanstalkAdapter.new(:host => '12.34.56.78', :port => 12345)
    end
  end
 
  it "should write onto queue and fetch stuff back off" do
    JobQueue.put("hello")
    
    JobQueue.subscribe do |job|
      @job = job
      throw :stop
    end
    
    @job.should == "hello"
  end
  
  it "should output message if error raised in job" do
    JobQueue.put("hello")
    
    JobQueue.logger.should_receive(:error).with(/Job failed\w*/)
    
    index = 0
    JobQueue.subscribe do |job|
      index +=1
      raise 'foo' if index == 1
      throw :stop
    end
  end
  
  it "should use error_report block if supplied" do
    JobQueue.put("hello")
    
    error_report = Proc.new do |job, e|
      JobQueue.logger.error "Yikes that broke matey!"
    end
    
    JobQueue.logger.should_receive(:error).with("Yikes that broke matey!")
    
    index = 0
    JobQueue.subscribe(error_report) do |job|
      index +=1
      raise 'foo' if index == 1
      throw :stop
    end
  end
end