amqp-spec 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
data/HISTORY CHANGED
@@ -61,3 +61,7 @@
61
61
  == 0.3.1 / 2010-11-17
62
62
 
63
63
  * Documentation cleanup
64
+
65
+ == 0.3.2 / 2010-11-23
66
+
67
+ * EM hooks now working as they should - bugs fixed
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.1
1
+ 0.3.2
@@ -46,9 +46,10 @@ module AMQP
46
46
 
47
47
  # Runs hooks of specified type (hopefully, inside the event loop)
48
48
  #
49
- def run_hooks type
50
- hooks = @example_group_instance.class.em_hooks[type]
49
+ def run_em_hooks type
50
+ hooks = @example_group_instance.class.all_hooks type
51
51
  (:before == type ? hooks : hooks.reverse).each do |hook|
52
+ # @example_group_instance.class.all_hooks(type).each do |hook|
52
53
  if @example_group_instance.respond_to? :instance_eval_without_event_loop
53
54
  @example_group_instance.instance_eval_without_event_loop(&hook)
54
55
  else
@@ -64,7 +65,7 @@ module AMQP
64
65
  def run_em_loop
65
66
  begin
66
67
  EM.run do
67
- run_hooks :before
68
+ run_em_hooks :before
68
69
 
69
70
  @spec_exception = nil
70
71
  timeout(@opts[:spec_timeout]) if @opts[:spec_timeout]
@@ -77,7 +78,7 @@ module AMQP
77
78
  end
78
79
  rescue Exception => @spec_exception
79
80
  # p "Outside loop, caught #{@spec_exception}"
80
- run_hooks :after # Event loop was broken, but we still need to run em_after hooks
81
+ run_em_hooks :after # Event loop was broken, but we still need to run em_after hooks
81
82
  ensure
82
83
  finish_example
83
84
  end
@@ -86,7 +87,7 @@ module AMQP
86
87
  # Stops EM event loop. It is called from #done
87
88
  #
88
89
  def finish_em_loop
89
- run_hooks :after
90
+ run_em_hooks :after
90
91
  EM.stop_event_loop if EM.reactor_running?
91
92
  end
92
93
 
@@ -94,6 +95,7 @@ module AMQP
94
95
  # Descendant classes may redefine to clean up type-specific state.
95
96
  #
96
97
  def finish_example
98
+ # p @spec_exception if @spec_exception
97
99
  raise @spec_exception if @spec_exception
98
100
  end
99
101
 
@@ -1,5 +1,5 @@
1
- require 'amqp-spec/amqp'
2
- require 'amqp-spec/evented_example'
1
+ require_relative 'amqp'
2
+ require_relative 'evented_example'
3
3
 
4
4
  # You can include one of the following modules into your example groups:
5
5
  # AMQP::SpecHelper,
@@ -80,8 +80,30 @@ module AMQP
80
80
 
81
81
  # Collection of evented hooks
82
82
  def em_hooks
83
- metadata[:em_hooks] ||= {:before => [], :after => []}
83
+ metadata[:em_hooks] ||= {}
84
+ metadata[:em_hooks][self] ||= {:before => [], :after => []}
85
+ # p "#{self} < #{superclass}", em_metadata[:em_hooks].keys
86
+ metadata[:em_hooks][self]
84
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
+
85
107
  end
86
108
 
87
109
  def self.included example_group
@@ -92,6 +114,12 @@ module AMQP
92
114
  end
93
115
  end
94
116
 
117
+ # Retrieves metadata passed in from enclosing example groups
118
+ #
119
+ def metadata
120
+ @em_metadata ||= self.class.metadata.dup rescue {}
121
+ end
122
+
95
123
  # Yields to a given block inside EM.run and AMQP.start loops. This method takes
96
124
  # any option that is accepted by EventMachine::connect. Options for AMQP.start include:
97
125
  # * :user => String (default ‘guest’) - Username as defined by the AMQP server.
