rspec-isolation 0.1.0 → 0.1.1
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/README.mkd +51 -53
- data/lib/rspec/isolation/version.rb +2 -2
- data/rspec-isolation.gemspec +6 -5
- metadata +9 -11
data/README.mkd
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
Running Your Test Cases in Isolation
|
2
2
|
====================================
|
3
3
|
|
4
|
-
The RSpec examples are generally run in a single ruby process. It dosen't matter until your code introduces some **global variables**, which would **be polluted between examples**. A common solution is to reset them in the
|
4
|
+
The RSpec examples are generally run in a single ruby process. It dosen't matter until your code introduces some **global variables**, which would **be polluted between examples**. A common solution is to reset them in the after hook, but it breaks the DRY rule and would brings a lots of extra works. The best way is to **run them in separated sub processes**. This gem would help you to achieve this within a single method call.
|
5
5
|
|
6
6
|
Dependency
|
7
7
|
----------
|
8
|
-
This gem
|
8
|
+
This gem depends on Rspec 2.0 and above. You should have it installed before using this gem.
|
9
9
|
|
10
10
|
Installation
|
11
11
|
------------
|
12
12
|
|
13
|
-
|
13
|
+
sudo gem install rspec-isolation
|
14
14
|
|
15
15
|
**Note:** The installation would NOT automatically install the rspec 2.0.
|
16
16
|
|
@@ -20,69 +20,67 @@ Image a spec file exists:
|
|
20
20
|
|
21
21
|
$greeting = "Hello, world!"
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
23
|
+
describe "Test with global vars" do
|
24
|
+
it "should be replaced with my name" do
|
25
|
+
$greeting.gsub!(/\bworld\b/, "Kevin")
|
26
|
+
$greeting.should == "Hello, Kevin!"
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should be replaced with my hometown name" do
|
30
|
+
$greeting.gsub!(/\bworld\b/, "Wuhan")
|
31
|
+
$greeting.should == "Hello, Wuhan!"
|
32
|
+
end
|
33
|
+
end
|
34
34
|
|
35
35
|
The `$greeting` is polluted in the first example and the second example would failed.
|
36
36
|
|
37
37
|
Now we require this gem:
|
38
38
|
|
39
|
-
|
39
|
+
require 'rspec/isolation'
|
40
40
|
|
41
41
|
Then you can choose one of the following ways to enable the isolation:
|
42
42
|
|
43
|
-
1. Using `iso_it
|
43
|
+
**1. Using `iso_it`:**
|
44
44
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
describe "Test with global vars" do
|
49
|
-
iso_it "should be replace with my name" do
|
50
|
-
$greeting.gsub!(/\bworld\b/, "Kevin")
|
51
|
-
$greeting.should == "Hello, Kevin!"
|
52
|
-
end
|
45
|
+
require 'rspec/isolation'
|
46
|
+
$greeting = "Hello, world!"
|
53
47
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
48
|
+
describe "Test with global vars" do
|
49
|
+
iso_it "should be replaced with my name" do
|
50
|
+
$greeting.gsub!(/\bworld\b/, "Kevin")
|
51
|
+
$greeting.should == "Hello, Kevin!"
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should be replaced with my hometown name" do
|
55
|
+
$greeting.gsub!(/\bworld\b/, "Wuhan")
|
56
|
+
$greeting.should == "Hello, Wuhan!"
|
57
|
+
end
|
58
|
+
end
|
59
59
|
|
60
|
-
|
60
|
+
Now the first example would be run in a sub process.
|
61
61
|
|
62
|
-
2. Using `run_in_isolation` in `before(:each)` hook
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
62
|
+
**2. Using `run_in_isolation` in `before(:each)` hook:**
|
63
|
+
|
64
|
+
require 'rspec/isolation'
|
65
|
+
$greeting = "Hello, world!"
|
66
|
+
|
67
|
+
describe "Test with global vars" do
|
68
|
+
before(:each) do
|
69
|
+
run_in_isolation
|
70
|
+
end
|
71
|
+
it "should be replaced with my name" do
|
72
|
+
$greeting.gsub!(/\bworld\b/, "Kevin")
|
73
|
+
$greeting.should == "Hello, Kevin!"
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should be replaced with my hometown name" do
|
77
|
+
$greeting.gsub!(/\bworld\b/, "Wuhan")
|
78
|
+
$greeting.should == "Hello, Wuhan!"
|
79
|
+
end
|
80
|
+
end
|
81
81
|
|
82
|
-
|
83
|
-
if you put `run_in_isolation` in a `before(:all)` hook.
|
82
|
+
Now all examples would be run in separated sub processes. **Note: It won't work if you put `run_in_isolation` in a `before(:all)` hook.**
|
84
83
|
|
85
84
|
Author
|
86
85
|
------
|
87
|
-
Kevin Fu, corntrace@gmail.com, @corntrace. If you like and use this gem, please feel free to give me any
|
88
|
-
recommandation.
|
86
|
+
Kevin Fu, corntrace@gmail.com, @corntrace. If you like and use this gem, please feel free to give me any recommandation.
|
data/rspec-isolation.gemspec
CHANGED
@@ -9,17 +9,18 @@ Gem::Specification.new do |s|
|
|
9
9
|
s.authors = ["Kevin Fu"]
|
10
10
|
s.email = ["corntrace@gmail.com"]
|
11
11
|
s.homepage = "http://rubygems.org/gems/rspec-isolation"
|
12
|
-
s.summary = "Make rspec examples
|
13
|
-
s.description = "Make rspec examples
|
12
|
+
s.summary = "Make rspec examples run in separated processes."
|
13
|
+
s.description = "Make rspec examples run in separated processes. \
|
14
14
|
Especially used in framework development."
|
15
15
|
|
16
16
|
s.required_rubygems_version = ">= 1.3.6"
|
17
17
|
|
18
|
-
s.add_development_dependency "bundler", ">= 1.0.
|
18
|
+
s.add_development_dependency "bundler", ">= 1.0.2"
|
19
|
+
s.add_development_dependency "rspec", ">=2.0.0"
|
19
20
|
|
20
21
|
s.files = `git ls-files`.split("\n")
|
21
22
|
s.executables = `git ls-files`.split("\n").select{|f| f =~ /^bin/}
|
22
23
|
s.require_path = 'lib'
|
23
24
|
|
24
|
-
s.add_dependency("rspec", ["~> 2.0.0"])
|
25
|
-
end
|
25
|
+
# s.add_dependency("rspec", ["~> 2.0.0"])
|
26
|
+
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 1
|
9
|
+
version: 0.1.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Kevin Fu
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-10-
|
17
|
+
date: 2010-10-17 00:00:00 +08:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -28,10 +28,8 @@ dependencies:
|
|
28
28
|
segments:
|
29
29
|
- 1
|
30
30
|
- 0
|
31
|
-
-
|
32
|
-
|
33
|
-
- 5
|
34
|
-
version: 1.0.0.rc.5
|
31
|
+
- 2
|
32
|
+
version: 1.0.2
|
35
33
|
type: :development
|
36
34
|
version_requirements: *id001
|
37
35
|
- !ruby/object:Gem::Dependency
|
@@ -40,16 +38,16 @@ dependencies:
|
|
40
38
|
requirement: &id002 !ruby/object:Gem::Requirement
|
41
39
|
none: false
|
42
40
|
requirements:
|
43
|
-
- -
|
41
|
+
- - ">="
|
44
42
|
- !ruby/object:Gem::Version
|
45
43
|
segments:
|
46
44
|
- 2
|
47
45
|
- 0
|
48
46
|
- 0
|
49
47
|
version: 2.0.0
|
50
|
-
type: :
|
48
|
+
type: :development
|
51
49
|
version_requirements: *id002
|
52
|
-
description: Make rspec examples
|
50
|
+
description: Make rspec examples run in separated processes. Especially used in framework development.
|
53
51
|
email:
|
54
52
|
- corntrace@gmail.com
|
55
53
|
executables: []
|
@@ -102,6 +100,6 @@ rubyforge_project:
|
|
102
100
|
rubygems_version: 1.3.7
|
103
101
|
signing_key:
|
104
102
|
specification_version: 3
|
105
|
-
summary: Make rspec examples
|
103
|
+
summary: Make rspec examples run in separated processes.
|
106
104
|
test_files: []
|
107
105
|
|