class Wisper::Testing

Constants

VERSION

Public Class Methods

_forget() click to toggle source

Forget the original broadcaster configuration.

This is only used in the specs of Wisper::Testing to get clean state.

@api private

# File lib/wisper/testing.rb, line 89
def self._forget
  return unless original_broadcasters?
  @enabled = false
  @original_broadcasters = nil
end
enabled?() click to toggle source

Returns true when either fake! or inline! having been invoked and restore! has not subsequently been invoked.

@return Boolean

# File lib/wisper/testing.rb, line 79
def self.enabled?
  !!@enabled
end
fake() { || ... } click to toggle source

Sets all broadcasters to FakeBroadcaster which does not broadcast any events to the subscriber, for the duration of the block

@return self

# File lib/wisper/testing.rb, line 26
def self.fake
  fake!
  yield
  restore!
  self
end
fake!() click to toggle source

Sets all broadcasters to FakeBroadcaster which does not broadcast any events to the subscriber.

@return self

# File lib/wisper/testing.rb, line 12
def self.fake!
  store_original_broadcasters
  Wisper.configuration.broadcasters.keys.each do |key, broadcaster|
    Wisper.configuration.broadcasters[key] = FakeBroadcaster.new
  end
  is_enabled
  self
end
inline() { || ... } click to toggle source

Sets all broadcasters to InlineBroadcaster which broadcasts event

to the subscriber synchronously.

@return self
# File lib/wisper/testing.rb, line 52
def self.inline
  inline!
  yield
  restore!
  self
end
inline!() click to toggle source

Sets all broadcasters to InlineBroadcaster which broadcasts event

to the subscriber synchronously.

@return self
# File lib/wisper/testing.rb, line 38
def self.inline!
  store_original_broadcasters
  Wisper.configuration.broadcasters.keys.each do |key, broadcaster|
    Wisper.configuration.broadcasters[key] = InlineBroadcaster.new
  end
  is_enabled
  self
end
restore!() click to toggle source

Restores the original broadcasters configuration

@return self

# File lib/wisper/testing.rb, line 63
def self.restore!
  if enabled?
    Wisper.configuration.broadcasters.clear
    original_broadcasters.each do |key, broadcaster|
      Wisper.configuration.broadcasters[key] = broadcaster
    end
    is_not_enabled
  end
  self
end

Private Class Methods

is_enabled() click to toggle source
# File lib/wisper/testing.rb, line 97
def self.is_enabled
  @enabled = true
end
is_not_enabled() click to toggle source
# File lib/wisper/testing.rb, line 101
def self.is_not_enabled
  @enabled = false
end
original_broadcasters() click to toggle source
# File lib/wisper/testing.rb, line 105
def self.original_broadcasters
  @original_broadcasters
end
original_broadcasters?() click to toggle source
# File lib/wisper/testing.rb, line 113
def self.original_broadcasters?
  !!original_broadcasters
end
store_original_broadcasters() click to toggle source
# File lib/wisper/testing.rb, line 109
def self.store_original_broadcasters
  @original_broadcasters = Wisper.configuration.broadcasters.to_h.dup
end