@@ -0,0 +1,89 @@
1
+ require 'spec_helper'
2
+
3
+ describe AMQP::SpecHelper, " .default_options" do
4
+ include AMQP::SpecHelper
5
+ root_default_options = {:one => 1}
6
+ default_options root_default_options
7
+
8
+ it 'example has access to default options through self.class.default_options' do
9
+ self.class.default_options.should == root_default_options
10
+ end
11
+
12
+ context 'inside nested example group 1' do
13
+ it 'defaults start as a copy of enclosing example group default_options' do
14
+ self.class.default_options.should == root_default_options
15
+ end
16
+
17
+ it 'can be changed, thus diverging from example group default_options' do
18
+ self.class.default_options[:example_key] = :example_value
19
+ self.class.default_options.should have_key :example_key
20
+ self.class.default_options.should_not == root_default_options
21
+ end
22
+
23
+ it 'changing example default_options has no effect on subsequent examples' do
24
+ self.class.default_options.should == root_default_options
25
+ end
26
+
27
+ context 'inside deeply nested example group 1' do
28
+ it 'example default_options starts as a copy of enclosing example group default_options' do
29
+ default_options.should == root_default_options
30
+ end
31
+
32
+ it 'can be changed, thus diverging from example group default_options' do
33
+ self.class.default_options[:example_key] = :example_value
34
+ self.class.default_options.should have_key :example_key
35
+ self.class.default_options.should_not == root_default_options
36
+ end
37
+
38
+ it 'changing example default_options has no effect on subsequent examples' do
39
+ self.class.default_options.should_not have_key :example_key
40
+ self.class.default_options.should == root_default_options
41
+ end
42
+ end
43
+ end # inside nested example group 1
44
+
45
+ context 'inside nested example group 2' do
46
+ default_options[:nested_key] = :nested_value
47
+ nested_default_options = default_options
48
+
49
+ it 'changing default_options in nested group affects example group default_options' do
50
+ default_options.should == nested_default_options
51
+ default_options.should_not == root_default_options
52
+ end
53
+
54
+ it 'can be changed, thus diverging from example group default_options' do
55
+ default_options[:example_key] = :example_value
56
+ default_options.should have_key :example_key
57
+ default_options.should_not == nested_default_options
58
+ default_options.should_not == root_default_options
59
+ end
60
+
61
+ it 'changing example default_options has no effect on subsequent examples' do
62
+ default_options.should == nested_default_options
63
+ end
64
+
65
+ context 'inside deeply nested example group 2' do
66
+ default_options[:deeply_nested_key] = :deeply_nested_value
67
+ deeply_nested_default_options = default_options
68
+
69
+ it 'changing default_options in nested group affects example group default_options' do
70
+ default_options.should == deeply_nested_default_options
71
+ default_options.should_not == nested_default_options
72
+ default_options.should_not == root_default_options
73
+ default_options.should have_key :deeply_nested_key
74
+ end
75
+
76
+ it 'can be changed, thus diverging from example group default_options' do
77
+ default_options[:example_key] = :example_value
78
+ default_options.should have_key :example_key
79
+ default_options.should_not == nested_default_options
80
+ default_options.should_not == root_default_options
81
+ end
82
+
83
+ it 'changing example default_options has no effect on subsequent examples' do
84
+ default_options.should == deeply_nested_default_options
85
+ end
86
+ end
87
+ end # inside nested example group 2
88
+
89
+ end # describe AMQP, "default_options"
@@ -10,6 +10,7 @@ shared_examples_for 'hooked em specs' do
10
10
  end
11
11
 
12
12
  it 'should execute em_after if business exception is raised' do
13
+ # Expectation is set in after{} hook
13
14
  em do
