Question

I've this file called jobs.rb

require File.expand_path("../environment", __FILE__)

job "do.stuff" do |args|
  $value = 10
end

Then I've this spec file called jobs_spec.rb

require File.expand_path("../../spec_helper", __FILE__)

describe "some beanstalk jobs" do
  it "should work" do

    # What to do here?

    $value.should eq(10)
  end
end

How do I test the $value variable?

Was it helpful?

Solution

You have to run beanstalkd on the machine you are running the test on.


require "Stalker"

describe Stalker, "job" do
  before :all do
    # Make sure beanstalkd is running
    if `pgrep beanstalkd` == ""
      raise "PRECONDITION NOT MET: beanstalkd not running"
    end

    module Stalker
      def log(msg); end
      def log_error(msg); end
    end
  end

  before :each do
    Stalker.clear!
    $result = -1
    $handled = false
  end

  it "enqueue and work a job" do
    val = rand(999999)
    Stalker.job('my.job') { |args| $result = args['val'] }
    Stalker.enqueue('my.job', :val => val)
    Stalker.prep
    Stalker.work_one_job
    val.should == $result
  end
end

OTHER TIPS

I'd check out how the library itself runs it's test:

https://github.com/adamwiggins/stalker/blob/master/test/stalker_test.rb

Keep in mind that this is using Test::Unit, however you can apply the same techniques in Rspec.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top