em-rspec 0.1 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +37 -0
- data/lib/patch.rb +3 -1
- metadata +34 -43
data/README.md
CHANGED
@@ -0,0 +1,37 @@
|
|
1
|
+
# em-rspec
|
2
|
+
|
3
|
+
em-rspec is a very simple patch to RSpec 2 that sets up and tears down an EventMachine reactor loop, and runs each example within the context of the loop.
|
4
|
+
It also will wrap each example in a [Fiber](http://ruby-doc.org/core-1.9/classes/Fiber.html) so you are free to untangle nested callbacks.
|
5
|
+
|
6
|
+
# Usage
|
7
|
+
|
8
|
+
`gem install em-rspec`
|
9
|
+
|
10
|
+
`require 'em-rspec'`
|
11
|
+
|
12
|
+
em-rspec extends RSpec in an unobtrusive way that requires no addtional code in your specs to test EM code. e.g.
|
13
|
+
|
14
|
+
<pre>describe 'em-rspec' do
|
15
|
+
it 'executes specs within a reactor loop' do
|
16
|
+
EM.reactor_running?.should be_true # This is true
|
17
|
+
end
|
18
|
+
end</pre>
|
19
|
+
|
20
|
+
# How it works
|
21
|
+
|
22
|
+
As mentioned before, before the spec is run, a reactor loop is setup, and a callback to teardown the loop when your example finishes execution is created.
|
23
|
+
This is an important point to consider because if you do any asynchronous i/o operations, your code will not be tested, because your code will likely have
|
24
|
+
finished execution before the i/o operation is complete. It is an antipattern to actually hit the network in your tests and what you should do is mock out
|
25
|
+
i/o calls to return immediately, e.g. http calls with [webmock](https://github.com/bblimke/webmock).
|
26
|
+
|
27
|
+
This is how your examples are run with em-rspec:
|
28
|
+
|
29
|
+
- Set up reactor loop
|
30
|
+
- Set callback to tear down reactor loop when spec is finished
|
31
|
+
- Wrap example in fiber
|
32
|
+
- Run before each block
|
33
|
+
- Run example
|
34
|
+
- Run after each block
|
35
|
+
- Tear down reactor loop
|
36
|
+
|
37
|
+
© 2011 Stevie Graham
|
data/lib/patch.rb
CHANGED
@@ -12,8 +12,10 @@ RSpec::Core::Example.class_eval do
|
|
12
12
|
def run(example_group_instance, reporter)
|
13
13
|
Fiber.new do
|
14
14
|
EM.run do
|
15
|
-
|
15
|
+
df = EM::DefaultDeferrable.new
|
16
|
+
df.callback { |x| EM.stop }
|
16
17
|
ignorant_run example_group_instance, reporter
|
18
|
+
df.succeed
|
17
19
|
end
|
18
20
|
end.resume
|
19
21
|
end
|
metadata
CHANGED
@@ -1,79 +1,70 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: em-rspec
|
3
|
-
version: !ruby/object:Gem::Version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
4
5
|
prerelease:
|
5
|
-
version: "0.1"
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
7
|
+
authors:
|
8
8
|
- Stevie Graham
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
dependencies:
|
16
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2012-07-13 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
17
15
|
name: eventmachine
|
18
|
-
|
19
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: &70187642950260 !ruby/object:Gem::Requirement
|
20
17
|
none: false
|
21
|
-
requirements:
|
22
|
-
- -
|
23
|
-
- !ruby/object:Gem::Version
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
24
21
|
version: 0.12.10
|
25
22
|
type: :runtime
|
26
|
-
version_requirements: *id001
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: rspec
|
29
23
|
prerelease: false
|
30
|
-
|
24
|
+
version_requirements: *70187642950260
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rspec
|
27
|
+
requirement: &70187642949580 !ruby/object:Gem::Requirement
|
31
28
|
none: false
|
32
|
-
requirements:
|
33
|
-
- -
|
34
|
-
- !ruby/object:Gem::Version
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
35
32
|
version: 2.5.0
|
36
33
|
type: :development
|
37
|
-
|
38
|
-
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70187642949580
|
36
|
+
description: ! 'Test EventMachine code in RSpec 2 '
|
39
37
|
email: sjtgraham@mac.com
|
40
38
|
executables: []
|
41
|
-
|
42
39
|
extensions: []
|
43
|
-
|
44
40
|
extra_rdoc_files: []
|
45
|
-
|
46
|
-
files:
|
41
|
+
files:
|
47
42
|
- README.md
|
48
43
|
- lib/em-rspec.rb
|
49
44
|
- lib/patch.rb
|
50
|
-
has_rdoc: true
|
51
45
|
homepage: http://github.com/stevegraham/em-rspec
|
52
46
|
licenses: []
|
53
|
-
|
54
47
|
post_install_message:
|
55
48
|
rdoc_options: []
|
56
|
-
|
57
|
-
require_paths:
|
49
|
+
require_paths:
|
58
50
|
- lib
|
59
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
52
|
none: false
|
61
|
-
requirements:
|
62
|
-
- -
|
63
|
-
- !ruby/object:Gem::Version
|
53
|
+
requirements:
|
54
|
+
- - ! '>='
|
55
|
+
- !ruby/object:Gem::Version
|
64
56
|
version: 1.9.1
|
65
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
58
|
none: false
|
67
|
-
requirements:
|
68
|
-
- -
|
69
|
-
- !ruby/object:Gem::Version
|
70
|
-
version:
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
71
63
|
requirements: []
|
72
|
-
|
73
64
|
rubyforge_project:
|
74
|
-
rubygems_version: 1.
|
65
|
+
rubygems_version: 1.8.16
|
75
66
|
signing_key:
|
76
67
|
specification_version: 3
|
77
68
|
summary: Test EventMachine code in RSpec 2
|
78
69
|
test_files: []
|
79
|
-
|
70
|
+
has_rdoc:
|