我正在使用RSPEC进行测试,并将Sidekiq用于后台作业。
因为,rspec中没有dword ptr
的生成器,所以不确定使用什么。
https://relishapp.com/rspec/rspec-rails/docs/generators
int
10
像下面这样,我得到:workers
需要'spec_helper'
require 'spec_helper'
RSpec.describe TestWorker, type: ? do # ex. :worker :sidekiq ...
describe "TestWorker" do
it "" do
....
end
end
end
在我尝试的过程中,bundle exec rspec spec/workers/test_worker_spec.rb
https://github.com/philostler/rspec-sidekiq
有人可以提供示例模板来在Rspec中测试uninitialized constant TestWorker
。
谢谢。
答案 0 :(得分:1)
我还没有使用过rspec-sidekiq gem,但是,这是我如何检查使用sidekiq的后台作业的示例
# app/spec/workers/demo_worker_spec.rb
require 'rails_helper'
require 'sidekiq/testing'
Sidekiq::Testing.fake!
RSpec.describe DemoWorker, type: :worker do
describe "Sidekiq Worker" do
let (:demo) { FactoryGirl.create(:demo) }
it "should respond to #perform" do
expect(DemoWorker.new).to respond_to(:perform)
end
describe "Demo" do
before do
Sidekiq::Extensions.enable_delay!
Sidekiq::Worker.clear_all
end
it "should enqueue a Email and SMS job" do
assert_equal 0, Sidekiq::Extensions::DelayedMailer.jobs.size
Mailer.delay.demo_request(demo.id)
assert_equal 1, Sidekiq::Extensions::DelayedMailer.jobs.size
end
end
end
end