forked from sidekiq/sidekiq
/
test_testing_inline.rb
93 lines (76 loc) · 2.25 KB
/
test_testing_inline.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
require_relative 'helper'
require 'sidekiq'
require 'sidekiq/worker'
require 'active_record'
require 'action_mailer'
require 'sidekiq/rails'
require 'sidekiq/extensions/action_mailer'
require 'sidekiq/extensions/active_record'
Sidekiq.hook_rails!
class TestInline < Sidekiq::Test
describe 'sidekiq inline testing' do
class InlineError < RuntimeError; end
class ParameterIsNotString < RuntimeError; end
class InlineWorker
include Sidekiq::Worker
def perform(pass)
raise ArgumentError, "no jid" unless jid
raise InlineError unless pass
end
end
class InlineWorkerWithTimeParam
include Sidekiq::Worker
def perform(time)
raise ParameterIsNotString unless time.is_a?(String) || time.is_a?(Numeric)
end
end
class InlineFooMailer < ActionMailer::Base
def bar(str)
raise InlineError
end
end
class InlineFooModel < ActiveRecord::Base
def self.bar(str)
raise InlineError
end
end
before do
require 'sidekiq/testing/inline.rb'
Sidekiq::Testing.inline!
end
after do
Sidekiq::Testing.disable!
end
it 'stubs the async call when in testing mode' do
assert InlineWorker.perform_async(true)
assert_raises InlineError do
InlineWorker.perform_async(false)
end
end
it 'stubs the delay call on mailers' do
assert_raises InlineError do
InlineFooMailer.delay.bar('three')
end
end
it 'stubs the delay call on models' do
assert_raises InlineError do
InlineFooModel.delay.bar('three')
end
end
it 'stubs the enqueue call when in testing mode' do
assert Sidekiq::Client.enqueue(InlineWorker, true)
assert_raises InlineError do
Sidekiq::Client.enqueue(InlineWorker, false)
end
end
it 'stubs the push_bulk call when in testing mode' do
assert Sidekiq::Client.push_bulk({'class' => InlineWorker, 'args' => [[true], [true]]})
assert_raises InlineError do
Sidekiq::Client.push_bulk({'class' => InlineWorker, 'args' => [[true], [false]]})
end
end
it 'should relay parameters through json' do
assert Sidekiq::Client.enqueue(InlineWorkerWithTimeParam, Time.now)
end
end
end