rspec_around_all 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.md +45 -0
- data/lib/rspec_around_all.rb +34 -0
- data/spec/rspec_around_all_spec.rb +94 -0
- metadata +67 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2012-2013 Myron Marston
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# RSpec Around All
|
2
|
+
|
3
|
+
Provides around(:all) hooks for RSpec.
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
In your Gemfile:
|
8
|
+
|
9
|
+
``` ruby
|
10
|
+
gem 'rspec_around_all', git: 'git://gist.github.com/2005175.git'
|
11
|
+
```
|
12
|
+
|
13
|
+
In a spec:
|
14
|
+
|
15
|
+
``` ruby
|
16
|
+
require 'rspec_around_all'
|
17
|
+
|
18
|
+
describe "MyClass" do
|
19
|
+
around(:all) do |group|
|
20
|
+
# do something before
|
21
|
+
group.run_examples
|
22
|
+
# do something after
|
23
|
+
end
|
24
|
+
|
25
|
+
# or...
|
26
|
+
around(:all) do |group|
|
27
|
+
transactionally(&group)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
```
|
31
|
+
|
32
|
+
See also the original [blog post](http://myronmars.to/n/dev-blog/2012/03/building-an-around-hook-using-fibers) about this.
|
33
|
+
|
34
|
+
## Contributing
|
35
|
+
|
36
|
+
* Fork the project
|
37
|
+
* Add tests
|
38
|
+
* Fix the issue / add the feature
|
39
|
+
* Submit pull request on github
|
40
|
+
|
41
|
+
## Copyright
|
42
|
+
|
43
|
+
Copyright (c) 2012-2013 Myron Marston. Released under the terms of the
|
44
|
+
MIT license. See LICENSE for details.
|
45
|
+
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'delegate'
|
2
|
+
require 'fiber'
|
3
|
+
|
4
|
+
module RSpecAroundAll
|
5
|
+
class FiberAwareGroup < SimpleDelegator
|
6
|
+
def run_examples
|
7
|
+
Fiber.yield
|
8
|
+
end
|
9
|
+
|
10
|
+
def to_proc
|
11
|
+
proc { run_examples }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def around(scope = :each, &block)
|
16
|
+
# let RSpec handle around(:each) hooks...
|
17
|
+
return super(scope, &block) unless scope == :all
|
18
|
+
|
19
|
+
group, fiber = self, nil
|
20
|
+
before(:all) do
|
21
|
+
fiber = Fiber.new(&block)
|
22
|
+
fiber.resume(FiberAwareGroup.new(group))
|
23
|
+
end
|
24
|
+
|
25
|
+
after(:all) do
|
26
|
+
fiber.resume
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
RSpec.configure do |c|
|
32
|
+
c.extend RSpecAroundAll
|
33
|
+
end
|
34
|
+
|
@@ -0,0 +1,94 @@
|
|
1
|
+
require_relative '../lib/rspec_around_all'
|
2
|
+
|
3
|
+
module RSpec
|
4
|
+
module Core
|
5
|
+
describe "around(:all) hook" do
|
6
|
+
it "runs the hook around all examples" do
|
7
|
+
order = []
|
8
|
+
|
9
|
+
group = ExampleGroup.describe "group" do
|
10
|
+
around(:all) do |g|
|
11
|
+
order << :before
|
12
|
+
g.run_examples
|
13
|
+
order << :after
|
14
|
+
end
|
15
|
+
specify { order << :e1 }
|
16
|
+
specify { order << :e2 }
|
17
|
+
end
|
18
|
+
|
19
|
+
group.run(double.as_null_object)
|
20
|
+
order.should eq([:before, :e1, :e2, :after])
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'allows the yielded arg to be treated as a proc' do
|
24
|
+
group = ExampleGroup.describe "group" do
|
25
|
+
def self.order
|
26
|
+
@order ||= []
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.transactionally
|
30
|
+
order << :before
|
31
|
+
yield
|
32
|
+
order << :after
|
33
|
+
end
|
34
|
+
|
35
|
+
around(:all) { |g| transactionally(&g) }
|
36
|
+
specify { self.class.order << :e1 }
|
37
|
+
specify { self.class.order << :e2 }
|
38
|
+
end
|
39
|
+
|
40
|
+
group.run(double.as_null_object)
|
41
|
+
group.order.should eq([:before, :e1, :e2, :after])
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'can access metadata in the hook' do
|
45
|
+
foo_value = nil
|
46
|
+
group = ExampleGroup.describe "group", :foo => :bar do
|
47
|
+
around(:all) do |group|
|
48
|
+
foo_value = group.metadata[:foo]
|
49
|
+
group.run_examples
|
50
|
+
end
|
51
|
+
specify { }
|
52
|
+
end
|
53
|
+
|
54
|
+
group.run(double.as_null_object)
|
55
|
+
foo_value.should eq(:bar)
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'allows around(:each) hooks to run as normal' do
|
59
|
+
order = []
|
60
|
+
|
61
|
+
group = ExampleGroup.describe "group" do
|
62
|
+
around(:each) do |e|
|
63
|
+
order << :before
|
64
|
+
e.run
|
65
|
+
order << :after
|
66
|
+
end
|
67
|
+
specify { order << :e1 }
|
68
|
+
specify { order << :e2 }
|
69
|
+
end
|
70
|
+
|
71
|
+
group.run(double.as_null_object)
|
72
|
+
order.should eq([:before, :e1, :after, :before, :e2, :after])
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'allows around hooks with no scope argument to run as normal' do
|
76
|
+
order = []
|
77
|
+
|
78
|
+
group = ExampleGroup.describe "group" do
|
79
|
+
around do |e|
|
80
|
+
order << :before
|
81
|
+
e.run
|
82
|
+
order << :after
|
83
|
+
end
|
84
|
+
specify { order << :e1 }
|
85
|
+
specify { order << :e2 }
|
86
|
+
end
|
87
|
+
|
88
|
+
group.run(double.as_null_object)
|
89
|
+
order.should eq([:before, :e1, :after, :before, :e2, :after])
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
metadata
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rspec_around_all
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Myron Marston
|
9
|
+
- Sean Walbran
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2013-08-07 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rspec
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ~>
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '2.0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ~>
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: '2.0'
|
31
|
+
description:
|
32
|
+
email: seanwalbran@gmail.com
|
33
|
+
executables: []
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- lib/rspec_around_all.rb
|
38
|
+
- LICENSE
|
39
|
+
- README.md
|
40
|
+
- spec/rspec_around_all_spec.rb
|
41
|
+
homepage: https://github.com/seanwalbran/rspec_around_all
|
42
|
+
licenses:
|
43
|
+
- MIT
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options: []
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 1.9.2
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ! '>='
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
requirements: []
|
61
|
+
rubyforge_project:
|
62
|
+
rubygems_version: 1.8.25
|
63
|
+
signing_key:
|
64
|
+
specification_version: 3
|
65
|
+
summary: Provides around(:all) hook for RSpec
|
66
|
+
test_files:
|
67
|
+
- spec/rspec_around_all_spec.rb
|