Skip to content

Instantly share code, notes, and snippets.

@queso
Created October 29, 2008 13:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save queso/20693 to your computer and use it in GitHub Desktop.
Save queso/20693 to your computer and use it in GitHub Desktop.
# Specs
describe "process" do
before(:each) do
@starling = mock(Starling)
Starling.should_receive(:new).and_return(@starling)
@queue = Tweetbot::Queue.new
end
it "should run the actual job" do
job = {:type => "Retweet", :id => 1}
@queue.stub!(:fetch_job).and_return(job)
@queue.should_receive(:run_job).with(job)
Retweet.should_receive(:new)
@queue.process
end
end
# Actual code
module Tweetbot
class Queue
attr_accessor :starling
def initialize(server = '127.0.0.1:22122')
@starling = Starling.new(server)
end
def process
if job = fetch_job
run_job(job)
else
sleep 2
end
end
protected
def fetch_job
@starling.get('jobs')
end
def run_job(job)
job[:type] = "Tweetbot::#{job[:type]}"
actual_job = job[:type].constantize.send(:new, job[:id])
actual_job.run
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment