我有一个 Resque 工作,我正在尝试使用 rspec 进行测试。这份工作看起来像:
class ImporterJob
def perform
job_key = options['test_key']
user = options['user']
end
我正在使用 Resque 状态,所以我使用 create 方法来创建作业,如下所示:
ImporterJob.create({key:'test_key',user: 2})
如果我尝试在 rspec 测试中以相同的方式创建作业,则选项似乎无法完成作业。如,当我在 之后插入 binding.pry 时user = options['user']
,选项哈希为空。
我的 rspec 测试如下所示:
describe ImporterJob do
context 'create' do
let(:import_options) {
{
'import_key' => 'test_key',
'user' => 1,
'model' => 'Test',
'another_flag' => nil
}
}
before(:all) do
Resque.redis.set('test_key',csv_file_location('data.csv'))
end
it 'validates and imports csv data' do
ImporterJob.create(import_options)
end
end
end