test-unit-around 0.0.1 → 0.0.2
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.md +34 -15
- data/lib/test/unit/around/version.rb +1 -1
- data/test-unit-around.gemspec +1 -1
- data/test/test/unit/around_test.rb +21 -1
- metadata +3 -3
data/README.md
CHANGED
@@ -1,54 +1,73 @@
|
|
1
|
+
|
1
2
|
# Test::Unit::Around
|
2
3
|
|
3
4
|
Use an around filter instead or in addition to test/unit's setup and teardown methods.
|
5
|
+
This is imho especially useful in combination with context blocks provided by e.g.,
|
6
|
+
the test-unit-context gem to avoid duplicate code.
|
4
7
|
|
5
8
|
## Installation
|
6
9
|
|
7
10
|
Add this line to your application's Gemfile:
|
8
11
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
+
```ruby
|
13
|
+
group :test do
|
14
|
+
gem 'test-unit-around'
|
15
|
+
end
|
16
|
+
```
|
12
17
|
|
13
18
|
And then execute:
|
14
19
|
|
15
|
-
|
20
|
+
```
|
21
|
+
$ bundle
|
22
|
+
```
|
23
|
+
|
24
|
+
Alternatively, you can of course install it without bundler via:
|
25
|
+
|
26
|
+
```
|
27
|
+
$ gem install test-unit-around
|
28
|
+
```
|
16
29
|
|
17
30
|
## Usage
|
18
31
|
|
19
32
|
Use it in your tests:
|
20
33
|
|
21
|
-
|
22
|
-
class FeatureTest
|
34
|
+
```ruby
|
35
|
+
class FeatureTest < Test::Unit::TestCase
|
23
36
|
def around
|
24
|
-
# Before
|
37
|
+
# Before a test runs
|
25
38
|
|
26
39
|
yield
|
27
40
|
|
28
|
-
# After
|
41
|
+
# After a test has run
|
29
42
|
end
|
30
43
|
|
31
44
|
def test_feature
|
32
|
-
#
|
45
|
+
# First test
|
33
46
|
end
|
47
|
+
|
48
|
+
...
|
34
49
|
end
|
35
|
-
|
50
|
+
```
|
36
51
|
|
37
52
|
You can as well use around as a class method:
|
38
53
|
|
39
|
-
|
40
|
-
class FeatureTest
|
54
|
+
```ruby
|
55
|
+
class FeatureTest < Test::Unit::TestCase
|
41
56
|
around do |test|
|
42
|
-
# Before
|
57
|
+
# Before a test runs
|
43
58
|
|
44
59
|
test.run
|
45
60
|
|
46
|
-
# After
|
61
|
+
# After a test has run
|
62
|
+
end
|
63
|
+
|
64
|
+
test "feature" do
|
65
|
+
# First test
|
47
66
|
end
|
48
67
|
|
49
68
|
...
|
50
69
|
end
|
51
|
-
|
70
|
+
```
|
52
71
|
|
53
72
|
## Contributing
|
54
73
|
|
data/test-unit-around.gemspec
CHANGED
@@ -3,42 +3,62 @@ require File.expand_path("../../../../lib/test/unit/around", __FILE__)
|
|
3
3
|
require "test/unit"
|
4
4
|
|
5
5
|
class AroundClassMethodTest < Test::Unit::TestCase
|
6
|
+
setup do
|
7
|
+
assert_nil @before
|
8
|
+
assert_nil @after
|
9
|
+
end
|
10
|
+
|
6
11
|
around do |test|
|
7
12
|
@before = :before
|
8
13
|
|
9
14
|
test.run
|
10
15
|
|
11
16
|
@after = :after
|
17
|
+
end
|
12
18
|
|
19
|
+
teardown do
|
20
|
+
assert_equal :before, @before
|
13
21
|
assert_equal :after, @after
|
14
22
|
end
|
15
23
|
|
16
|
-
|
24
|
+
test "around" do
|
17
25
|
assert_equal :before, @before
|
26
|
+
|
18
27
|
assert_nil @after
|
19
28
|
end
|
20
29
|
end
|
21
30
|
|
22
31
|
class AroundInstanceMethodTest < Test::Unit::TestCase
|
32
|
+
def setup
|
33
|
+
assert_nil @before
|
34
|
+
assert_nil @after
|
35
|
+
end
|
36
|
+
|
23
37
|
def around
|
24
38
|
@before = :before
|
25
39
|
|
26
40
|
yield
|
27
41
|
|
28
42
|
@after = :after
|
43
|
+
end
|
29
44
|
|
45
|
+
def teardown
|
46
|
+
assert_equal :before, @before
|
30
47
|
assert_equal :after, @after
|
31
48
|
end
|
32
49
|
|
33
50
|
def test_around
|
34
51
|
assert_equal :before, @before
|
52
|
+
|
35
53
|
assert_nil @after
|
36
54
|
end
|
37
55
|
end
|
38
56
|
|
39
57
|
class WithoutAroundTest < Test::Unit::TestCase
|
40
58
|
def test_something
|
59
|
+
assert_nil @before
|
41
60
|
assert_nil @after
|
61
|
+
|
42
62
|
assert_equal 1, 1
|
43
63
|
end
|
44
64
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: test-unit-around
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -34,7 +34,7 @@ dependencies:
|
|
34
34
|
requirements:
|
35
35
|
- - ! '>='
|
36
36
|
- !ruby/object:Gem::Version
|
37
|
-
version: 2.4.
|
37
|
+
version: 2.4.4
|
38
38
|
type: :runtime
|
39
39
|
prerelease: false
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -42,7 +42,7 @@ dependencies:
|
|
42
42
|
requirements:
|
43
43
|
- - ! '>='
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
version: 2.4.
|
45
|
+
version: 2.4.4
|
46
46
|
description: Use around instead or in combination with test/unit's setup and teardown
|
47
47
|
methods
|
48
48
|
email:
|