1
0
Fork 0
mirror of https://github.com/mperham/sidekiq.git synced 2022-11-09 13:52:34 -05:00
mperham--sidekiq/test/testing_inline.rb
Teo Ljungberg c72f0d2e81
Rename worker references to job (#5568)
* standardrb

* Rename all `*_worker` references to `*_job`

* Rename Worker references to Job in test suite

* Rename ApiJob to ApiAjJob to avoid collisions

* Rename remaining Worker to Job references

* Rename WorkController to JobController

Including routes

* fixup! Rename WorkController to JobController
2022-10-11 08:38:53 -07:00

61 lines
1.4 KiB
Ruby

# frozen_string_literal: true
require_relative "helper"
class InlineError < RuntimeError; end
class ParameterIsNotString < RuntimeError; end
class InlineJob
include Sidekiq::Job
def perform(pass)
raise ArgumentError, "no jid" unless jid
raise InlineError unless pass
end
end
class InlineJobWithTimeParam
include Sidekiq::Job
def perform(time)
raise ParameterIsNotString unless time.is_a?(String) || time.is_a?(Numeric)
end
end
describe "Sidekiq::Testing.inline" do
before do
require "sidekiq/testing/inline"
Sidekiq::Testing.inline!
end
after do
Sidekiq::Testing.disable!
end
it "stubs the async call when in testing mode" do
assert InlineJob.perform_async(true)
assert_raises InlineError do
InlineJob.perform_async(false)
end
end
it "stubs the enqueue call when in testing mode" do
assert Sidekiq::Client.enqueue(InlineJob, true)
assert_raises InlineError do
Sidekiq::Client.enqueue(InlineJob, false)
end
end
it "stubs the push_bulk call when in testing mode" do
assert Sidekiq::Client.push_bulk({"class" => InlineJob, "args" => [[true], [true]]})
assert_raises InlineError do
Sidekiq::Client.push_bulk({"class" => InlineJob, "args" => [[true], [false]]})
end
end
it "should relay parameters through json" do
assert Sidekiq::Client.enqueue(InlineJobWithTimeParam, Time.now.to_f)
end
end