test-unit-around 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +60 -0
- data/Rakefile +10 -0
- data/lib/test/unit/around/version.rb +7 -0
- data/lib/test/unit/around.rb +53 -0
- data/test/test/unit/around_test.rb +45 -0
- data/test-unit-around.gemspec +22 -0
- metadata +88 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Benjamin Vetter
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# Test::Unit::Around
|
2
|
+
|
3
|
+
Use an around filter instead or in addition to test/unit's setup and teardown methods.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
group :test do
|
10
|
+
gem 'test-unit-around'
|
11
|
+
end
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
Use it in your tests:
|
20
|
+
|
21
|
+
<pre>
|
22
|
+
class FeatureTest < Test::Unit::TestCase
|
23
|
+
def around
|
24
|
+
# Before the test runs
|
25
|
+
|
26
|
+
yield
|
27
|
+
|
28
|
+
# After the test has run
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_feature
|
32
|
+
# The test itself
|
33
|
+
end
|
34
|
+
end
|
35
|
+
</pre>
|
36
|
+
|
37
|
+
You can as well use around as a class method:
|
38
|
+
|
39
|
+
<pre>
|
40
|
+
class FeatureTest < Test::Unit::TestCase
|
41
|
+
around do |test|
|
42
|
+
# Before the test runs
|
43
|
+
|
44
|
+
test.run
|
45
|
+
|
46
|
+
# After the test has run
|
47
|
+
end
|
48
|
+
|
49
|
+
...
|
50
|
+
end
|
51
|
+
</pre>
|
52
|
+
|
53
|
+
## Contributing
|
54
|
+
|
55
|
+
1. Fork it
|
56
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
57
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
58
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
59
|
+
5. Create new Pull Request
|
60
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
|
2
|
+
require "test/unit/around/version"
|
3
|
+
require "test/unit"
|
4
|
+
|
5
|
+
module Test
|
6
|
+
module Unit
|
7
|
+
module Around
|
8
|
+
def self.included(base)
|
9
|
+
base.class_eval do
|
10
|
+
def self.around(&block)
|
11
|
+
define_method :around do |&blk|
|
12
|
+
unless blk.respond_to?(:run)
|
13
|
+
def blk.run
|
14
|
+
call
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
instance_exec blk, &block
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def run_with_around(result, &block)
|
23
|
+
if respond_to?(:around)
|
24
|
+
orig = :"orig_#{method_name}"
|
25
|
+
|
26
|
+
unless respond_to?(orig)
|
27
|
+
singleton = class << self; self; end
|
28
|
+
|
29
|
+
singleton.send :define_method, method_name do
|
30
|
+
around { super() }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
run_without_around result, &block
|
36
|
+
end
|
37
|
+
|
38
|
+
alias_method :run_without_around, :run
|
39
|
+
alias_method :run, :run_with_around
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
if defined?(ActiveSupport::TestCase)
|
47
|
+
# ActiveSupport::TestCase itself already overwrites run.
|
48
|
+
# Thus, we need to redefine run there as well.
|
49
|
+
|
50
|
+
ActiveSupport::TestCase.send :include, Test::Unit::Around
|
51
|
+
end
|
52
|
+
|
53
|
+
Test::Unit::TestCase.send :include, Test::Unit::Around
|
@@ -0,0 +1,45 @@
|
|
1
|
+
|
2
|
+
require File.expand_path("../../../../lib/test/unit/around", __FILE__)
|
3
|
+
require "test/unit"
|
4
|
+
|
5
|
+
class AroundClassMethodTest < Test::Unit::TestCase
|
6
|
+
around do |test|
|
7
|
+
@before = :before
|
8
|
+
|
9
|
+
test.run
|
10
|
+
|
11
|
+
@after = :after
|
12
|
+
|
13
|
+
assert_equal :after, @after
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_around
|
17
|
+
assert_equal :before, @before
|
18
|
+
assert_nil @after
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class AroundInstanceMethodTest < Test::Unit::TestCase
|
23
|
+
def around
|
24
|
+
@before = :before
|
25
|
+
|
26
|
+
yield
|
27
|
+
|
28
|
+
@after = :after
|
29
|
+
|
30
|
+
assert_equal :after, @after
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_around
|
34
|
+
assert_equal :before, @before
|
35
|
+
assert_nil @after
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
class WithoutAroundTest < Test::Unit::TestCase
|
40
|
+
def test_something
|
41
|
+
assert_nil @after
|
42
|
+
assert_equal 1, 1
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "test/unit/around/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "test-unit-around"
|
7
|
+
s.version = Test::Unit::Around::VERSION
|
8
|
+
s.authors = ["Benjamin Vetter"]
|
9
|
+
s.email = ["vetter@flakks.com"]
|
10
|
+
s.homepage = "https://github.com/mrkamel/test-unit-around"
|
11
|
+
s.summary = %q{Use around instead or in combination with test/unit's setup and teardown methods}
|
12
|
+
s.description = %q{Use around instead or in combination with test/unit's setup and teardown methods}
|
13
|
+
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
|
19
|
+
s.add_development_dependency "rake"
|
20
|
+
s.add_dependency 'test-unit', '>= 2.4.0'
|
21
|
+
end
|
22
|
+
|
metadata
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: test-unit-around
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Benjamin Vetter
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-11-27 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: test-unit
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 2.4.0
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 2.4.0
|
46
|
+
description: Use around instead or in combination with test/unit's setup and teardown
|
47
|
+
methods
|
48
|
+
email:
|
49
|
+
- vetter@flakks.com
|
50
|
+
executables: []
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- .gitignore
|
55
|
+
- Gemfile
|
56
|
+
- LICENSE.txt
|
57
|
+
- README.md
|
58
|
+
- Rakefile
|
59
|
+
- lib/test/unit/around.rb
|
60
|
+
- lib/test/unit/around/version.rb
|
61
|
+
- test-unit-around.gemspec
|
62
|
+
- test/test/unit/around_test.rb
|
63
|
+
homepage: https://github.com/mrkamel/test-unit-around
|
64
|
+
licenses: []
|
65
|
+
post_install_message:
|
66
|
+
rdoc_options: []
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ! '>='
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
none: false
|
77
|
+
requirements:
|
78
|
+
- - ! '>='
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
requirements: []
|
82
|
+
rubyforge_project:
|
83
|
+
rubygems_version: 1.8.23
|
84
|
+
signing_key:
|
85
|
+
specification_version: 3
|
86
|
+
summary: Use around instead or in combination with test/unit's setup and teardown
|
87
|
+
methods
|
88
|
+
test_files: []
|