我的文件名为 jobs.rb
require File.expand_path("../environment", __FILE__)
job "do.stuff" do |args|
$value = 10
end
然后我有一个名为 jobs_spec.rb
的spec文件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
如何测试$value
变量?
答案 0 :(得分:1)
我将查看库本身如何运行它的测试:
https://github.com/adamwiggins/stalker/blob/master/test/stalker_test.rb
请记住,这是使用Test :: Unit,但您可以在Rspec中应用相同的技术。
答案 1 :(得分:1)
您必须在运行测试的计算机上运行beanstalkd。
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