amqp-spec 0.1.13 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY +4 -0
- data/VERSION +1 -1
- data/lib/amqp-spec/rspec.rb +26 -9
- data/spec/failing_rspec_spec.rb +10 -4
- data/spec/problematic_rspec_spec.rb +1 -1
- data/spec/rspec_amqp_spec.rb +10 -10
- data/spec/rspec_em_spec.rb +2 -2
- data/spec/shared_examples.rb +40 -43
- data/spec/spec_helper.rb +7 -6
- data/tasks/spec.rake +3 -7
- metadata +5 -5
data/HISTORY
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/lib/amqp-spec/rspec.rb
CHANGED
@@ -55,25 +55,42 @@ module AMQP
|
|
55
55
|
SpecTimeoutExceededError = Class.new(RuntimeError)
|
56
56
|
|
57
57
|
def self.included(example_group)
|
58
|
-
|
59
|
-
|
58
|
+
# unless defined? self.default_timeout
|
59
|
+
if defined?(RSpec)
|
60
|
+
example_group.instance_exec do
|
60
61
|
|
62
|
+
metadata[:em_default_options] = {}
|
63
|
+
metadata[:em_default_timeout] = nil
|
64
|
+
|
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
|
69
|
+
|
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
|
61
77
|
@@_em_default_options = {}
|
62
78
|
@@_em_default_timeout = nil
|
63
79
|
|
64
|
-
def self.
|
80
|
+
def self.default_timeout(spec_timeout=nil)
|
65
81
|
@@_em_default_timeout = spec_timeout if spec_timeout
|
66
82
|
@@_em_default_timeout
|
67
83
|
end
|
68
84
|
|
69
|
-
alias default_timeout default_spec_timeout
|
70
|
-
|
71
85
|
def self.default_options(opts=nil)
|
72
86
|
@@_em_default_options = opts if opts
|
73
87
|
@@_em_default_options
|
74
88
|
end
|
75
89
|
end
|
90
|
+
|
91
|
+
# end
|
76
92
|
end
|
93
|
+
|
77
94
|
end
|
78
95
|
|
79
96
|
# Yields to given block inside EM.run and AMQP.start loops. This method takes any option that is
|
@@ -88,12 +105,12 @@ module AMQP
|
|
88
105
|
# if something goes wrong and EM/AMQP loop hangs for some reason. SpecTimeoutExceededError is raised.
|
89
106
|
#
|
90
107
|
def amqp opts={}, &block
|
91
|
-
opts =
|
108
|
+
opts = self.class.default_options.merge opts
|
92
109
|
begin
|
93
110
|
EM.run do
|
94
111
|
@_em_spec_with_amqp = true
|
95
112
|
@_em_spec_exception = nil
|
96
|
-
spec_timeout = opts.delete(:spec_timeout) ||
|
113
|
+
spec_timeout = opts.delete(:spec_timeout) || self.class.default_timeout
|
97
114
|
timeout(spec_timeout) if spec_timeout
|
98
115
|
@_em_spec_fiber = Fiber.new do
|
99
116
|
begin
|
@@ -117,8 +134,8 @@ module AMQP
|
|
117
134
|
|
118
135
|
# Yields to block inside EM loop, :spec_timeout option (in seconds) is used to force spec to timeout
|
119
136
|
# if something goes wrong and EM/AMQP loop hangs for some reason. SpecTimeoutExceededError is raised.
|
120
|
-
def em(spec_timeout =
|
121
|
-
spec_timeout = spec_timeout[:spec_timeout] ||
|
137
|
+
def em(spec_timeout = self.class.default_timeout, &block)
|
138
|
+
spec_timeout = spec_timeout[:spec_timeout] || self.class.default_timeout if spec_timeout.is_a?(Hash)
|
122
139
|
EM.run do
|
123
140
|
@_em_spec_with_amqp = false
|
124
141
|
@_em_spec_exception = nil
|
data/spec/failing_rspec_spec.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
|
-
|
3
|
+
describe 'Following examples should all be failing:' do
|
4
4
|
describe EventMachine, " when running failing examples" do
|
5
5
|
include AMQP::EMSpec
|
6
6
|
|
@@ -17,8 +17,12 @@ context 'Following examples should all be failing:' do
|
|
17
17
|
end
|
18
18
|
|
19
19
|
describe EventMachine, " when testing with AMQP::EMSpec with a maximum execution time per test" do
|
20
|
-
|
21
20
|
include AMQP::EMSpec
|
21
|
+
|
22
|
+
# For RSpec 1, default_timeout and default_options are global
|
23
|
+
# For RSpec 2, default_timeout and default_options are example-group local, inheritable by nested groups
|
24
|
+
default_timeout 1
|
25
|
+
|
22
26
|
it 'should timeout before reaching done' do
|
23
27
|
EM.add_timer(2) { done }
|
24
28
|
end
|
@@ -33,7 +37,9 @@ context 'Following examples should all be failing:' do
|
|
33
37
|
|
34
38
|
include AMQP::Spec
|
35
39
|
|
36
|
-
|
40
|
+
# For RSpec 1, default_timeout and default_options are global
|
41
|
+
# For RSpec 2, default_timeout and default_options are example-group local, inheritable by nested groups
|
42
|
+
default_timeout 1
|
37
43
|
|
38
44
|
it 'should timeout before reaching done' do
|
39
45
|
EM.add_timer(2) { done }
|
data/spec/rspec_amqp_spec.rb
CHANGED
@@ -1,11 +1,5 @@
|
|
1
1
|
require_relative 'spec_helper.rb'
|
2
2
|
|
3
|
-
describe 'Rspec' do
|
4
|
-
it 'should work as normal without AMQP-Spec' do
|
5
|
-
1.should == 1
|
6
|
-
end
|
7
|
-
end
|
8
|
-
|
9
3
|
def publish_and_consume_once(queue_name="test_sink", data="data")
|
10
4
|
amqp do
|
11
5
|
q = MQ.queue(queue_name)
|
@@ -20,7 +14,13 @@ def publish_and_consume_once(queue_name="test_sink", data="data")
|
|
20
14
|
end
|
21
15
|
end
|
22
16
|
|
23
|
-
|
17
|
+
describe RSPEC do
|
18
|
+
it 'should work as normal without AMQP-Spec' do
|
19
|
+
1.should == 1
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe 'Evented AMQP specs' do
|
24
24
|
describe AMQP, " when testing with AMQP::SpecHelper" do
|
25
25
|
include AMQP::SpecHelper
|
26
26
|
|
@@ -55,7 +55,7 @@ context 'Evented AMQP specs' do
|
|
55
55
|
amqp do
|
56
56
|
:this.should == :fail
|
57
57
|
end
|
58
|
-
}.to raise_error
|
58
|
+
}.to raise_error RSPEC::Expectations::ExpectationNotMetError
|
59
59
|
AMQP.conn.should == nil
|
60
60
|
end
|
61
61
|
|
@@ -65,7 +65,7 @@ context 'Evented AMQP specs' do
|
|
65
65
|
done
|
66
66
|
:this.should == :fail
|
67
67
|
end
|
68
|
-
}.to raise_error
|
68
|
+
}.to raise_error RSPEC::Expectations::ExpectationNotMetError
|
69
69
|
AMQP.conn.should == nil
|
70
70
|
end
|
71
71
|
|
@@ -91,7 +91,7 @@ context 'Evented AMQP specs' do
|
|
91
91
|
end
|
92
92
|
end
|
93
93
|
|
94
|
-
describe
|
94
|
+
describe RSPEC, " when running an example group after another group that uses AMQP-Spec " do
|
95
95
|
it "should work normally" do
|
96
96
|
:does_not_hang.should_not be_false
|
97
97
|
end
|
data/spec/rspec_em_spec.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require_relative 'spec_helper.rb'
|
2
2
|
|
3
|
-
|
3
|
+
describe 'Plain EM, no AMQP' do
|
4
4
|
describe EventMachine, " when testing with AMQP::SpecHelper" do
|
5
5
|
include AMQP::SpecHelper
|
6
6
|
|
@@ -46,7 +46,7 @@ context 'Plain EM, no AMQP' do
|
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
|
-
describe
|
49
|
+
describe RSPEC, " when running an example group after groups that uses EM specs " do
|
50
50
|
it "should work normally" do
|
51
51
|
:does_not_hang.should_not be_false
|
52
52
|
end
|
data/spec/shared_examples.rb
CHANGED
@@ -61,48 +61,6 @@ shared_examples_for 'SpecHelper examples' do
|
|
61
61
|
it_should_behave_like 'timeout examples'
|
62
62
|
end
|
63
63
|
|
64
|
-
shared_examples_for 'Spec examples' do
|
65
|
-
after do
|
66
|
-
EM.reactor_running?.should == true
|
67
|
-
# AMQP.conn.should be_nil # You're inside running amqp block, stupid!
|
68
|
-
done
|
69
|
-
end
|
70
|
-
|
71
|
-
it 'should work' do
|
72
|
-
done
|
73
|
-
end
|
74
|
-
|
75
|
-
it 'should have timers' do
|
76
|
-
start = Time.now
|
77
|
-
|
78
|
-
EM.add_timer(0.5) {
|
79
|
-
(Time.now-start).should be_close(0.5, 0.1)
|
80
|
-
done
|
81
|
-
}
|
82
|
-
end
|
83
|
-
|
84
|
-
it 'should have periodic timers' do
|
85
|
-
num = 0
|
86
|
-
start = Time.now
|
87
|
-
|
88
|
-
timer = EM.add_periodic_timer(0.25) {
|
89
|
-
if (num += 1) == 2
|
90
|
-
(Time.now-start).should be_close(0.5, 0.1)
|
91
|
-
EM.cancel_timer timer
|
92
|
-
done
|
93
|
-
end
|
94
|
-
}
|
95
|
-
end
|
96
|
-
|
97
|
-
it 'should have deferrables' do
|
98
|
-
defr = EM::DefaultDeferrable.new
|
99
|
-
defr.timeout(0.5)
|
100
|
-
defr.errback {
|
101
|
-
done
|
102
|
-
}
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
64
|
shared_examples_for 'done examples' do
|
107
65
|
|
108
66
|
it 'should yield to block given to done (when amqp is used)' do
|
@@ -138,7 +96,6 @@ shared_examples_for 'done examples' do
|
|
138
96
|
end
|
139
97
|
end
|
140
98
|
|
141
|
-
|
142
99
|
shared_examples_for 'timeout examples' do
|
143
100
|
before { @start = Time.now }
|
144
101
|
|
@@ -175,4 +132,44 @@ shared_examples_for 'timeout examples' do
|
|
175
132
|
end
|
176
133
|
end
|
177
134
|
|
135
|
+
shared_examples_for 'Spec examples' do
|
136
|
+
after do
|
137
|
+
EM.reactor_running?.should == true
|
138
|
+
# AMQP.conn.should be_nil # You're inside running amqp block, stupid!
|
139
|
+
done
|
140
|
+
end
|
141
|
+
|
142
|
+
it 'should work' do
|
143
|
+
done
|
144
|
+
end
|
145
|
+
|
146
|
+
it 'should have timers' do
|
147
|
+
start = Time.now
|
148
|
+
|
149
|
+
EM.add_timer(0.25) {
|
150
|
+
(Time.now-start).should be_close(0.25, 0.1)
|
151
|
+
done
|
152
|
+
}
|
153
|
+
end
|
154
|
+
|
155
|
+
it 'should have periodic timers' do
|
156
|
+
num = 0
|
157
|
+
start = Time.now
|
178
158
|
|
159
|
+
timer = EM.add_periodic_timer(0.25) {
|
160
|
+
if (num += 1) == 2
|
161
|
+
(Time.now-start).should be_close(0.5, 0.1)
|
162
|
+
EM.cancel_timer timer
|
163
|
+
done
|
164
|
+
end
|
165
|
+
}
|
166
|
+
end
|
167
|
+
|
168
|
+
it 'should have deferrables' do
|
169
|
+
defr = EM::DefaultDeferrable.new
|
170
|
+
defr.timeout(0.25)
|
171
|
+
defr.errback {
|
172
|
+
done
|
173
|
+
}
|
174
|
+
end
|
175
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,17 +1,18 @@
|
|
1
|
-
#$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
-
|
3
1
|
$LOAD_PATH << "." unless $LOAD_PATH.include? "." # moronic 1.9.2 breaks things bad
|
4
2
|
|
5
|
-
require '
|
6
|
-
|
3
|
+
require 'bundler'
|
4
|
+
Bundler.setup
|
5
|
+
Bundler.require :test
|
7
6
|
|
7
|
+
require 'yaml'
|
8
8
|
require 'amqp-spec/rspec'
|
9
9
|
require 'shared_examples'
|
10
|
-
|
10
|
+
|
11
|
+
RSPEC = defined?(RSpec) ? RSpec : Spec
|
11
12
|
|
12
13
|
amqp_config = File.dirname(__FILE__) + '/amqp.yml'
|
13
|
-
if File.exists? amqp_config
|
14
14
|
|
15
|
+
if File.exists? amqp_config
|
15
16
|
class Hash
|
16
17
|
def symbolize_keys
|
17
18
|
self.inject({}) { |result, (key, value)|
|
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-spec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
version: 0.2.0
|
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
|