evented-spec 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. data/HISTORY +8 -1
  2. data/README.textile +51 -9
  3. data/Rakefile +3 -4
  4. data/VERSION +1 -1
  5. data/lib/evented-spec.rb +22 -1
  6. data/lib/evented-spec/amqp_spec.rb +27 -0
  7. data/lib/evented-spec/coolio_spec.rb +26 -0
  8. data/lib/evented-spec/em_spec.rb +26 -0
  9. data/lib/evented-spec/evented_example.rb +13 -5
  10. data/lib/evented-spec/evented_example/amqp_example.rb +8 -7
  11. data/lib/evented-spec/evented_example/coolio_example.rb +4 -18
  12. data/lib/evented-spec/evented_example/em_example.rb +6 -12
  13. data/lib/evented-spec/{amqp.rb → ext/amqp.rb} +31 -2
  14. data/lib/evented-spec/ext/coolio.rb +14 -0
  15. data/lib/evented-spec/spec_helper.rb +141 -0
  16. data/lib/evented-spec/spec_helper/amqp_helpers.rb +55 -0
  17. data/lib/evented-spec/spec_helper/coolio_helpers.rb +49 -0
  18. data/lib/evented-spec/spec_helper/event_machine_helpers.rb +52 -0
  19. data/spec/em_hooks_spec.rb +3 -3
  20. data/spec/evented-spec/adapters/adapter_seg.rb +156 -0
  21. data/spec/evented-spec/adapters/amqp_spec.rb +58 -0
  22. data/spec/evented-spec/adapters/cool_io_spec.rb +30 -0
  23. data/spec/evented-spec/adapters/em_spec.rb +29 -0
  24. data/spec/{em_defaults_spec.rb → evented-spec/defaults_options_spec.rb} +0 -0
  25. data/spec/{em_metadata_spec.rb → evented-spec/evented_spec_metadata_spec.rb} +0 -0
  26. data/spec/{util_spec.rb → evented-spec/util_spec.rb} +0 -0
  27. data/spec/{failing_rspec_spec.rb → integration/failing_rspec_spec.rb} +1 -1
  28. data/spec/spec_helper.rb +18 -9
  29. data/tasks/spec.rake +7 -2
  30. metadata +44 -24
  31. data/lib/evented-spec/rspec.rb +0 -267
  32. data/spec/cool_io_spec.rb +0 -72
  33. data/spec/rspec_amqp_spec.rb +0 -116
  34. data/spec/rspec_em_spec.rb +0 -53
  35. data/spec/shared_examples.rb +0 -194
