jmoses_event_bus 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile.lock +2 -2
- data/lib/event_bus/testing.rb +21 -0
- data/spec/lib/event_bus_spec.rb +10 -0
- data/spec/spec_helper.rb +1 -0
- metadata +2 -1
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
|
4
|
+
jmoses_event_bus (1.0.2)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
@@ -33,7 +33,7 @@ PLATFORMS
|
|
33
33
|
ruby
|
34
34
|
|
35
35
|
DEPENDENCIES
|
36
|
-
|
36
|
+
jmoses_event_bus!
|
37
37
|
json
|
38
38
|
rake (~> 10.0.1)
|
39
39
|
rspec (~> 2.12)
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class EventBus
|
2
|
+
def self.with_temporary_subscriber(pattern, listener, method_name, &block)
|
3
|
+
subscribe(pattern, listener, method_name)
|
4
|
+
temporary_subscriber = registrations.last_subscriber
|
5
|
+
|
6
|
+
yield
|
7
|
+
ensure
|
8
|
+
registrations.remove_subscriber(temporary_subscriber)
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
class Registrations
|
13
|
+
def remove_subscriber(subscriber)
|
14
|
+
listeners.delete subscriber
|
15
|
+
end
|
16
|
+
|
17
|
+
def last_subscriber
|
18
|
+
listeners.last
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/spec/lib/event_bus_spec.rb
CHANGED
@@ -7,6 +7,16 @@ describe EventBus do
|
|
7
7
|
EventBus.clear
|
8
8
|
end
|
9
9
|
|
10
|
+
describe "testing" do
|
11
|
+
it "adds then removes the handler" do
|
12
|
+
EventBus.with_temporary_subscriber(/test/, listener, :handler) do
|
13
|
+
EventBus.publish 'test'
|
14
|
+
end
|
15
|
+
listener.should have_received(:handler).with(event_name: 'test')
|
16
|
+
EventBus.send(:registrations).send(:listeners).should be_empty
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
10
20
|
describe 'publishing' do
|
11
21
|
|
12
22
|
context 'accepts a string for the event name' do
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jmoses_event_bus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -77,6 +77,7 @@ files:
|
|
77
77
|
- Rakefile
|
78
78
|
- lib/event_bus.rb
|
79
79
|
- lib/event_bus/registrations.rb
|
80
|
+
- lib/event_bus/testing.rb
|
80
81
|
- spec/lib/event_bus_spec.rb
|
81
82
|
- spec/spec_helper.rb
|
82
83
|
homepage: http://github.com/jmoses/event_bus
|