Class: Sidekiq::Testing

Inherits:
Object
  • Object
show all
Defined in:
lib/sidekiq/testing.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.__test_modeObject

Returns the value of attribute __test_mode.



9
10
11
# File 'lib/sidekiq/testing.rb', line 9

def __test_mode
  @__test_mode
end

Class Method Details

.__set_test_mode(mode) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/sidekiq/testing.rb', line 11

def __set_test_mode(mode)
  if block_given?
    current_mode = __test_mode
    begin
      self.__test_mode = mode
      yield
    ensure
      self.__test_mode = current_mode
    end
  else
    self.__test_mode = mode
  end
end

.constantize(str) ⇒ Object



59
60
61
62
63
64
65
66
# File 'lib/sidekiq/testing.rb', line 59

def constantize(str)
  names = str.split("::")
  names.shift if names.empty? || names.first.empty?

  names.inject(Object) do |constant, name|
    constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
  end
end

.disable!(&block) ⇒ Object



25
26
27
# File 'lib/sidekiq/testing.rb', line 25

def disable!(&block)
  __set_test_mode(:disable, &block)
end

.disabled?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/sidekiq/testing.rb', line 41

def disabled?
  __test_mode == :disable
end

.enabled?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/sidekiq/testing.rb', line 37

def enabled?
  __test_mode != :disable
end

.fake!(&block) ⇒ Object



29
30
31
# File 'lib/sidekiq/testing.rb', line 29

def fake!(&block)
  __set_test_mode(:fake, &block)
end

.fake?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/sidekiq/testing.rb', line 45

def fake?
  __test_mode == :fake
end

.inline!(&block) ⇒ Object



33
34
35
# File 'lib/sidekiq/testing.rb', line 33

def inline!(&block)
  __set_test_mode(:inline, &block)
end

.inline?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/sidekiq/testing.rb', line 49

def inline?
  __test_mode == :inline
end

.server_middleware {|@server_chain| ... } ⇒ Object

Yields:

  • (@server_chain)


53
54
55
56
57
# File 'lib/sidekiq/testing.rb', line 53

def server_middleware
  @server_chain ||= Middleware::Chain.new
  yield @server_chain if block_given?
  @server_chain
end