Class: Wisper::Testing
- Inherits:
-
Object
- Object
- Wisper::Testing
- Defined in:
- lib/wisper/testing.rb,
lib/wisper/testing/version.rb,
lib/wisper/testing/fake_broadcaster.rb,
lib/wisper/testing/inline_broadcaster.rb
Defined Under Namespace
Classes: FakeBroadcaster, InlineBroadcaster
Constant Summary collapse
- VERSION =
"2.0.0"
Class Method Summary collapse
-
._forget ⇒ Object
private
Forget the original broadcaster configuration.
-
.enabled? ⇒ Boolean
Returns true when either fake! or inline! having been invoked and restore! has not subsequently been invoked.
-
.fake ⇒ Object
Sets all broadcasters to FakeBroadcaster which does not broadcast any events to the subscriber, for the duration of the block.
-
.fake! ⇒ Object
Sets all broadcasters to FakeBroadcaster which does not broadcast any events to the subscriber.
-
.inline ⇒ Object
Sets all broadcasters to InlineBroadcaster which broadcasts event to the subscriber synchronously.
-
.inline! ⇒ Object
Sets all broadcasters to InlineBroadcaster which broadcasts event to the subscriber synchronously.
-
.restore! ⇒ Object
Restores the original broadcasters configuration.
Class Method Details
._forget ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Forget the original broadcaster configuration.
This is only used in the specs of Wisper::Testing to get clean state.
107 108 109 110 111 |
# File 'lib/wisper/testing.rb', line 107 def self._forget return unless original_broadcasters? @enabled = false @original_broadcasters = nil end |
.enabled? ⇒ Boolean
Returns true when either fake! or inline! having been invoked and restore! has not subsequently been invoked.
97 98 99 |
# File 'lib/wisper/testing.rb', line 97 def self.enabled? !!@enabled end |
.fake ⇒ Object
Sets all broadcasters to FakeBroadcaster which does not broadcast any events to the subscriber, for the duration of the block
33 34 35 36 37 38 |
# File 'lib/wisper/testing.rb', line 33 def self.fake fake! yield restore! self end |
.fake! ⇒ Object
Sets all broadcasters to FakeBroadcaster which does not broadcast any events to the subscriber.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# 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 store_global_broadcasters Wisper::GlobalListeners.registrations.each do |registration| registration.instance_variable_set("@broadcaster", FakeBroadcaster.new) end is_enabled self end |
.inline ⇒ Object
Sets all broadcasters to InlineBroadcaster which broadcasts event
to the subscriber synchronously.
@return self
65 66 67 68 69 70 |
# File 'lib/wisper/testing.rb', line 65 def self.inline inline! yield restore! self end |
.inline! ⇒ Object
Sets all broadcasters to InlineBroadcaster which broadcasts event
to the subscriber synchronously.
@return self
45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/wisper/testing.rb', line 45 def self.inline! store_original_broadcasters Wisper.configuration.broadcasters.keys.each do |key, broadcaster| Wisper.configuration.broadcasters[key] = InlineBroadcaster.new end store_global_broadcasters Wisper::GlobalListeners.registrations.each do |registration| registration.instance_variable_set("@broadcaster", InlineBroadcaster.new) end is_enabled self end |
.restore! ⇒ Object
Restores the original broadcasters configuration
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/wisper/testing.rb', line 76 def self.restore! if enabled? Wisper.configuration.broadcasters.clear original_broadcasters.each do |key, broadcaster| Wisper.configuration.broadcasters[key] = broadcaster end Wisper::GlobalListeners.registrations.each do |registration| registration.instance_variable_set("@broadcaster", global_broadcaster_for(registration)) end is_not_enabled end self end |