amqp-spec 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/HISTORY CHANGED
@@ -46,22 +46,14 @@
46
46
 
47
47
  * SpecHelper class methods refactored
48
48
 
49
- == 0.1.10 / 2010-10-15
50
-
51
- * Cleanup
52
-
53
49
  == 0.1.11 / 2010-10-18
54
50
 
55
51
  * Optional delay added to done
56
52
 
57
- == 0.1.12 / 2010-10-18
58
-
59
- * README extended
60
-
61
- == 0.1.13 / 2010-10-23
62
-
63
- * Release
64
-
65
53
  == 0.2.0 / 2010-10-28
66
54
 
67
55
  * Rspec 2 support added
56
+
57
+ == 0.2.1 / 2010-10-28
58
+
59
+ * RSpec2-specific examples added
@@ -4,7 +4,7 @@ url: http://github.com/arvicco/amqp-spec
4
4
 
5
5
  == Summary
6
6
 
7
- Simple API for testing asynchronous EventMachine/AMQP code.
7
+ Simple API for writing asynchronous EventMachine/AMQP specs. Supports RSpec and RSpec2.
8
8
 
9
9
  == Description
10
10
 
@@ -28,12 +28,17 @@ between examples. You can try to combine AMQP-Spec and Moqueue[http://github.com
28
28
  if you want to abstract away actual broker interactions, but still specify some event-based expectations.
29
29
 
30
30
  ==Rspec
31
+
31
32
  There are several ways to use amqp-spec. To use it as a helper, include AMQP::SpecHelper in your describe block.
32
33
  You then use either 'amqp' or 'em' methods to wrap your evented test code. Inside the amqp/em block, you must call
33
34
  #done after your expectations. Everything works normally otherwise. You can use default_timeout and default_options
34
35
  macros to avoid manually setting AMQP options in each example. However, if you DO manually set options inside
35
- the example, they override the defaults. Only default options and default timeout are global across groups,
36
- it is currently impossible to have separate defaults for separate groups.
36
+ the example, they override the defaults.
37
+
38
+ RSpec 1:: Default options and default timeout are global across all groups, it is impossible to have separate
39
+ defaults for separate groups.
40
+ RSpec 2:: Default options and default timeout are local for each example group and inherited by its nested groups,
41
+ different example groups can have separate defaults.
37
42
 
38
43
  require "amqp-spec/rspec"
39
44
  describe AMQP do
@@ -205,7 +210,7 @@ actually fired at all AFTER your amqp/em block. Something like this will do the
205
210
 
206
211
  ==Limitations
207
212
 
208
- AMQP-Spec can be currently used with rspec only. I suppose, there is nothing special in extending EM-Spec's
213
+ AMQP-Spec can be currently used with Rspec only. I suppose, there is nothing special in extending EM-Spec's
209
214
  test unit and bacon support, I just do not have experience dealing with these platforms. Another limitation,
210
215
  it uses native Fibers and therefore not compatible with Ruby 1.8. Again, it seems possible to rewrite it in
211
216
  1.8-compatible style, with string evals and Fiber backport, but I'd rather leave this work to someone else.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.1
@@ -55,42 +55,39 @@ module AMQP
55
55
  SpecTimeoutExceededError = Class.new(RuntimeError)
56
56
 
57
57
  def self.included(example_group)
58
- # unless defined? self.default_timeout
59
- if defined?(RSpec)
60
- example_group.instance_exec do
61
58
 
62
- metadata[:em_default_options] = {}
63
- metadata[:em_default_timeout] = nil
59
+ extended_class = defined?(RSpec) ? example_group : ::Spec::Example::ExampleGroup
60
+ unless extended_class.respond_to? :default_timeout
61
+ extended_class.instance_exec do
62
+ if defined?(RSpec)
63
+ metadata[:em_default_options] = {}
64
+ metadata[:em_default_timeout] = nil
64
65
 
65
- def self.default_timeout(spec_timeout=nil)
66
- metadata[:em_default_timeout] = spec_timeout if spec_timeout
67
- metadata[:em_default_timeout]
68
- end
66
+ def self.default_timeout(spec_timeout=nil)
67
+ metadata[:em_default_timeout] = spec_timeout if spec_timeout
68
+ metadata[:em_default_timeout]
69
+ end
69
70
 
70
- def self.default_options(opts=nil)
71
- metadata[:em_default_options] = opts if opts
72
- metadata[:em_default_options]
73
- end
74
- end
75
- else
76
- ::Spec::Example::ExampleGroup.instance_exec do
77
- @@_em_default_options = {}
78
- @@_em_default_timeout = nil
71
+ def self.default_options(opts=nil)
72
+ metadata[:em_default_options] = opts if opts
73
+ metadata[:em_default_options]
74
+ end
75
+ else
76
+ @@_em_default_options = {}
77
+ @@_em_default_timeout = nil
79
78
 
80
- def self.default_timeout(spec_timeout=nil)
81
- @@_em_default_timeout = spec_timeout if spec_timeout
82
- @@_em_default_timeout
83
- end
79
+ def self.default_timeout(spec_timeout=nil)
80
+ @@_em_default_timeout = spec_timeout if spec_timeout
81
+ @@_em_default_timeout
82
+ end
84
83
 
85
- def self.default_options(opts=nil)
86
- @@_em_default_options = opts if opts
87
- @@_em_default_options
84
+ def self.default_options(opts=nil)
85
+ @@_em_default_options = opts if opts
86
+ @@_em_default_options
87
+ end
88
88
  end
89
89
  end
90
-
91
- # end
92
90
  end
93
-
94
91
  end
95
92
 
96
93
  # Yields to given block inside EM.run and AMQP.start loops. This method takes any option that is
@@ -27,7 +27,7 @@ describe 'Evented AMQP specs' do
27
27
  default_options AMQP_OPTS if defined? AMQP_OPTS
28
28
  default_timeout 1 # Can be used to set default :spec_timeout for all your amqp-based specs
29
29
 
30
- puts "Default timeout: #{default_timeout.inspect}, Default options:"
30
+ puts "Default timeout: #{default_timeout}, Default options:"
31
31
  p default_options
32
32
 
33
33
  it_should_behave_like 'SpecHelper examples'
@@ -130,6 +130,27 @@ shared_examples_for 'timeout examples' do
130
130
  specify "AMQP connection should not leak between examples" do
131
131
  AMQP.conn.should be_nil
132
132
  end
133
+
134
+ if rspec2?
135
+ context 'embedded context can set up separate defaults' do
136
+ default_timeout 0.25 # Can be used to set default :spec_timeout for all your amqp-based specs
137
+
138
+ specify 'default timeout should be 0.25' do
139
+ expect { amqp { EM.add_timer(2) { done } } }.to raise_error SpecTimeoutExceededError
140
+ (Time.now-@start).should be_close(0.25, 0.1)
141
+ end
142
+
143
+ context 'deeply embedded context can set up separate defaults' do
144
+ default_timeout 0.5 # Can be used to set default :spec_timeout for all your amqp-based specs
145
+
146
+ specify 'default timeout should be 0.5' do
147
+ expect { amqp { EM.add_timer(2) { done } } }.to raise_error SpecTimeoutExceededError
148
+ (Time.now-@start).should be_close(0.5, 0.1)
149
+ end
150
+ end
151
+ end
152
+
153
+ end
133
154
  end
134
155
 
135
156
  shared_examples_for 'Spec examples' do
@@ -8,7 +8,11 @@ require 'yaml'
8
8
  require 'amqp-spec/rspec'
9
9
  require 'shared_examples'
10
10
 
11
- RSPEC = defined?(RSpec) ? RSpec : Spec
11
+ def rspec2?
12
+ defined?(RSpec)
13
+ end
14
+
15
+ RSPEC = rspec2? ? RSpec : Spec
12
16
 
13
17
  amqp_config = File.dirname(__FILE__) + '/amqp.yml'
14
18
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: amqp-spec
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 0
10
- version: 0.2.0
9
+ - 1
10
+ version: 0.2.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Arvicco
@@ -50,7 +50,7 @@ dependencies:
50
50
  version: 0.6.7
51
51
  type: :runtime
52
52
  version_requirements: *id002
53
- description: Simple API for writing (asynchronous) AMQP specs
53
+ description: Simple API for writing asynchronous EventMachine/AMQP specs. Supports RSpec and RSpec2.
54
54
  email: arvitallian@gmail.com
55
55
  executables: []
56
56
 
@@ -122,7 +122,7 @@ rubyforge_project:
122
122
  rubygems_version: 1.3.7
123
123
  signing_key:
124
124
  specification_version: 3
125
- summary: Simple API for writing (asynchronous) AMQP specs
125
+ summary: Simple API for writing asynchronous EventMachine/AMQP specs. Supports RSpec and RSpec2.
126
126
  test_files:
127
127
  - spec/amqp.yml
128
128
  - spec/failing_rspec_spec.rb