14
15
  expect {
15
16
  raise StandardError
@@ -19,6 +20,7 @@ shared_examples_for 'hooked em specs' do
19
20
  end
20
21
 
21
22
  it 'should execute em_after if RSpec expectation fails' do
23
+ # Expectation is set in after{} hook
22
24
  em do
23
25
  expect { :this.should == :fail
24
26
  }.to raise_error RSPEC::Expectations::ExpectationNotMetError
@@ -37,6 +39,7 @@ shared_examples_for 'hooked amqp specs' do
37
39
  end
38
40
 
39
41
  it 'should execute em_after if business exception is raised' do
42
+ # Expectation is set in after{} hook
40
43
  amqp do
41
44
  expect {
42
45
  raise StandardError
@@ -46,6 +49,7 @@ shared_examples_for 'hooked amqp specs' do
46
49
  end
47
50
 
48
51
  it 'should execute em_after if RSpec expectation fails' do
52
+ # Expectation is set in after{} hook
49
53
  amqp do
50
54
  expect { :this.should == :fail
51
55
  }.to raise_error RSPEC::Expectations::ExpectationNotMetError
@@ -92,6 +96,21 @@ describe AMQP, " with em_before/em_after" do
92
96
 
93
97
  it_should_behave_like 'hooked em specs'
94
98
 
99
+ it 'should not run nested em hooks' do
100
+ em do
101
+ @hooks_called.should_not include :context_em_before, :context_before
102
+ done
103
+ end
104
+ end
105
+
106
+ it 'should not run hooks from unrelated group' do
107
+ em do
108
+ @hooks_called.should_not include :amqp_context_em_before,
109
+ :amqp_context_before
110
+ done
111
+ end
112
+ end
113
+
95
114
  context 'inside nested example group' do
96
115
  before { @hooks_called << :context_before }
97
116
  em_before { @hooks_called << :context_em_before }
@@ -104,6 +123,8 @@ describe AMQP, " with em_before/em_after" do
104
123
  :context_em_after,
105
124
  :em_after }
106
125
 
126
+ it_should_behave_like 'hooked em specs'
127
+
107
128
  it 'should fire both nested :before hooks' do
108
129
  em do
109
130
  @hooks_called.should include :before,
@@ -115,8 +136,6 @@ describe AMQP, " with em_before/em_after" do
115
136
  end
116
137
  end
117
138
 
118
- it_should_behave_like 'hooked em specs'
119
-
120
139
  end # context 'inside nested example group'
121
140
  end # context 'with em block'
122
141
 
@@ -124,31 +143,45 @@ describe AMQP, " with em_before/em_after" do
124
143
 
125
144
  it_should_behave_like 'hooked amqp specs'
126
145
 
146
+ it 'should not run nested em hooks' do
147
+ amqp do
148
+ @hooks_called.should_not include :amqp_context_em_before,
149
+ :amqp_context_before
150
+ done
151
+ end
152
+ end
153
+
154
+ it 'should not run hooks from unrelated group' do
155
+ amqp do
156
+ @hooks_called.should_not include :context_em_before, :context_before
157
+ done
158
+ end
159
+ end
160
+
127
161
  context 'inside nested example group' do
128
- before { @hooks_called << :context_before }
129
- em_before { @hooks_called << :context_em_before }
130
- em_after { @hooks_called << :context_em_after }
162
+ before { @hooks_called << :amqp_context_before }
163
+ em_before { @hooks_called << :amqp_context_em_before }
164
+ em_after { @hooks_called << :amqp_context_em_after }
131
165
 
132
- after { @hooks_called.should include :before,
133
- :context_before,
134
- :em_before,
135
- :context_em_before,
136
- :context_em_after,
137
- :em_after }
166
+ after { @hooks_called.should == [:before,
167
+ :amqp_context_before,
168
+ :em_before,
169
+ :amqp_context_em_before,
170
+ :amqp_context_em_after,
171
+ :em_after] }
138
172
 
139
- it 'should fire both nested :before hooks' do
173
+ it_should_behave_like 'hooked amqp specs'
174
+
175
+ it 'should fire all :before hooks in correct order' do
140
176
  amqp do
141
- @hooks_called.should include :before,
142
- :context_before,
143
- :em_before,
144
- :context_em_before
145
- @hooks_called.should_not include :em_after, :context_em_after
177
+ @hooks_called.should == [:before,
178
+ :amqp_context_before,
179
+ :em_before,
180
+ :amqp_context_em_before]
146
181
  done
147
182
  end
148
183
  end
149
184
 
150
- it_should_behave_like 'hooked amqp specs'
151
-
152
185
  end # context 'inside nested example group'
153
186
  end # context 'with amqp block'
154
187
  end # context 'for evented specs'
@@ -0,0 +1,167 @@
1
+ require 'spec_helper'
2
+
3
+ describe AMQP::SpecHelper, " .metadata" do
4
+ include AMQP::SpecHelper
5
+ root_metadata = metadata
6
+
7
+ it 'example metadata starts as a copy of example group metadata' do
8
+ metadata.should == root_metadata
9
+ end
10
+
11
+ it 'can be changed, thus diverging from example group metadata' do
12
+ metadata[:example_key] = :example_value
13
+ metadata.should have_key :example_key
14
+ metadata.should_not == root_metadata
15
+ end
16
+
17
+ it 'changing example metadata has no effect on subsequent examples' do
18
+ metadata.should_not have_key :example_key
19
+ metadata.should == root_metadata
20
+ end
21
+
22
+ context 'inside nested example group 1' do
23
+ nested_metadata = metadata
24
+
25
+ it 'nested group metadata CONTAINS root enclosing group metadata' do
26
+ nested_metadata.should_not == root_metadata
27
+ nested_metadata[:example_group][:example_group].should ==
28
+ root_metadata[:example_group]
29
+ end
30
+
31
+ it 'except for :example_group key, nested and root group metadata is the same' do
32
+ @root = root_metadata.dup
33
+ @root.delete(:example_group)
34
+ @nested = nested_metadata.dup
35
+ @nested.delete(:example_group)
36
+ @nested.should == @root
37
+ end
38
+
39
+ it 'example metadata starts as a copy of nested group metadata' do
40
+ metadata.should == nested_metadata
41
+ end
42
+
43
+ it 'can be changed, thus diverging from example group metadata' do
44
+ metadata[:example_key] = :example_value
45
+ metadata.should have_key :example_key
46
+ metadata.should_not == nested_metadata
47
+ end
48
+
49
+ it 'changing example metadata has no effect on subsequent examples' do
50
+ metadata.should_not have_key :example_key
51
+ metadata.should == nested_metadata
52
+ end
53
+
54
+ context 'inside deeply nested example group 1' do
55
+ deeply_nested_metadata = metadata
56
+
57
+ it 'deeply_nested group metadata CONTAINS enclosing group metadata' do
58
+ deeply_nested_metadata.should_not == root_metadata
59
+ deeply_nested_metadata[:example_group][:example_group].should ==
60
+ nested_metadata[:example_group]
61
+ end
62
+
63
+ it 'except for :example_group key, deeply_nested and root group metadata is the same' do
64
+ @root = root_metadata.dup
65
+ @root.delete(:example_group)
66
+ @nested = nested_metadata.dup
67
+ @nested.delete(:example_group)
68
+ @deeply_nested = deeply_nested_metadata.dup
69
+ @deeply_nested.delete(:example_group)
70
+ @deeply_nested.should == @nested
71
+ @deeply_nested.should == @root
72
+ end
73
+
74
+ it 'example metadata starts as a copy of deeply_nested group metadata' do
75
+ metadata.should == deeply_nested_metadata
76
+ end
77
+
78
+ it 'can be changed, thus diverging from example group metadata' do
79
+ metadata[:example_key] = :example_value
80
+ metadata.should have_key :example_key
81
+ metadata.should_not == deeply_nested_metadata
82
+ end
83
+
84
+ it 'changing example metadata has no effect on subsequent examples' do
85
+ metadata.should_not have_key :example_key
86
+ metadata.should == deeply_nested_metadata
87
+ end
88
+
89
+ end
90
+ end # inside nested example group 1
91
+
92
+ context 'inside nested example group 2' do
93
+ metadata[:nested_key] = :nested_value
94
+ nested_metadata = metadata
95
+
96
+ it 'nested group metadata CONTAINS root enclosing group metadata' do
97
+ nested_metadata.should_not == root_metadata
98
+ nested_metadata[:example_group][:example_group].should ==
99
+ root_metadata[:example_group]
100
+ end
101
+
102
+ it "except for :example_group and modified keys," +
103
+ "nested and root group metadata is the same" do
104
+ @root = root_metadata.dup
105
+ @root.delete(:example_group)
106
+ @nested = nested_metadata.dup
107
+ @nested.delete(:example_group)
108
+ @nested.delete(:nested_key)
109
+ @nested.should == @root
110
+ end
111
+
112
+ it 'example metadata starts as a copy of nested group metadata' do
113
+ metadata.should == nested_metadata
114
+ end
115
+
116
+ it 'can be changed, thus diverging from example group metadata' do
117
+ metadata[:example_key] = :example_value
118
+ metadata.should have_key :example_key
119
+ metadata.should_not == nested_metadata
120
+ end
121
+
122
+ it 'changing example metadata has no effect on subsequent examples' do
123
+ metadata.should_not have_key :example_key
124
+ metadata.should == nested_metadata
125
+ end
126
+
127
+ context 'inside deeply nested example group 1' do
128
+ metadata[:deeply_nested_key] = :deeply_nested_value
129
+ deeply_nested_metadata = metadata
130
+
131
+ it 'deeply_nested group metadata CONTAINS enclosing group metadata' do
132
+ deeply_nested_metadata[:example_group][:example_group].should ==
133
+ nested_metadata[:example_group]
134
+ end
135
+
136
+ it "except for :example_group and modified keys," +
137
+ "deeply nested and root group metadata is the same" do
138
+ @root = root_metadata.dup
139
+ @root.delete(:example_group)
140
+ @nested = nested_metadata.dup
141
+ @nested.delete(:example_group)
142
+ @deeply_nested = deeply_nested_metadata.dup
143
+ @deeply_nested.delete(:example_group)
144
+ @deeply_nested.delete(:deeply_nested_key)
145
+ @deeply_nested.should == @nested
146
+ @deeply_nested.delete(:nested_key)
147
+ @deeply_nested.should == @root
148
+ end
149
+
150
+ it 'example metadata starts as a copy of deeply_nested group metadata' do
151
+ metadata.should == deeply_nested_metadata
152
+ end
153
+
154
+ it 'can be changed, thus diverging from example group metadata' do
155
+ metadata[:example_key] = :example_value
156
+ metadata.should have_key :example_key
157
+ metadata.should_not == deeply_nested_metadata
158
+ end
159
+
160
+ it 'changing example metadata has no effect on subsequent examples' do
161
+ metadata.should_not have_key :example_key
162
+ metadata.should == deeply_nested_metadata
163
+ end
164
+ end
165
+ end # inside nested example group 2
166
+
167
+ 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
- - 1
9
- version: 0.3.1
8
+ - 2
9
+ version: 0.3.2
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 00:00:00 +03:00
17
+ date: 2010-11-23 00:00:00 +03:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -79,7 +79,9 @@ files:
79
79
  - lib/amqp-spec.rb
80
80
  - lib/version.rb
81
81
  - spec/amqp.yml
82
+ - spec/em_defaults_spec.rb
82
83
  - spec/em_hooks_spec.rb
84
+ - spec/em_metadata_spec.rb
83
85
  - spec/failing_rspec_spec.rb
84
86
  - spec/problematic_rspec_spec.rb
85
87
  - spec/rspec_amqp_spec.rb
@@ -138,7 +140,9 @@ specification_version: 3
138
140
  summary: Simple API for writing asynchronous EventMachine/AMQP specs. Supports RSpec and RSpec2.
139
141
  test_files:
140
142
  - spec/amqp.yml
143
+ - spec/em_defaults_spec.rb
141
144
  - spec/em_hooks_spec.rb
145
+ - spec/em_metadata_spec.rb
142
146
  - spec/failing_rspec_spec.rb
143
147
  - spec/problematic_rspec_spec.rb
144
148
  - spec/rspec_amqp_spec.rb