@@ -0,0 +1,58 @@
1
+ require 'spec_helper'
2
+
3
+ describe EventedSpec::SpecHelper, "AMQP bindings" do
4
+ include EventedSpec::SpecHelper
5
+ default_timeout 0.5
6
+
7
+ def amqp_running?
8
+ EM.reactor_running? && !!AMQP.connection
9
+ end # em_running?
10
+
11
+ let(:method_name) { "amqp" }
12
+ let(:prefix) { "amqp_" }
13
+
14
+ it_should_behave_like "EventedSpec adapter"
15
+
16
+ describe EventedSpec::AMQPSpec do
17
+ include EventedSpec::AMQPSpec
18
+ it "should run inside of amqp block" do
19
+ amqp_running?.should be_true
20
+ done
21
+ end
22
+ end
23
+
24
+ describe "actual AMQP functionality" do
25
+ include EventedSpec::SpecHelper
26
+ default_options AMQP_OPTS if defined? AMQP_OPTS
27
+
28
+ def publish_and_consume_once(queue_name="test_sink", data="data")
29
+ amqp(:spec_timeout => 0.5) do
30
+ AMQP::Channel.new do |channel, _|
31
+ exchange = channel.direct(queue_name)
32
+ queue = channel.queue(queue_name).bind(exchange)
33
+ queue.subscribe do |hdr, msg|
34
+ hdr.should be_an AMQP::Header
35
+ msg.should == data
36
+ done { queue.unsubscribe; queue.delete }
37
+ end
38
+ EM.add_timer(0.2) do
39
+ exchange.publish data
40
+ end
41
+ end
42
+ end
43
+ end
44
+
45
+ it 'sends data to the queue' do
46
+ publish_and_consume_once
47
+ end
48
+
49
+ it 'does not hang sending data to the same queue, again' do
50
+ publish_and_consume_once
51
+ end
52
+
53
+ it 'cleans Thread.current[:mq] after pubsub examples' do
54
+ Thread.current[:mq].should be_nil
55
+ end
56
+ end
57
+
58
+ end
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ describe EventedSpec::SpecHelper, "Cool.io bindings", :nojruby => true do
4
+ include EventedSpec::SpecHelper
5
+ default_timeout 1
6
+
7
+ def coolio_running?
8
+ Coolio::Loop.default.instance_variable_get(:@running)
9
+ end # coolio_running?
10
+
11
+ after(:each) {
12
+ coolio_running?.should be_false
13
+ }
14
+
15
+ let(:method_name) { "coolio" }
16
+ let(:prefix) { "coolio_" }
17
+
18
+ it_should_behave_like "EventedSpec adapter"
19
+
20
+
21
+ describe EventedSpec::CoolioSpec do
22
+ include EventedSpec::CoolioSpec
23
+ it "should run inside of coolio loop" do
24
+ coolio_running?.should be_true
25
+ Coolio::Loop.default.has_active_watchers?.should be_true
26
+ done
27
+ end
28
+ end
29
+
30
+ end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ describe EventedSpec::SpecHelper, "EventMachine bindings" do
4
+ include EventedSpec::SpecHelper
5
+ default_timeout 0.5
6
+
7
+ def em_running?
8
+ EM.reactor_running?
9
+ end # em_running?
10
+
11
+ after(:each) {
12
+ em_running?.should be_false
13
+ }
14
+
15
+ let(:method_name) { "em" }
16
+ let(:prefix) { "em_" }
17
+
18
+ it_should_behave_like "EventedSpec adapter"
19
+
20
+
21
+ describe EventedSpec::EMSpec do
22
+ include EventedSpec::EMSpec
23
+ it "should run inside of em loop" do
24
+ em_running?.should be_true
25
+ done
26
+ end
27
+ end
28
+
29
+ end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe 'Following 9 examples should all be failing:' do
3
+ describe 'Following 9 examples should all be failing:', :deliberately_failing => true do
4
4
  describe EventMachine, " when running failing examples" do
5
5
  include EventedSpec::EMSpec
6
6
 
@@ -1,32 +1,41 @@
1
- $LOAD_PATH << "." unless $LOAD_PATH.include? "." # moronic 1.9.2 breaks things bad
1
+ #$LOAD_PATH << "." unless $LOAD_PATH.include? "." # moronic 1.9.2 breaks things bad
2
2
 
3
3
  require 'bundler'
4
4
  Bundler.setup
5
5
  Bundler.require :default, :test
6
6
 
7
7
  require 'yaml'
8
- require 'evented-spec/rspec'
9
- require 'shared_examples'
8
+ require 'evented-spec'
9
+ require 'evented-spec/adapters/adapter_seg'
10
10
 
11
- require 'amqp'
12
- require 'cool.io'
13
11
 
14
- def rspec2?
15
- defined?(RSpec)
12
+ require 'amqp'
13
+ begin
14
+ require 'cool.io'
15
+ rescue LoadError => e
16
+ if RUBY_PLATFORM =~ /java/
17
+ puts "Cool.io is unavailable for jruby"
18
+ else
19
+ # cause unknown, reraise
20
+ raise e
21
+ end
16
22
  end
17
23
 
18
24
  # Done is defined as noop to help share examples between evented and non-evented specs
19
25
  def done
20
26
  end
21
27
 
22
- RSPEC = rspec2? ? RSpec : Spec
28
+ RSpec.configure do |c|
29
+ c.filter_run_excluding :nojruby => true if RUBY_PLATFORM =~ /java/
30
+ c.filter_run_excluding :deliberately_failing => true if ENV["EXCLUDE_DELIBERATELY_FAILING_SPECS"]
31
+ end
23
32
 
24
33
  amqp_config = File.dirname(__FILE__) + '/amqp.yml'
25
34
 
26
35
  AMQP_OPTS = unless File.exists? amqp_config
27
36
  {:user => 'guest',
28
37
  :pass => 'guest',
29
- :host => '10.211.55.2',
38
+ :host => 'localhost',
30
39
  :vhost => '/'}
31
40
  else
32
41
  class Hash
@@ -1,11 +1,16 @@
1
1
  desc 'Alias to spec:spec'
2
- task :spec => 'spec:spec'
2
+ task :spec => 'spec:all'
3
3
 
4
4
  namespace :spec do
5
5
  require 'rspec/core/rake_task'
6
6
 
7
7
  desc "Run all specs"
8
- RSpec::Core::RakeTask.new(:spec){|task|}
8
+ RSpec::Core::RakeTask.new(:all){|task|}
9
+
10
+ desc "Run all non-failing specs (for CI)"
11
+ RSpec::Core::RakeTask.new(:ci) do |task|
12
+ ENV["EXCLUDE_DELIBERATELY_FAILING_SPECS"] = "1"
13
+ end
9
14
 
10
15
  desc "Run specs with RCov"
11
16
  RSpec::Core::RakeTask.new(:rcov) do |t|
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: evented-spec
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.4.0
5
+ version: 0.4.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Arvicco
@@ -11,7 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2011-04-12 00:00:00 -05:00
14
+ date: 2011-04-29 00:00:00 +04:00
15
15
  default_executable:
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
@@ -31,9 +31,9 @@ dependencies:
31
31
  requirement: &id002 !ruby/object:Gem::Requirement
32
32
  none: false
33
33
  requirements:
34
- - - "="
34
+ - - ~>
35
35
  - !ruby/object:Gem::Version
36
- version: 0.8.0.pre
36
+ version: 0.8.0.rc1
37
37
  type: :development
38
38
  version_requirements: *id002
39
39
  - !ruby/object:Gem::Dependency
@@ -56,8 +56,19 @@ dependencies:
56
56
  - - ~>
57
57
  - !ruby/object:Gem::Version
58
58
  version: 4.2.7
59
- type: :runtime
59
+ type: :development
60
60
  version_requirements: *id004
61
+ - !ruby/object:Gem::Dependency
62
+ name: yard
63
+ prerelease: false
64
+ requirement: &id005 !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: "0"
70
+ type: :development
71
+ version_requirements: *id005
61
72
  description: Simple API for writing asynchronous EventMachine and AMQP specs. Runs legacy EM-Spec based examples. Supports RSpec and RSpec2.
62
73
  email: arvitallian@gmail.com
63
74
  executables: []
@@ -70,26 +81,34 @@ extra_rdoc_files:
70
81
  - README.textile
71
82
  files:
72
83
  - lib/amqp-spec.rb
73
- - lib/evented-spec/amqp.rb
84
+ - lib/evented-spec/amqp_spec.rb
85
+ - lib/evented-spec/coolio_spec.rb
86
+ - lib/evented-spec/em_spec.rb
74
87
  - lib/evented-spec/evented_example/amqp_example.rb
75
88
  - lib/evented-spec/evented_example/coolio_example.rb
76
89
  - lib/evented-spec/evented_example/em_example.rb
77
90
  - lib/evented-spec/evented_example.rb
78
- - lib/evented-spec/rspec.rb
91
+ - lib/evented-spec/ext/amqp.rb
92
+ - lib/evented-spec/ext/coolio.rb
93
+ - lib/evented-spec/spec_helper/amqp_helpers.rb
94
+ - lib/evented-spec/spec_helper/coolio_helpers.rb
95
+ - lib/evented-spec/spec_helper/event_machine_helpers.rb
96
+ - lib/evented-spec/spec_helper.rb
79
97
  - lib/evented-spec/util.rb
80
98
  - lib/evented-spec/version.rb
81
99
  - lib/evented-spec.rb
82
- - spec/cool_io_spec.rb
83
- - spec/em_defaults_spec.rb
100
+ - spec/amqp.yml
84
101
  - spec/em_hooks_spec.rb
85
- - spec/em_metadata_spec.rb
86
- - spec/failing_rspec_spec.rb
87
- - spec/rspec_amqp_spec.rb
88
- - spec/rspec_em_spec.rb
89
- - spec/shared_examples.rb
102
+ - spec/evented-spec/adapters/adapter_seg.rb
103
+ - spec/evented-spec/adapters/amqp_spec.rb
104
+ - spec/evented-spec/adapters/cool_io_spec.rb
105
+ - spec/evented-spec/adapters/em_spec.rb
106
+ - spec/evented-spec/defaults_options_spec.rb
107
+ - spec/evented-spec/evented_spec_metadata_spec.rb
108
+ - spec/evented-spec/util_spec.rb
109
+ - spec/integration/failing_rspec_spec.rb
90
110
  - spec/spec.opts
91
111
  - spec/spec_helper.rb
92
- - spec/util_spec.rb
93
112
  - tasks/common.rake
94
113
  - tasks/doc.rake
95
114
  - tasks/gem.rake
@@ -130,20 +149,21 @@ required_rubygems_version: !ruby/object:Gem::Requirement
130
149
  version: "0"
131
150
  requirements: []
132
151
 
133
- rubyforge_project:
152
+ rubyforge_project: evented-spec
134
153
  rubygems_version: 1.6.2
135
154
  signing_key:
136
155
  specification_version: 3
137
156
  summary: Simple API for writing asynchronous EventMachine/AMQP specs. Supports RSpec and RSpec2.
138
157
  test_files:
139
- - spec/cool_io_spec.rb
140
- - spec/em_defaults_spec.rb
158
+ - spec/amqp.yml
141
159
  - spec/em_hooks_spec.rb
142
- - spec/em_metadata_spec.rb
143
- - spec/failing_rspec_spec.rb
144
- - spec/rspec_amqp_spec.rb
145
- - spec/rspec_em_spec.rb
146
- - spec/shared_examples.rb
160
+ - spec/evented-spec/adapters/adapter_seg.rb
161
+ - spec/evented-spec/adapters/amqp_spec.rb
162
+ - spec/evented-spec/adapters/cool_io_spec.rb
163
+ - spec/evented-spec/adapters/em_spec.rb
164
+ - spec/evented-spec/defaults_options_spec.rb
165
+ - spec/evented-spec/evented_spec_metadata_spec.rb
166
+ - spec/evented-spec/util_spec.rb
167
+ - spec/integration/failing_rspec_spec.rb
147
168
  - spec/spec.opts
148
169
  - spec/spec_helper.rb
