Skip to content

Instantly share code, notes, and snippets.

@denniskuczynski
Created March 14, 2012 22:50
Show Gist options
  • Save denniskuczynski/2040189 to your computer and use it in GitHub Desktop.
Save denniskuczynski/2040189 to your computer and use it in GitHub Desktop.
Basic Stalker RSpec Test Example
require "spec_helper"
describe Stalker, "/jobs/stalker_example.rb" do
before :all do
# Make sure beanstalkd is running
if `pgrep beanstalkd` == ""
raise "PRECONDITION NOT MET: beanstalkd not running"
end
# Turn off all log output
module Stalker
def log(msg); end
def log_error(msg); end
end
end
before :each do
@entered_error_handler = false
# Clears all job, before, and error handlers
Stalker.clear!
# Load all jobs in our jobs file
require File.dirname(__FILE__) + "/../../../lib/jobs/stalker_example"
end
it "enqueue and work (basic_job) ensuring that (second_job) is placed on the queue" do
#Redefine the error handler
Stalker.error { |e| @entered_error_handler = true }
id = "test"
Stalker.enqueue('basic_job', {:id => id})
Stalker.prep
Stalker.work_one_job
@entered_error_handler.should eq(false)
# Work (second_job)
Stalker.work_one_job
@entered_error_handler.should eq(false)
# Check that (second_job) did what it was supposed to (TODO: example doesn't do anything)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment