amqp-spec 0.3.2 → 0.3.3
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/HISTORY +4 -0
- data/VERSION +1 -1
- data/lib/amqp-spec/evented_example.rb +4 -11
- data/lib/amqp-spec/rspec.rb +17 -37
- data/spec/em_defaults_spec.rb +67 -24
- data/spec/em_hooks_spec.rb +7 -7
- data/spec/em_metadata_spec.rb +27 -21
- metadata +3 -3
data/HISTORY
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.3
|
@@ -38,18 +38,10 @@ module AMQP
|
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
-
# Retrieves metadata passed in from enclosing example groups
|
42
|
-
#
|
43
|
-
def metadata
|
44
|
-
@metadata ||= @example_group_instance.metadata.dup rescue {}
|
45
|
-
end
|
46
|
-
|
47
41
|
# Runs hooks of specified type (hopefully, inside the event loop)
|
48
42
|
#
|
49
43
|
def run_em_hooks type
|
50
|
-
|
51
|
-
(:before == type ? hooks : hooks.reverse).each do |hook|
|
52
|
-
# @example_group_instance.class.all_hooks(type).each do |hook|
|
44
|
+
@example_group_instance.class.em_hooks[type].each do |hook|
|
53
45
|
if @example_group_instance.respond_to? :instance_eval_without_event_loop
|
54
46
|
@example_group_instance.instance_eval_without_event_loop(&hook)
|
55
47
|
else
|
@@ -78,7 +70,7 @@ module AMQP
|
|
78
70
|
end
|
79
71
|
rescue Exception => @spec_exception
|
80
72
|
# p "Outside loop, caught #{@spec_exception}"
|
81
|
-
run_em_hooks :after # Event loop
|
73
|
+
run_em_hooks :after # Event loop broken, but we still need to run em_after hooks
|
82
74
|
ensure
|
83
75
|
finish_example
|
84
76
|
end
|
@@ -91,7 +83,8 @@ module AMQP
|
|
91
83
|
EM.stop_event_loop if EM.reactor_running?
|
92
84
|
end
|
93
85
|
|
94
|
-
# Called from #run_event_loop when event loop is stopped,
|
86
|
+
# Called from #run_event_loop when event loop is stopped,
|
87
|
+
# but before the example returns.
|
95
88
|
# Descendant classes may redefine to clean up type-specific state.
|
96
89
|
#
|
97
90
|
def finish_example
|
data/lib/amqp-spec/rspec.rb
CHANGED
@@ -54,16 +54,16 @@ module AMQP
|
|
54
54
|
# example group and its nested groups.
|
55
55
|
#
|
56
56
|
def default_timeout spec_timeout=nil
|
57
|
-
|
58
|
-
metadata[:em_timeout]
|
57
|
+
default_options[:spec_timeout] = spec_timeout || default_options[:spec_timeout]
|
59
58
|
end
|
60
59
|
|
61
60
|
# Sets/retrieves default AMQP.start options for this example group
|
62
61
|
# and its nested groups.
|
63
62
|
#
|
64
63
|
def default_options opts=nil
|
65
|
-
metadata[:em_defaults]
|
66
|
-
metadata[:em_defaults]
|
64
|
+
metadata[:em_defaults] ||= {}
|
65
|
+
metadata[:em_defaults][self] ||= (superclass.default_options.dup rescue {})
|
66
|
+
metadata[:em_defaults][self] = opts || metadata[:em_defaults][self]
|
67
67
|
end
|
68
68
|
|
69
69
|
# Add before hook that will run inside EM event loop
|
@@ -75,42 +75,21 @@ module AMQP
|
|
75
75
|
# Add after hook that will run inside EM event loop
|
76
76
|
def em_after scope = :each, &block
|
77
77
|
raise ArgumentError, "em_after only supports :each scope" unless :each == scope
|
78
|
-
em_hooks[:after]
|
78
|
+
em_hooks[:after].unshift block
|
79
79
|
end
|
80
80
|
|
81
|
-
# Collection of evented hooks
|
81
|
+
# Collection of evented hooks for THIS example group
|
82
82
|
def em_hooks
|
83
83
|
metadata[:em_hooks] ||= {}
|
84
|
-
metadata[:em_hooks][self] ||=
|
85
|
-
|
86
|
-
|
84
|
+
metadata[:em_hooks][self] ||=
|
85
|
+
{before: (superclass.em_hooks[:before].clone rescue []),
|
86
|
+
after: (superclass.em_hooks[:after].clone rescue [])}
|
87
87
|
end
|
88
|
-
|
89
|
-
# # Returns a collection of all em hooks of given type
|
90
|
-
# # (including ancestor hooks)
|
91
|
-
# #
|
92
|
-
# def all_hooks type
|
93
|
-
# hooks = superclass.all_hooks(type) rescue []
|
94
|
-
# hooks += em_hooks[type]
|
95
|
-
# end
|
96
|
-
|
97
|
-
# Returns a collection of all em hooks of given type
|
98
|
-
# (including ancestor hooks)
|
99
|
-
#
|
100
|
-
def all_hooks type
|
101
|
-
hooks = superclass.all_hooks(type) rescue []
|
102
|
-
hooks += em_hooks[type]
|
103
|
-
# :before == type ? hooks : hooks.reverse
|
104
|
-
hooks
|
105
|
-
end
|
106
|
-
|
107
88
|
end
|
108
89
|
|
109
90
|
def self.included example_group
|
110
91
|
unless example_group.respond_to? :default_timeout
|
111
92
|
example_group.extend GroupMethods
|
112
|
-
example_group.metadata[:em_defaults] = {}
|
113
|
-
example_group.metadata[:em_timeout] = nil
|
114
93
|
end
|
115
94
|
end
|
116
95
|
|
@@ -120,6 +99,12 @@ module AMQP
|
|
120
99
|
@em_metadata ||= self.class.metadata.dup rescue {}
|
121
100
|
end
|
122
101
|
|
102
|
+
# Retrieves default options passed in from enclosing example groups
|
103
|
+
#
|
104
|
+
def default_options
|
105
|
+
@em_default_options ||= self.class.default_options.dup rescue {}
|
106
|
+
end
|
107
|
+
|
123
108
|
# Yields to a given block inside EM.run and AMQP.start loops. This method takes
|
124
109
|
# any option that is accepted by EventMachine::connect. Options for AMQP.start include:
|
125
110
|
# * :user => String (default ‘guest’) - Username as defined by the AMQP server.
|
@@ -133,8 +118,7 @@ module AMQP
|
|
133
118
|
# reason. SpecTimeoutExceededError is raised if it happens.
|
134
119
|
#
|
135
120
|
def amqp opts={}, &block
|
136
|
-
opts =
|
137
|
-
opts[:spec_timeout] ||= self.class.default_timeout
|
121
|
+
opts = default_options.merge opts
|
138
122
|
@evented_example = AMQPExample.new(opts, self, &block)
|
139
123
|
@evented_example.run
|
140
124
|
end
|
@@ -147,11 +131,7 @@ module AMQP
|
|
147
131
|
# or numeric timeout in seconds.
|
148
132
|
#
|
149
133
|
def em opts = {}, &block
|
150
|
-
|
151
|
-
opts[:spec_timeout] ||= self.class.default_timeout
|
152
|
-
else
|
153
|
-
opts = {spec_timeout: opts}
|
154
|
-
end
|
134
|
+
opts = default_options.merge(opts.is_a?(Hash) ? opts : {spec_timeout: opts})
|
155
135
|
@evented_example = EMExample.new(opts, self, &block)
|
156
136
|
@evented_example.run
|
157
137
|
end
|
data/spec/em_defaults_spec.rb
CHANGED
@@ -2,58 +2,91 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe AMQP::SpecHelper, " .default_options" do
|
4
4
|
include AMQP::SpecHelper
|
5
|
-
root_default_options = {:
|
5
|
+
root_default_options = {:root_key => 1}
|
6
6
|
default_options root_default_options
|
7
7
|
|
8
|
-
it '
|
9
|
-
|
8
|
+
it 'subsequent and nested groups should not change root default options' do
|
9
|
+
root_default_options.should == {:root_key => 1}
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'example has access to default options' do
|
13
|
+
default_options.should == root_default_options
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'defaults can be changed inside example, diverging from example group defaults' do
|
17
|
+
default_options[:example_key] = :example_value
|
18
|
+
default_options.should have_key :example_key
|
19
|
+
default_options.should_not == root_default_options
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'changing example defaults has no effect on subsequent examples' do
|
23
|
+
default_options.should_not have_key :example_key
|
24
|
+
default_options.should == root_default_options
|
10
25
|
end
|
11
26
|
|
12
27
|
context 'inside nested example group 1' do
|
13
|
-
|
14
|
-
|
28
|
+
nested_default_options = default_options
|
29
|
+
|
30
|
+
it 'nested group defaults start as a copy of enclosing group default_options' do
|
31
|
+
nested_default_options.should == root_default_options
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'example has access to default options' do
|
35
|
+
default_options.should == nested_default_options
|
15
36
|
end
|
16
37
|
|
17
38
|
it 'can be changed, thus diverging from example group default_options' do
|
18
|
-
|
19
|
-
|
20
|
-
|
39
|
+
default_options[:example_key] = :example_value
|
40
|
+
default_options.should have_key :example_key
|
41
|
+
default_options.should_not == root_default_options
|
21
42
|
end
|
22
43
|
|
23
44
|
it 'changing example default_options has no effect on subsequent examples' do
|
24
|
-
|
45
|
+
default_options.should_not have_key :example_key
|
46
|
+
default_options.should == root_default_options
|
25
47
|
end
|
26
48
|
|
27
49
|
context 'inside deeply nested example group 1' do
|
28
|
-
|
29
|
-
|
50
|
+
nested_default_options = default_options
|
51
|
+
|
52
|
+
it 'nested group defaults start as a copy of enclosing group default_options' do
|
53
|
+
nested_default_options.should == root_default_options
|
30
54
|
end
|
31
55
|
|
32
|
-
it '
|
33
|
-
|
34
|
-
|
35
|
-
|
56
|
+
it 'example has access to default options' do
|
57
|
+
default_options.should == nested_default_options
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'can be changed in example, thus diverging from example group default_options' do
|
61
|
+
default_options[:example_key] = :example_value
|
62
|
+
default_options.should have_key :example_key
|
63
|
+
default_options.should_not == nested_default_options
|
36
64
|
end
|
37
65
|
|
38
66
|
it 'changing example default_options has no effect on subsequent examples' do
|
39
|
-
|
40
|
-
|
67
|
+
default_options.should_not have_key :example_key
|
68
|
+
default_options.should == nested_default_options
|
41
69
|
end
|
42
|
-
end
|
70
|
+
end # inside deeply nested example group 1
|
43
71
|
end # inside nested example group 1
|
44
72
|
|
45
73
|
context 'inside nested example group 2' do
|
46
74
|
default_options[:nested_key] = :nested_value
|
47
75
|
nested_default_options = default_options
|
48
76
|
|
49
|
-
it 'changing
|
77
|
+
it 'changing default options inside nested group works' do
|
78
|
+
nested_default_options.should have_key :nested_key
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'changing default_options in nested group affects example default_options' do
|
50
82
|
default_options.should == nested_default_options
|
51
83
|
default_options.should_not == root_default_options
|
52
84
|
end
|
53
85
|
|
54
|
-
it 'can be changed, thus diverging from example group default_options' do
|
86
|
+
it 'can be changed in example, thus diverging from example group default_options' do
|
55
87
|
default_options[:example_key] = :example_value
|
56
88
|
default_options.should have_key :example_key
|
89
|
+
default_options.should have_key :nested_key
|
57
90
|
default_options.should_not == nested_default_options
|
58
91
|
default_options.should_not == root_default_options
|
59
92
|
end
|
@@ -66,16 +99,27 @@ describe AMQP::SpecHelper, " .default_options" do
|
|
66
99
|
default_options[:deeply_nested_key] = :deeply_nested_value
|
67
100
|
deeply_nested_default_options = default_options
|
68
101
|
|
102
|
+
it 'inherits default options from enclosing group' do
|
103
|
+
deeply_nested_default_options.should have_key :nested_key
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'changing default options inside deeply nested group works' do
|
107
|
+
deeply_nested_default_options.should have_key :deeply_nested_key
|
108
|
+
end
|
109
|
+
|
69
110
|
it 'changing default_options in nested group affects example group default_options' do
|
70
111
|
default_options.should == deeply_nested_default_options
|
112
|
+
default_options.should have_key :nested_key
|
113
|
+
default_options.should have_key :deeply_nested_key
|
71
114
|
default_options.should_not == nested_default_options
|
72
115
|
default_options.should_not == root_default_options
|
73
|
-
default_options.should have_key :deeply_nested_key
|
74
116
|
end
|
75
117
|
|
76
|
-
it 'can be changed, thus diverging from example group default_options' do
|
118
|
+
it 'can be changed in example, thus diverging from example group default_options' do
|
77
119
|
default_options[:example_key] = :example_value
|
78
120
|
default_options.should have_key :example_key
|
121
|
+
default_options.should have_key :nested_key
|
122
|
+
default_options.should have_key :deeply_nested_key
|
79
123
|
default_options.should_not == nested_default_options
|
80
124
|
default_options.should_not == root_default_options
|
81
125
|
end
|
@@ -83,7 +127,6 @@ describe AMQP::SpecHelper, " .default_options" do
|
|
83
127
|
it 'changing example default_options has no effect on subsequent examples' do
|
84
128
|
default_options.should == deeply_nested_default_options
|
85
129
|
end
|
86
|
-
end
|
130
|
+
end # inside deeply nested example group 2
|
87
131
|
end # inside nested example group 2
|
88
|
-
|
89
132
|
end # describe AMQP, "default_options"
|
data/spec/em_hooks_spec.rb
CHANGED
@@ -58,17 +58,17 @@ shared_examples_for 'hooked amqp specs' do
|
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
|
-
describe AMQP, "
|
62
|
-
before { @hooks_called = [] }
|
61
|
+
describe AMQP::SpecHelper, ".em_before/.em_after" do
|
62
|
+
before { @hooks_called = [] }
|
63
63
|
|
64
64
|
describe AMQP, " tested with AMQP::SpecHelper" do
|
65
65
|
include AMQP::SpecHelper
|
66
66
|
default_options AMQP_OPTS if defined? AMQP_OPTS
|
67
67
|
|
68
|
-
before { @hooks_called << :before }
|
68
|
+
before { @hooks_called << :before }
|
69
69
|
|
70
|
-
em_before { @hooks_called << :em_before }
|
71
|
-
em_after { @hooks_called << :em_after }
|
70
|
+
em_before { @hooks_called << :em_before }
|
71
|
+
em_after { @hooks_called << :em_after }
|
72
72
|
|
73
73
|
context 'for non-evented specs' do
|
74
74
|
after { @hooks_called.should == [:before] }
|
@@ -159,7 +159,7 @@ describe AMQP, " with em_before/em_after" do
|
|
159
159
|
end
|
160
160
|
|
161
161
|
context 'inside nested example group' do
|
162
|
-
before { @hooks_called << :amqp_context_before }
|
162
|
+
before { @hooks_called << :amqp_context_before; $debug = true }
|
163
163
|
em_before { @hooks_called << :amqp_context_em_before }
|
164
164
|
em_after { @hooks_called << :amqp_context_em_after }
|
165
165
|
|
@@ -168,7 +168,7 @@ describe AMQP, " with em_before/em_after" do
|
|
168
168
|
:em_before,
|
169
169
|
:amqp_context_em_before,
|
170
170
|
:amqp_context_em_after,
|
171
|
-
:em_after] }
|
171
|
+
:em_after] ; $debug = nil}
|
172
172
|
|
173
173
|
it_should_behave_like 'hooked amqp specs'
|
174
174
|
|
data/spec/em_metadata_spec.rb
CHANGED
@@ -22,10 +22,12 @@ describe AMQP::SpecHelper, " .metadata" do
|
|
22
22
|
context 'inside nested example group 1' do
|
23
23
|
nested_metadata = metadata
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
25
|
+
if rspec2? #describes RSpec2-specific behavior
|
26
|
+
it 'nested group metadata CONTAINS root enclosing group metadata' do
|
27
|
+
nested_metadata.should_not == root_metadata
|
28
|
+
nested_metadata[:example_group][:example_group].should ==
|
29
|
+
root_metadata[:example_group]
|
30
|
+
end
|
29
31
|
end
|
30
32
|
|
31
33
|
it 'except for :example_group key, nested and root group metadata is the same' do
|
@@ -54,13 +56,15 @@ describe AMQP::SpecHelper, " .metadata" do
|
|
54
56
|
context 'inside deeply nested example group 1' do
|
55
57
|
deeply_nested_metadata = metadata
|
56
58
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
59
|
+
if rspec2? #describes RSpec2-specific behavior
|
60
|
+
it 'deeply_nested group metadata CONTAINS enclosing group metadata' do
|
61
|
+
deeply_nested_metadata.should_not == root_metadata
|
62
|
+
deeply_nested_metadata[:example_group][:example_group].should ==
|
63
|
+
nested_metadata[:example_group]
|
64
|
+
end
|
61
65
|
end
|
62
66
|
|
63
|
-
it 'except for :example_group
|
67
|
+
it 'except for :example_group, deeply_nested and root group metadata is the same' do
|
64
68
|
@root = root_metadata.dup
|
65
69
|
@root.delete(:example_group)
|
66
70
|
@nested = nested_metadata.dup
|
@@ -85,18 +89,19 @@ describe AMQP::SpecHelper, " .metadata" do
|
|
85
89
|
metadata.should_not have_key :example_key
|
86
90
|
metadata.should == deeply_nested_metadata
|
87
91
|
end
|
88
|
-
|
89
|
-
end
|
92
|
+
end # inside deeply nested example group 1
|
90
93
|
end # inside nested example group 1
|
91
94
|
|
92
95
|
context 'inside nested example group 2' do
|
93
96
|
metadata[:nested_key] = :nested_value
|
94
97
|
nested_metadata = metadata
|
95
98
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
99
|
+
if rspec2? #describes RSpec2-specific behavior
|
100
|
+
it 'nested group metadata CONTAINS root enclosing group metadata' do
|
101
|
+
nested_metadata.should_not == root_metadata
|
102
|
+
nested_metadata[:example_group][:example_group].should ==
|
103
|
+
root_metadata[:example_group]
|
104
|
+
end
|
100
105
|
end
|
101
106
|
|
102
107
|
it "except for :example_group and modified keys," +
|
@@ -124,13 +129,15 @@ describe AMQP::SpecHelper, " .metadata" do
|
|
124
129
|
metadata.should == nested_metadata
|
125
130
|
end
|
126
131
|
|
127
|
-
context 'inside deeply nested example group
|
132
|
+
context 'inside deeply nested example group 2' do
|
128
133
|
metadata[:deeply_nested_key] = :deeply_nested_value
|
129
134
|
deeply_nested_metadata = metadata
|
130
135
|
|
131
|
-
|
132
|
-
|
133
|
-
|
136
|
+
if rspec2? #describes RSpec2-specific behavior
|
137
|
+
it 'deeply_nested group metadata CONTAINS enclosing group metadata' do
|
138
|
+
deeply_nested_metadata[:example_group][:example_group].should ==
|
139
|
+
nested_metadata[:example_group]
|
140
|
+
end
|
134
141
|
end
|
135
142
|
|
136
143
|
it "except for :example_group and modified keys," +
|
@@ -161,7 +168,6 @@ describe AMQP::SpecHelper, " .metadata" do
|
|
161
168
|
metadata.should_not have_key :example_key
|
162
169
|
metadata.should == deeply_nested_metadata
|
163
170
|
end
|
164
|
-
end
|
171
|
+
end # inside deeply nested example group 2
|
165
172
|
end # inside nested example group 2
|
166
|
-
|
167
173
|
end # describe AMQP, "metadata"
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 3
|
8
|
-
-
|
9
|
-
version: 0.3.
|
8
|
+
- 3
|
9
|
+
version: 0.3.3
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Arvicco
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-11-
|
17
|
+
date: 2010-11-24 00:00:00 +03:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|