ruby - Why is this Sidekiq fake test not increasing the size of the jobs array? -
i have following test setup sidekiq test using fake testing in https://github.com/mperham/sidekiq/wiki/testing.
spec_helper.rb
require 'sidekiq/testing' sidekiq::testing.fake! # see http://rubydoc.info/gems/rspec-core/rspec/core/configuration rspec.configure |config| config.before(:suite) factorygirl.reload factorygirl.define to_create { |instance| instance.save } end databasecleaner.strategy = :transaction databasecleaner.clean_with(:truncation) airbrake.configure |c| c.project_id = env['airbrake_project_id'] c.project_key = env['airbrake_project_key'] end end config.before(:each, job: true) sidekiq::worker.clear_all #make sure jobs don't linger between tests end config.around(:each) |example| databasecleaner.cleaning example.run end end config.include factorygirl::syntax::methods end notification_spec.rb
require 'spec_helper' rspec.describe notificationworker "perform should call airbrake#notify", job: true notification_worker = notificationworker.new message = "this error message" expect { notification_worker.perform(message) }.to change(notificationworker.jobs, :size).by(1) end end notification_worker.rb
class notificationworker include sidekiq::worker sidekiq_options queue: :high def perform(message) airbrake.notify(message) end end yet, why receive following error message:
failure/error: expect { notification_worker.perform(message) }.to change(notificationworker.jobs, :size).by(1) expected #size have changed 1, changed 0 it seems if jobs array should incremented 1. going on? threading issue caused interaction between rspec , database cleaner?
because it's calling perform method directly , not sidekiq's api.
try notificationworker.perform_async(message)
Comments
Post a Comment