amqp-events 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY +4 -0
- data/Rakefile +1 -7
- data/VERSION +1 -1
- data/lib/amqp-events.rb +15 -2
- data/lib/amqp-events/event.rb +140 -0
- data/lib/amqp-events/event_manager.rb +19 -0
- data/lib/amqp-events/events.rb +47 -126
- data/spec/amqp-events/event_manager_spec.rb +63 -0
- data/spec/amqp-events/event_spec.rb +74 -0
- data/spec/amqp-events/events_spec.rb +89 -0
- data/spec/cs_spec.rb +2 -4
- data/spec/shared_examples.rb +282 -0
- data/spec/spec_helper.rb +40 -11
- data/tasks/spec.rake +3 -7
- metadata +37 -15
- data/spec/amqp-events_spec.rb +0 -214
- data/spec/spec.opts +0 -2
data/spec/spec_helper.rb
CHANGED
@@ -4,20 +4,49 @@ Bundler.require :test
|
|
4
4
|
|
5
5
|
require 'amqp-events'
|
6
6
|
require 'pathname'
|
7
|
+
require 'shared_examples'
|
7
8
|
|
8
9
|
BASE_PATH = Pathname.new(__FILE__).dirname + '..'
|
9
10
|
|
10
|
-
Spec::Runner.configure do |config|
|
11
|
-
# == Mock Framework
|
12
|
-
#
|
13
|
-
# RSpec uses it's own mocking framework by default. If you prefer to
|
14
|
-
# use mocha, flexmock or RR, uncomment the appropriate line:
|
15
|
-
#
|
16
|
-
# config.mock_with :mocha
|
17
|
-
# config.mock_with :flexmock
|
18
|
-
# config.mock_with :rr
|
11
|
+
#Spec::Runner.configure do |config|
|
12
|
+
# # == Mock Framework
|
13
|
+
# #
|
14
|
+
# # RSpec uses it's own mocking framework by default. If you prefer to
|
15
|
+
# # use mocha, flexmock or RR, uncomment the appropriate line:
|
16
|
+
# #
|
17
|
+
# # config.mock_with :mocha
|
18
|
+
# # config.mock_with :flexmock
|
19
|
+
# # config.mock_with :rr
|
20
|
+
#end
|
21
|
+
|
22
|
+
def subscribers_to_be_called(num, event = subject)
|
23
|
+
@counter = 0
|
24
|
+
|
25
|
+
event.subscribers.should have(num).subscribers
|
26
|
+
event.listeners.should have(num).listeners
|
27
|
+
|
28
|
+
event.fire "data" # fire Event, sending "data" to subscribers
|
29
|
+
@counter.should == num
|
19
30
|
end
|
20
31
|
|
21
|
-
|
32
|
+
def should_be_defined_event(object=subject, name)
|
33
|
+
object.should respond_to name.to_sym
|
34
|
+
object.should respond_to "#{name}=".to_sym
|
35
|
+
object.events.should include name.to_sym
|
36
|
+
object.events.should_not include name.to_s
|
37
|
+
object.class.instance_events.should include name.to_sym
|
38
|
+
object.class.instance_events.should_not include name.to_s
|
39
|
+
object.send(name.to_sym).should be_kind_of AMQP::Events::Event
|
40
|
+
end
|
41
|
+
|
42
|
+
def define_subscribers
|
43
|
+
def self.subscriber_method(*args)
|
44
|
+
args.should == ["data"]
|
45
|
+
@counter += 1
|
46
|
+
end
|
22
47
|
|
23
|
-
|
48
|
+
@subscriber_proc = proc do |*args|
|
49
|
+
args.should == ["data"]
|
50
|
+
@counter += 1
|
51
|
+
end
|
52
|
+
end
|
data/tasks/spec.rake
CHANGED
@@ -2,17 +2,13 @@ desc 'Alias to spec:spec'
|
|
2
2
|
task :spec => 'spec:spec'
|
3
3
|
|
4
4
|
namespace :spec do
|
5
|
-
require '
|
5
|
+
require 'rspec/core/rake_task'
|
6
6
|
|
7
7
|
desc "Run all specs"
|
8
|
-
|
9
|
-
t.spec_opts = ['--options', %Q{"#{BASE_PATH}/spec/spec.opts"}]
|
10
|
-
t.spec_files = FileList['spec/**/*_spec.rb']
|
11
|
-
end
|
8
|
+
RSpec::Core::RakeTask.new(:spec){|task|}
|
12
9
|
|
13
10
|
desc "Run specs with RCov"
|
14
|
-
|
15
|
-
t.spec_files = FileList['spec/**/*_spec.rb']
|
11
|
+
RSpec::Core::RakeTask.new(:rcov) do |t|
|
16
12
|
t.rcov = true
|
17
13
|
t.rcov_opts = ['--exclude', 'spec']
|
18
14
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: amqp-events
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- arvicco
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-10-
|
18
|
+
date: 2010-10-28 00:00:00 +04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -24,14 +24,14 @@ dependencies:
|
|
24
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
25
|
none: false
|
26
26
|
requirements:
|
27
|
-
- -
|
27
|
+
- - ~>
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
hash:
|
29
|
+
hash: 15
|
30
30
|
segments:
|
31
|
-
- 1
|
32
31
|
- 2
|
33
|
-
-
|
34
|
-
|
32
|
+
- 0
|
33
|
+
- 0
|
34
|
+
version: 2.0.0
|
35
35
|
type: :development
|
36
36
|
version_requirements: *id001
|
37
37
|
- !ruby/object:Gem::Dependency
|
@@ -49,9 +49,25 @@ dependencies:
|
|
49
49
|
type: :development
|
50
50
|
version_requirements: *id002
|
51
51
|
- !ruby/object:Gem::Dependency
|
52
|
-
name:
|
52
|
+
name: amqp
|
53
53
|
prerelease: false
|
54
54
|
requirement: &id003 !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ~>
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
hash: 11
|
60
|
+
segments:
|
61
|
+
- 0
|
62
|
+
- 6
|
63
|
+
- 6
|
64
|
+
version: 0.6.6
|
65
|
+
type: :runtime
|
66
|
+
version_requirements: *id003
|
67
|
+
- !ruby/object:Gem::Dependency
|
68
|
+
name: bundler
|
69
|
+
prerelease: false
|
70
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
55
71
|
none: false
|
56
72
|
requirements:
|
57
73
|
- - ">="
|
@@ -63,7 +79,7 @@ dependencies:
|
|
63
79
|
- 9
|
64
80
|
version: 1.2.9
|
65
81
|
type: :runtime
|
66
|
-
version_requirements: *
|
82
|
+
version_requirements: *id004
|
67
83
|
description: Distributed Events/RPC system using AMQP as a transport (pre-alpha)
|
68
84
|
email: arvitallian@gmail.com
|
69
85
|
executables:
|
@@ -76,12 +92,16 @@ extra_rdoc_files:
|
|
76
92
|
- README.rdoc
|
77
93
|
files:
|
78
94
|
- bin/amqp-events
|
95
|
+
- lib/amqp-events/event.rb
|
96
|
+
- lib/amqp-events/event_manager.rb
|
79
97
|
- lib/amqp-events/events.rb
|
80
98
|
- lib/amqp-events.rb
|
81
99
|
- lib/version.rb
|
82
|
-
- spec/amqp-
|
100
|
+
- spec/amqp-events/event_manager_spec.rb
|
101
|
+
- spec/amqp-events/event_spec.rb
|
102
|
+
- spec/amqp-events/events_spec.rb
|
83
103
|
- spec/cs_spec.rb
|
84
|
-
- spec/
|
104
|
+
- spec/shared_examples.rb
|
85
105
|
- spec/spec_helper.rb
|
86
106
|
- features/amqp-events.feature
|
87
107
|
- features/step_definitions/amqp-events_steps.rb
|
@@ -139,7 +159,9 @@ signing_key:
|
|
139
159
|
specification_version: 3
|
140
160
|
summary: Distributed Events/RPC system using AMQP as a transport.
|
141
161
|
test_files:
|
142
|
-
- spec/amqp-
|
162
|
+
- spec/amqp-events/event_manager_spec.rb
|
163
|
+
- spec/amqp-events/event_spec.rb
|
164
|
+
- spec/amqp-events/events_spec.rb
|
143
165
|
- spec/cs_spec.rb
|
144
|
-
- spec/
|
166
|
+
- spec/shared_examples.rb
|
145
167
|
- spec/spec_helper.rb
|
data/spec/amqp-events_spec.rb
DELETED
@@ -1,214 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
class EmptyTestClass
|
4
|
-
include AMQP::Events
|
5
|
-
end
|
6
|
-
|
7
|
-
class TestClassWithEvents
|
8
|
-
include AMQP::Events
|
9
|
-
|
10
|
-
event :Bar
|
11
|
-
event :Baz
|
12
|
-
end
|
13
|
-
|
14
|
-
shared_examples_for 'evented class' do
|
15
|
-
specify { should respond_to :instance_events }
|
16
|
-
its(:instance_events) { should be_an Array }
|
17
|
-
end
|
18
|
-
|
19
|
-
shared_examples_for 'evented object' do
|
20
|
-
specify { should respond_to :events }
|
21
|
-
its(:events) { should be_a Hash }
|
22
|
-
end
|
23
|
-
|
24
|
-
def subscribers_to_be_called(num)
|
25
|
-
@counter = 0
|
26
|
-
|
27
|
-
subject.Bar.subscribers.should have(num).subscribers
|
28
|
-
subject.Bar.listeners.should have(num).listeners
|
29
|
-
|
30
|
-
subject.Bar.fire "data" # fire Event, sending "data" to subscribers
|
31
|
-
@counter.should == num
|
32
|
-
end
|
33
|
-
|
34
|
-
|
35
|
-
module EventsTest
|
36
|
-
describe EmptyTestClass, ' that includes AMQPEvents::Events and is just instantiated' do
|
37
|
-
subject { EmptyTestClass }
|
38
|
-
|
39
|
-
it_should_behave_like 'evented class'
|
40
|
-
its(:instance_events) { should be_empty }
|
41
|
-
|
42
|
-
end
|
43
|
-
|
44
|
-
describe EmptyTestClass, ' when instantiated' do
|
45
|
-
subject { EmptyTestClass.new }
|
46
|
-
|
47
|
-
it_should_behave_like 'evented object'
|
48
|
-
its(:events) { should be_empty }
|
49
|
-
|
50
|
-
context 'creating new (class-wide) Events' do
|
51
|
-
it 'should create events on instance' do
|
52
|
-
subject.event :Blah
|
53
|
-
subject.events.should include :Blah
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
describe TestClassWithEvents, ' (predefined) that includes AMQPEvents::Events' do
|
59
|
-
subject { TestClassWithEvents }
|
60
|
-
|
61
|
-
it_should_behave_like 'evented class'
|
62
|
-
its(:instance_events) { should include :Bar }
|
63
|
-
its(:instance_events) { should include :Baz }
|
64
|
-
|
65
|
-
it 'should create new events' do
|
66
|
-
subject.event :Foo
|
67
|
-
subject.instance_events.should include :Foo
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
describe TestClassWithEvents, ' when instantiated' do
|
72
|
-
|
73
|
-
it_should_behave_like 'evented object'
|
74
|
-
its(:events) { should have_key :Bar }
|
75
|
-
its(:events) { should have_key :Baz }
|
76
|
-
|
77
|
-
context 'creating new (class-wide) Events' do
|
78
|
-
it 'should create events on instance' do
|
79
|
-
subject.event :Blah
|
80
|
-
subject.events.should include :Blah
|
81
|
-
# object effectively defines new Event for all similar instances... Should it be allowed?
|
82
|
-
subject.class.instance_events.should include :Blah
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
context "#subscribe to object's Event" do
|
87
|
-
|
88
|
-
it 'allows anyone to add block subscribers/listeners (multiple syntax)' do
|
89
|
-
subject.events[:Bar].subscribe(:bar1) { |*args| args.should == ["data"]; @counter += 1 }
|
90
|
-
subject.Bar.subscribe(:bar2) { |*args| args.should == ["data"]; @counter += 1 }
|
91
|
-
subject.Bar.listen(:bar3) { |*args| args.should == ["data"]; @counter += 1 }
|
92
|
-
|
93
|
-
subscribers_to_be_called 3
|
94
|
-
end
|
95
|
-
|
96
|
-
it 'allows anyone to add method subscribers/listeners (multiple syntax)' do
|
97
|
-
def self.subscriber_method(*args)
|
98
|
-
args.should == ["data"]
|
99
|
-
@counter += 1
|
100
|
-
end
|
101
|
-
|
102
|
-
subject.events[:Bar].subscribe(:bar1, method(:subscriber_method))
|
103
|
-
subject.Bar.subscribe(:bar2, method(:subscriber_method))
|
104
|
-
subject.Bar.listen(:bar3, method(:subscriber_method))
|
105
|
-
subject.Bar.listen(method(:subscriber_method))
|
106
|
-
subject.Bar += method(:subscriber_method)
|
107
|
-
|
108
|
-
subscribers_to_be_called 5
|
109
|
-
end
|
110
|
-
|
111
|
-
it 'allows anyone to add proc subscribers/listeners (multiple syntax)' do
|
112
|
-
subscriber_proc = proc do |*args|
|
113
|
-
args.should == ["data"]
|
114
|
-
@counter += 1
|
115
|
-
end
|
116
|
-
|
117
|
-
subject.events[:Bar].subscribe(:bar1, subscriber_proc)
|
118
|
-
subject.Bar.subscribe(:bar2, subscriber_proc)
|
119
|
-
subject.Bar.subscribe(:bar3, &subscriber_proc)
|
120
|
-
subject.Bar.subscribe subscriber_proc
|
121
|
-
subject.Bar.subscribe &subscriber_proc
|
122
|
-
subject.Bar.listen subscriber_proc
|
123
|
-
subject.Bar += subscriber_proc
|
124
|
-
|
125
|
-
subscribers_to_be_called 7
|
126
|
-
end
|
127
|
-
|
128
|
-
it "allows you to mix subscriber types for one Event" do
|
129
|
-
def self.subscriber_method(*args)
|
130
|
-
args.should == ["data"]
|
131
|
-
@counter += 1
|
132
|
-
end
|
133
|
-
|
134
|
-
subscriber_proc = proc do |*args|
|
135
|
-
args.should == ["data"]
|
136
|
-
@counter += 1
|
137
|
-
end
|
138
|
-
|
139
|
-
subject.Bar.subscribe { |*args| args.should == ["data"]; @counter += 1 }
|
140
|
-
subject.Bar += method :subscriber_method
|
141
|
-
subject.Bar += subscriber_proc
|
142
|
-
|
143
|
-
subscribers_to_be_called 3
|
144
|
-
end
|
145
|
-
|
146
|
-
it "raises exception if the given handler is not callable" do
|
147
|
-
|
148
|
-
[:subscriber_symbol, 1, [1, 2, 3], {me: 2}].each do |args|
|
149
|
-
expect { subject.Bar.subscribe(args) }.
|
150
|
-
to raise_error /Handler .* does not respond to #call/
|
151
|
-
expect { subject.Bar.subscribe(:good_name, args) }.
|
152
|
-
to raise_error /Handler .* does not respond to #call/
|
153
|
-
subscribers_to_be_called 0
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
|
-
it "raises exception when adding handler with duplicate name" do
|
158
|
-
subscriber_proc = proc do |*args|
|
159
|
-
args.should == ["data"]
|
160
|
-
@counter += 1
|
161
|
-
end
|
162
|
-
|
163
|
-
subject.Bar.listen(:bar1) { |*args| args.should == ["data"]; @counter += 1 }
|
164
|
-
|
165
|
-
expect { subject.Bar.listen(:bar1) { |*args| args.should == ["data"]; @counter += 1 } }.
|
166
|
-
to raise_error /Handler name bar1 already in use/
|
167
|
-
expect { subject.Bar.listen(:bar1, subscriber_proc) }.
|
168
|
-
to raise_error /Handler name bar1 already in use/
|
169
|
-
subscribers_to_be_called 1
|
170
|
-
end
|
171
|
-
end #subscribe
|
172
|
-
|
173
|
-
context "#unsubscribe from object's Event" do
|
174
|
-
it "allows you to unsubscribe from Events by name" do
|
175
|
-
def self.subscriber_method(*args)
|
176
|
-
args.should == ["data"]
|
177
|
-
@counter += 1
|
178
|
-
end
|
179
|
-
|
180
|
-
subscriber_proc = proc do |*args|
|
181
|
-
args.should == ["data"]
|
182
|
-
@counter += 1
|
183
|
-
end
|
184
|
-
|
185
|
-
subject.Bar.subscribe(:bar1) { |*args| args.should == ["data"]; @counter += 1 }
|
186
|
-
subject.Bar.subscribe(:bar2, method(:subscriber_method))
|
187
|
-
subject.Bar.subscribe(:bar3, subscriber_proc)
|
188
|
-
|
189
|
-
subject.Bar.unsubscribe(:bar1)
|
190
|
-
subject.Bar.unsubscribe(:bar2)
|
191
|
-
subject.Bar.unsubscribe(:bar3)
|
192
|
-
|
193
|
-
subscribers_to_be_called 0
|
194
|
-
end
|
195
|
-
|
196
|
-
it "raises exception if the name is unknown or wrong" do
|
197
|
-
subscriber_proc = proc do |*args|
|
198
|
-
args.should == ["data"]
|
199
|
-
@counter += 1
|
200
|
-
end
|
201
|
-
|
202
|
-
subject.Bar.subscribe(subscriber_proc)
|
203
|
-
|
204
|
-
expect { subject.Bar.unsubscribe(subscriber_proc) }.
|
205
|
-
to raise_error /Unable to unsubscribe handler/
|
206
|
-
expect { subject.Bar.unsubscribe('I-dont-know') }.
|
207
|
-
to raise_error /Unable to unsubscribe handler I-dont-know/
|
208
|
-
|
209
|
-
subscribers_to_be_called 1
|
210
|
-
end
|
211
|
-
end #unsubscribe
|
212
|
-
end # TestClassWithEvents, ' when instantiated'
|
213
|
-
end # module EventsTest
|
214
|
-
|
data/spec/spec.opts
DELETED