1
0
Fork 0
mirror of https://github.com/mperham/sidekiq.git synced 2022-11-09 13:52:34 -05:00
mperham--sidekiq/test/test_testing.rb
Ryan Schlesinger fd0232eb15 Add dynamic testing
In addition to requiring 'sidekiq/testing' and 'sidekiq/testing/inline',
a user can also call the following methods to control the test harness:

Sidekiq::Testing.fake!
Sidekiq::Testing.inline!
Sidekiq::Testing.disable!

Each of the above methods also accepts a block to execute within that
context before reverting to the state present before method invocation.

To query the current state, use the following methods:

Sidekiq::Testing.enabled?
Sidekiq::Testing.disabled?
Sidekiq::Testing.fake?
Sidekiq::Testing.inline?

Closes #1053
2013-09-23 12:07:23 -07:00

82 lines
2.1 KiB
Ruby

require '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 TestTesting < Sidekiq::Test
describe 'sidekiq testing' do
describe 'require/load sidekiq/testing.rb' do
before do
require 'sidekiq/testing.rb'
end
after do
Sidekiq::Testing.disable!
end
it 'enables fake testing' do
Sidekiq::Testing.fake!
assert_equal true, Sidekiq::Testing.enabled?
assert_equal true, Sidekiq::Testing.fake?
end
it 'enables fake testing in a block' do
Sidekiq::Testing.disable!
assert_equal true, Sidekiq::Testing.disabled?
Sidekiq::Testing.fake! do
assert_equal true, Sidekiq::Testing.enabled?
assert_equal true, Sidekiq::Testing.fake?
end
assert_equal false, Sidekiq::Testing.enabled?
assert_equal false, Sidekiq::Testing.fake?
end
it 'disables testing in a block' do
Sidekiq::Testing.fake!
Sidekiq::Testing.disable! do
assert_equal true, Sidekiq::Testing.disabled?
end
assert_equal true, Sidekiq::Testing.enabled?
end
end
describe 'require/load sidekiq/testing/inline.rb' do
before do
require 'sidekiq/testing/inline.rb'
end
after do
Sidekiq::Testing.disable!
end
it 'enables inline testing' do
Sidekiq::Testing.inline!
assert_equal true, Sidekiq::Testing.enabled?
assert_equal true, Sidekiq::Testing.inline?
end
it 'enables inline testing in a block' do
Sidekiq::Testing.disable!
assert_equal true, Sidekiq::Testing.disabled?
Sidekiq::Testing.inline! do
assert_equal true, Sidekiq::Testing.enabled?
assert_equal true, Sidekiq::Testing.inline?
end
assert_equal false, Sidekiq::Testing.enabled?
assert_equal false, Sidekiq::Testing.inline?
end
end
end
end