149
- - spec/util_spec.rb
@@ -1,267 +0,0 @@
1
- require 'evented-spec/amqp'
2
- require 'evented-spec/evented_example'
3
- require 'evented-spec/util'
4
-
5
- # You can include one of the following modules into your example groups:
6
- # EventedSpec::SpecHelper,
7
- # EventedSpec::AMQPSpec,
8
- # EventedSpec::EMSpec.
9
- #
10
- # EventedSpec::SpecHelper module defines #ampq and #em methods that can be safely used inside
11
- # your specs (examples) to test code running inside AMQP.start or EM.run loop
12
- # respectively. Each example is running in a separate event loop,you can control
13
- # for timeouts either with :spec_timeout option given to #amqp/#em method or setting
14
- # a default timeout using default_timeout(timeout) macro inside describe/context block.
15
- #
16
- # If you include EventedSpec::Spec module into your example group, each example of this group
17
- # will run inside AMQP.start loop without the need to explicitly call 'amqp'. In order to
18
- # provide options to AMQP loop, default_options({opts}) macro is defined.
19
- #
20
- # Including EventedSpec::EMSpec module into your example group, each example of this group will
21
- # run inside EM.run loop without the need to explicitly call 'em'.
22
- #
23
- # In order to stop AMQP/EM loop, you should call 'done' AFTER you are sure that your
24
- # example is finished and your expectations executed. For example if you are using
25
- # subscribe block that tests expectations on messages, 'done' should be probably called
26
- # at the end of this block.
27
- #
28
- module EventedSpec
29
-
30
- # EventedSpec::SpecHelper module defines #ampq and #em methods that can be safely used inside
31
- # your specs (examples) to test code running inside AMQP.start or EM.run loop
32
- # respectively. Each example is running in a separate event loop, you can control
33
- # for timeouts either with :spec_timeout option given to #amqp/#em/#coolio method or setting
34
- # a default timeout using default_timeout(timeout) macro inside describe/context block.
35
- module SpecHelper
36
- # Error which shows in RSpec log when example does not call #done inside
37
- # of event loop.
38
- SpecTimeoutExceededError = Class.new(RuntimeError)
39
-
40
- # Class methods (macros) for any example groups that includes SpecHelper.
41
- # You can use these methods as macros inside describe/context block.
42
- module GroupMethods
43
- # Returns evented-spec related metadata for particular example group.
44
- # Metadata is cloned from parent to children, so that children inherit
45
- # all the options and hooks set in parent example groups
46
- #
47
- # @return [Hash] hash with example group metadata
48
- def evented_spec_metadata
49
- if @evented_spec_metadata
50
- @evented_spec_metadata
51
- else
52
- @evented_spec_metadata = superclass.evented_spec_metadata rescue {}
53
- @evented_spec_metadata = EventedSpec::Util.deep_clone(@evented_spec_metadata)
54
- end
55
- end # evented_spec_metadata
56
-
57
- # Sets/retrieves default timeout for running evented specs for this
58
- # example group and its nested groups.
59
- #
60
- # @param [Float] desired timeout for the example group
61
- # @return [Float]
62
- def default_timeout(spec_timeout = nil)
63
- if spec_timeout
64
- default_options[:spec_timeout] = spec_timeout
65
- else
66
- default_options[:spec_timeout] || self.superclass.default_timeout
67
- end
68
- end
69
-
70
- # Sets/retrieves default AMQP.start options for this example group
71
- # and its nested groups.
72
- #
73
- # @param [Hash] context-specific options for helper methods like #amqp, #em, #coolio
74
- # @return [Hash]
75
- def default_options(opts = nil)
76
- evented_spec_metadata[:default_options] ||= {}
77
- if opts
78
- evented_spec_metadata[:default_options].merge!(opts)
79
- else
80
- evented_spec_metadata[:default_options]
81
- end
82
- end
83
-
84
- # Adds before hook that will run inside EM event loop before example starts.
85
- #
86
- # @param [Symbol] scope for hook (only :each is supported currently)
87
- # @yield hook block
88
- def em_before(scope = :each, &block)
89
- raise ArgumentError, "em_before only supports :each scope" unless :each == scope
90
- em_hooks[:em_before] << block
91
- end
92
-
93
- # Adds after hook that will run inside EM event loop after example finishes.
94
- #
95
- # @param [Symbol] scope for hook (only :each is supported currently)
96
- # @yield hook block
97
- def em_after(scope = :each, &block)
98
- raise ArgumentError, "em_after only supports :each scope" unless :each == scope
99
- em_hooks[:em_after].unshift block
100
- end
101
-
102
- # Adds before hook that will run inside AMQP connection (AMQP.start loop)
103
- # before example starts
104
- #
105
- # @param [Symbol] scope for hook (only :each is supported currently)
106
- # @yield hook block
107
- def amqp_before(scope = :each, &block)
108
- raise ArgumentError, "amqp_before only supports :each scope" unless :each == scope
109
- em_hooks[:amqp_before] << block
110
- end
111
-
112
- # Adds after hook that will run inside AMQP connection (AMQP.start loop)
113
- # after example finishes
114
- #
115
- # @param [Symbol] scope for hook (only :each is supported currently)
116
- # @yield hook block
117
- def amqp_after(scope = :each, &block)
118
- raise ArgumentError, "amqp_after only supports :each scope" unless :each == scope
119
- em_hooks[:amqp_after].unshift block
120
- end
121
-
122
- # Collection of evented hooks for current example group
123
- #
124
- # @return [Hash] hash with hooks
125
- def em_hooks
126
- evented_spec_metadata[:em_hooks] ||= {
127
- :em_before => [],
128
- :em_after => [],
129
- :amqp_before => [],
130
- :amqp_after => []
131
- }
132
- end
133
- end
134
-
135
- def self.included(example_group)
136
- unless example_group.respond_to? :default_timeout
137
- example_group.extend GroupMethods
138
- end
139
- end
140
-
141
- # Retrieves default options passed in from enclosing example groups
142
- #
143
- # @return [Hash] default option for currently running example
144
- def default_options
145
- @em_default_options ||= self.class.default_options.dup rescue {}
146
- end
147
-
148
- # Yields to a given block inside EM.run and AMQP.start loops.
149
- #
150
- # @param [Hash] options for amqp connection initialization
151
- # @option opts [String] :user ('guest') Username as defined by the AMQP server.
152
- # @option opts [String] :pass ('guest') Password as defined by the AMQP server.
153
- # @option opts [String] :vhost ('/') Virtual host as defined by the AMQP server.
154
- # @option opts [Numeric] :timeout (nil) *Connection* timeout, measured in seconds.
155
- # @option opts [Boolean] :logging (false) Toggle the extremely verbose AMQP logging.
156
- # @option opts [Numeric] :spec_timeout (nil) Amount of time before spec is stopped by timeout
157
- # @yield block to execute after amqp connects
158
- def amqp(opts = {}, &block)
159
- opts = default_options.merge opts
160
- @evented_example = AMQPExample.new(opts, self, &block)
161
- @evented_example.run
162
- end
163
-
164
- # Yields to block inside EM loop, :spec_timeout option (in seconds) is used to
165
- # force spec to timeout if something goes wrong and EM/AMQP loop hangs for some
166
- # reason.
167
- #
168
- # For compatibility with EM-Spec API, em method accepts either options Hash
169
- # or numeric timeout in seconds.
170
- #
171
- # @param [Hash] options for eventmachine
172
- # @param opts [Numeric] :spec_timeout (nil) Amount of time before spec is stopped by timeout
173
- # @yield block to execute after eventmachine loop starts
174
- def em(opts = {}, &block)
175
- opts = default_options.merge(opts.is_a?(Hash) ? opts : { :spec_timeout => opts })
176
- @evented_example = EMExample.new(opts, self, &block)
177
- @evented_example.run
178
- end
179
-
180
- # Yields to block inside cool.io loop, :spec_timeout option (in seconds) is used to
181
- # force spec to timeout if something goes wrong and EM/AMQP loop hangs for some
182
- # reason.
183
- #
184
- # @param [Hash] options for cool.io
185
- # @param opts [Numeric] :spec_timeout (nil) Amount of time before spec is stopped by timeout
186
- # @yield block to execute after cool.io loop starts
187
- def coolio(opts = {}, &block)
188
- opts = default_options.merge opts
189
- @evented_example = CoolioExample.new(opts, self, &block)
190
- @evented_example.run
191
- end
192
-
193
- # Breaks the event loop and finishes the spec. This should be called after
194
- # you are reasonably sure that your expectations succeeded.
195
- # Done yields to any given block first, then stops EM event loop.
196
- # For amqp specs, stops AMQP and cleans up AMQP state.
197
- #
198
- # You may pass delay (in seconds) to done. If you do so, please keep in mind
199
- # that your (default or explicit) spec timeout may fire before your delayed done
200
- # callback is due, leading to SpecTimeoutExceededError
201
- #
202
- # @param [Float] Delay before event loop is stopped
203
- def done(*args, &block)
204
- @evented_example.done *args, &block if @evented_example
205
- end
206
-
207
- # Manually sets timeout for currently running example. If spec doesn't call
208
- # #done before timeout, it is marked as failed on timeout.
209
- #
210
- # @param [Float] Delay before event loop is stopped with error
211
- def timeout(*args)
212
- @evented_example.timeout *args if @evented_example
213
- end
214
-
215
- end # module SpecHelper
216
-
217
- # If you include EventedSpec::AMQPSpec module into your example group, each example of this group
218
- # will run inside AMQP.start loop without the need to explicitly call 'amqp'. In order
219
- # to provide options to AMQP loop, default_options class method is defined. Remember,
220
- # when using EventedSpec::Specs, you'll have a single set of AMQP.start options for all your
221
- # examples.
222
- #
223
- module AMQPSpec
224
- def self.included(example_group)
225
- example_group.send(:include, SpecHelper)
226
- example_group.extend(ClassMethods)
227
- end
228
-
229
- # @private
230
- module ClassMethods
231
- def it(*args, &block)
232
- if block
233
- new_block = Proc.new {|example_group_instance| (example_group_instance || self).instance_eval { amqp(&block) } }
234
- super(*args, &new_block)
235
- else
236
- # pending example
237
- super
238
- end
239
- end # it
240
- end # ClassMethods
241
- end # AMQPSpec
242
-
243
- # Including EventedSpec::EMSpec module into your example group, each example of this group
244
- # will run inside EM.run loop without the need to explicitly call 'em'.
245
- #
246
- module EMSpec
247
- def self.included(example_group)
248
- example_group.send(:include, SpecHelper)
249
- example_group.extend ClassMethods
250
- end
251
-
252
- # @private
253
- module ClassMethods
254
- def it(*args, &block)
255
- if block
256
- # Shared example groups seem to pass example group instance
257
- # to the actual example block
258
- new_block = Proc.new {|example_group_instance| (example_group_instance || self).instance_eval { em(&block) } }
259
- super(*args, &new_block)
260
- else
261
- # pending example
262
- super
263
- end
264
- end # it
265
- end # ClassMethods
266
- end # EMSpec
267
- end # EventedSpec