minitest-around 0.5.0 → 0.6.0
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.
- checksums.yaml +4 -4
- data/README.md +6 -13
- data/lib/minitest/around/spec.rb +2 -1
- data/lib/minitest/around/unit.rb +4 -5
- data/lib/minitest/around/version.rb +1 -1
- metadata +22 -32
- data/.gitignore +0 -6
- data/.travis.yml +0 -23
- data/Gemfile +0 -7
- data/Rakefile +0 -51
- data/config/cucumber.yml +0 -1
- data/examples/chdir_spec.rb +0 -3
- data/features/around_spec.feature +0 -378
- data/features/step_definitions/around_steps.rb +0 -24
- data/features/support/env.rb +0 -48
- data/minitest-around.gemspec +0 -18
- data/test/around_spec.rb +0 -116
- data/test/around_test.rb +0 -20
- data/test/helper.rb +0 -8
- data/test/nested_spec.rb +0 -36
- data/test/nested_test.rb +0 -35
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f4f10effb533b5e8decd833cd6393fa4b03bd115132584530835a3ad315e84fd
|
|
4
|
+
data.tar.gz: f959199da31aef0268d86753d09686667fc050b2dca2656adc194c5441111708
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 58b06112578cc8349834c3adeb7bbf07c3aa68bc1e18558253957b0c9b585c9d971546be9b28d881175fb62c8b79e2088a4b578306f235f38a57c44779355aa3
|
|
7
|
+
data.tar.gz: 2c32697a59363487efdeb20e4ae7066a87f8d82daddf06b3b8c694c7b1925c03dc6268e911787a0d6e1c68f60de769f4244dc17d0b7edbbe734f6323510618c3
|
data/README.md
CHANGED
|
@@ -2,22 +2,16 @@
|
|
|
2
2
|
[doc]: http://rubydoc.info/github/splattael/minitest-around/master/file/README.md
|
|
3
3
|
[gem]: https://rubygems.org/gems/minitest-around
|
|
4
4
|
[travis]: https://travis-ci.org/splattael/minitest-around
|
|
5
|
-
[codeclimate]: https://codeclimate.com/github/splattael/minitest-around
|
|
6
|
-
[inchpages]: https://inch-ci.org/github/splattael/minitest-around
|
|
7
5
|
|
|
8
6
|
# minitest-around
|
|
9
7
|
|
|
10
8
|
[][travis]
|
|
11
9
|
[][gem]
|
|
12
|
-
[][codeclimate]
|
|
13
|
-
[][codeclimate]
|
|
14
|
-
[][inchpages]
|
|
15
10
|
|
|
16
11
|
[Gem][gem] |
|
|
17
|
-
[Source][github]
|
|
18
|
-
[Documentation][doc]
|
|
12
|
+
[Source][github]
|
|
19
13
|
|
|
20
|
-
Around block for minitest 5.X.
|
|
14
|
+
Around block for minitest 5.X and later.
|
|
21
15
|
|
|
22
16
|
Alternative for setup/teardown dance.
|
|
23
17
|
|
|
@@ -81,9 +75,9 @@ Minitest-around also enables the use of multiple before/after blocks, which norm
|
|
|
81
75
|
- Test bodies won't be run if you don't test.call inside +around+.
|
|
82
76
|
- around runs inside a Fiber, so use `Thread.get_thread_local` / `set_thread_local` instead of `Thread.current.[]`
|
|
83
77
|
|
|
84
|
-
### Minitest 5.X
|
|
78
|
+
### Minitest 5.X and later
|
|
85
79
|
|
|
86
|
-
`minitest-around` currently supports only `minitest` 5.X.
|
|
80
|
+
`minitest-around` currently supports only `minitest` 5.X and later.
|
|
87
81
|
|
|
88
82
|
Please see the [mt4](https://github.com/splattael/minitest-around/tree/mt4) branch
|
|
89
83
|
for `minitest` 4.7.X support.
|
|
@@ -121,7 +115,6 @@ bundle exec rake test
|
|
|
121
115
|
## Release
|
|
122
116
|
|
|
123
117
|
```Bash
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
rake release
|
|
118
|
+
bundle exec rake bump:{patch|minor|major}
|
|
119
|
+
bundle exec rake release
|
|
127
120
|
```
|
data/lib/minitest/around/spec.rb
CHANGED
|
@@ -8,6 +8,7 @@ Minitest::Spec::DSL.class_eval do
|
|
|
8
8
|
# - execute test
|
|
9
9
|
# - resume fiber to execute last part
|
|
10
10
|
def around(*args, &block)
|
|
11
|
+
raise ArgumentError, "only :each, :example, or no argument are supported" if args - [:each, :example] != []
|
|
11
12
|
fib = nil
|
|
12
13
|
before do
|
|
13
14
|
fib = Fiber.new do |context, resume|
|
|
@@ -20,7 +21,7 @@ Minitest::Spec::DSL.class_eval do
|
|
|
20
21
|
end
|
|
21
22
|
fib.resume(self, lambda { Fiber.yield })
|
|
22
23
|
end
|
|
23
|
-
after { fib.resume
|
|
24
|
+
after { fib.resume if fib && fib != :failed }
|
|
24
25
|
end
|
|
25
26
|
|
|
26
27
|
# Minitest does not support multiple before/after blocks
|
data/lib/minitest/around/unit.rb
CHANGED
|
@@ -2,15 +2,14 @@ require 'minitest/test'
|
|
|
2
2
|
|
|
3
3
|
require 'minitest/around/version'
|
|
4
4
|
|
|
5
|
-
Minitest::Test.
|
|
6
|
-
alias_method :run_without_around, :run
|
|
5
|
+
Minitest::Test.prepend(Module.new do
|
|
7
6
|
def run(*args)
|
|
8
7
|
if defined?(around)
|
|
9
8
|
result = nil
|
|
10
|
-
around { result =
|
|
9
|
+
around { result = super(*args) }
|
|
11
10
|
result
|
|
12
11
|
else
|
|
13
|
-
|
|
12
|
+
super(*args)
|
|
14
13
|
end
|
|
15
14
|
end
|
|
16
|
-
end
|
|
15
|
+
end)
|
metadata
CHANGED
|
@@ -1,31 +1,37 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: minitest-around
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.6.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Peter Leitzen
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2025-12-28 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: minitest
|
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
|
16
16
|
requirements:
|
|
17
|
-
- - "
|
|
17
|
+
- - ">"
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
19
|
version: '5.0'
|
|
20
|
+
- - "<"
|
|
21
|
+
- !ruby/object:Gem::Version
|
|
22
|
+
version: '7.0'
|
|
20
23
|
type: :runtime
|
|
21
24
|
prerelease: false
|
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
26
|
requirements:
|
|
24
|
-
- - "
|
|
27
|
+
- - ">"
|
|
25
28
|
- !ruby/object:Gem::Version
|
|
26
29
|
version: '5.0'
|
|
30
|
+
- - "<"
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '7.0'
|
|
27
33
|
- !ruby/object:Gem::Dependency
|
|
28
|
-
name:
|
|
34
|
+
name: rake
|
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
|
30
36
|
requirements:
|
|
31
37
|
- - ">="
|
|
@@ -39,7 +45,7 @@ dependencies:
|
|
|
39
45
|
- !ruby/object:Gem::Version
|
|
40
46
|
version: '0'
|
|
41
47
|
- !ruby/object:Gem::Dependency
|
|
42
|
-
name:
|
|
48
|
+
name: cucumber
|
|
43
49
|
requirement: !ruby/object:Gem::Requirement
|
|
44
50
|
requirements:
|
|
45
51
|
- - ">="
|
|
@@ -53,21 +59,21 @@ dependencies:
|
|
|
53
59
|
- !ruby/object:Gem::Version
|
|
54
60
|
version: '0'
|
|
55
61
|
- !ruby/object:Gem::Dependency
|
|
56
|
-
name:
|
|
62
|
+
name: bump
|
|
57
63
|
requirement: !ruby/object:Gem::Requirement
|
|
58
64
|
requirements:
|
|
59
|
-
- - "
|
|
65
|
+
- - ">="
|
|
60
66
|
- !ruby/object:Gem::Version
|
|
61
|
-
version:
|
|
67
|
+
version: '0'
|
|
62
68
|
type: :development
|
|
63
69
|
prerelease: false
|
|
64
70
|
version_requirements: !ruby/object:Gem::Requirement
|
|
65
71
|
requirements:
|
|
66
|
-
- - "
|
|
72
|
+
- - ">="
|
|
67
73
|
- !ruby/object:Gem::Version
|
|
68
|
-
version:
|
|
74
|
+
version: '0'
|
|
69
75
|
- !ruby/object:Gem::Dependency
|
|
70
|
-
name:
|
|
76
|
+
name: forking_test_runner
|
|
71
77
|
requirement: !ruby/object:Gem::Requirement
|
|
72
78
|
requirements:
|
|
73
79
|
- - ">="
|
|
@@ -87,32 +93,17 @@ executables: []
|
|
|
87
93
|
extensions: []
|
|
88
94
|
extra_rdoc_files: []
|
|
89
95
|
files:
|
|
90
|
-
- ".gitignore"
|
|
91
|
-
- ".travis.yml"
|
|
92
|
-
- Gemfile
|
|
93
96
|
- LICENSE
|
|
94
97
|
- README.md
|
|
95
|
-
- Rakefile
|
|
96
|
-
- config/cucumber.yml
|
|
97
|
-
- examples/chdir_spec.rb
|
|
98
|
-
- features/around_spec.feature
|
|
99
|
-
- features/step_definitions/around_steps.rb
|
|
100
|
-
- features/support/env.rb
|
|
101
98
|
- lib/minitest/around.rb
|
|
102
99
|
- lib/minitest/around/spec.rb
|
|
103
100
|
- lib/minitest/around/unit.rb
|
|
104
101
|
- lib/minitest/around/version.rb
|
|
105
|
-
- minitest-around.gemspec
|
|
106
|
-
- test/around_spec.rb
|
|
107
|
-
- test/around_test.rb
|
|
108
|
-
- test/helper.rb
|
|
109
|
-
- test/nested_spec.rb
|
|
110
|
-
- test/nested_test.rb
|
|
111
102
|
homepage: https://github.com/splattael/minitest-around
|
|
112
103
|
licenses:
|
|
113
104
|
- MIT
|
|
114
105
|
metadata: {}
|
|
115
|
-
post_install_message:
|
|
106
|
+
post_install_message:
|
|
116
107
|
rdoc_options: []
|
|
117
108
|
require_paths:
|
|
118
109
|
- lib
|
|
@@ -127,9 +118,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
127
118
|
- !ruby/object:Gem::Version
|
|
128
119
|
version: '0'
|
|
129
120
|
requirements: []
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
signing_key:
|
|
121
|
+
rubygems_version: 3.4.10
|
|
122
|
+
signing_key:
|
|
133
123
|
specification_version: 4
|
|
134
124
|
summary: Around block for minitest.
|
|
135
125
|
test_files: []
|
data/.gitignore
DELETED
data/.travis.yml
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
language: ruby
|
|
2
|
-
sudo: false
|
|
3
|
-
cache: bundler
|
|
4
|
-
rvm:
|
|
5
|
-
- 2.0
|
|
6
|
-
- 2.1
|
|
7
|
-
- 2.2
|
|
8
|
-
- 2.3
|
|
9
|
-
- 2.4
|
|
10
|
-
- ruby-head
|
|
11
|
-
- jruby
|
|
12
|
-
- jruby-head
|
|
13
|
-
- rbx-2
|
|
14
|
-
env:
|
|
15
|
-
global:
|
|
16
|
-
- CODECLIMATE_REPO_TOKEN=e2647eb4bb8263157b9d99d9f79a49f8262a7e5ed11b07bdfbd312afdb43c2fa
|
|
17
|
-
- JRUBY_OPTS='--dev -J-Xmx1024M'
|
|
18
|
-
matrix:
|
|
19
|
-
allow_failures:
|
|
20
|
-
- rvm: ruby-head
|
|
21
|
-
- rvm: jruby-head
|
|
22
|
-
- rvm: rbx-2
|
|
23
|
-
fast_finish: true
|
data/Gemfile
DELETED
data/Rakefile
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
require 'bundler/setup'
|
|
2
|
-
require 'bundler/gem_tasks'
|
|
3
|
-
require 'cucumber/rake/task'
|
|
4
|
-
require 'bump/tasks'
|
|
5
|
-
|
|
6
|
-
desc 'Default: run unit tests.'
|
|
7
|
-
task :default => [:test, :"test:isolated", :features]
|
|
8
|
-
|
|
9
|
-
# Test
|
|
10
|
-
TEST_FILES = FileList.new('test/*_{test,spec}.rb')
|
|
11
|
-
|
|
12
|
-
desc "Run all tests"
|
|
13
|
-
task :test do
|
|
14
|
-
TEST_FILES.each do |test_file|
|
|
15
|
-
sh "bundle", "exec", "rake", "test:isolated", "TEST=#{test_file}"
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
require 'rake/testtask'
|
|
20
|
-
Rake::TestTask.new(:"test:isolated") do |test|
|
|
21
|
-
test.test_files = TEST_FILES
|
|
22
|
-
test.libs << 'test'
|
|
23
|
-
test.verbose = true
|
|
24
|
-
test.warning = true
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
# Examples
|
|
28
|
-
EXAMPLES = FileList["examples/*.rb"]
|
|
29
|
-
desc "Run all examples"
|
|
30
|
-
task :"test:examples" do
|
|
31
|
-
EXAMPLES.each do |example|
|
|
32
|
-
sh "bundle", "exec", "ruby", example
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
# Features
|
|
37
|
-
Cucumber::Rake::Task.new(:features) do |t|
|
|
38
|
-
skip_tags = %w[rspec todo].map { |tag| "--tag ~@#{tag}" }.join(" ")
|
|
39
|
-
t.cucumber_opts = "features #{skip_tags}"
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
# RDoc
|
|
43
|
-
require 'rdoc/task'
|
|
44
|
-
RDoc::Task.new do |rdoc|
|
|
45
|
-
rdoc.rdoc_dir = 'rdoc'
|
|
46
|
-
rdoc.title = 'mintest-around'
|
|
47
|
-
rdoc.main = 'README.md'
|
|
48
|
-
rdoc.rdoc_files.include('README.md', 'LICENSE', 'lib/**/*.rb')
|
|
49
|
-
rdoc.options << "--all"
|
|
50
|
-
rdoc.options << "--markup markdown"
|
|
51
|
-
end
|
data/config/cucumber.yml
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
default: --tags ~@ignore -f progress
|
data/examples/chdir_spec.rb
DELETED
|
@@ -1,378 +0,0 @@
|
|
|
1
|
-
Feature: `around` hooks
|
|
2
|
-
|
|
3
|
-
`around` hooks receive the example as a block argument, extended to behave as
|
|
4
|
-
a proc. This lets you define code that should be executed before and after the
|
|
5
|
-
example. Of course, you can do the same thing with `before` and `after` hooks;
|
|
6
|
-
and it's often cleaner to do so.
|
|
7
|
-
|
|
8
|
-
Where `around` hooks shine is when you want to run an example within a block.
|
|
9
|
-
For instance, if your database library offers a transaction method that
|
|
10
|
-
receives a block, you can use an `around` to cleanly open and close the
|
|
11
|
-
transaction around the example.
|
|
12
|
-
|
|
13
|
-
**WARNING:** `around` hooks do not share state with the example the way
|
|
14
|
-
`before` and `after` hooks do. This means that you cannot share instance
|
|
15
|
-
variables between `around` hooks and examples.
|
|
16
|
-
|
|
17
|
-
**WARNING:** Mock frameworks are set up and torn down within the context of
|
|
18
|
-
running the example. You cannot interact with them directly in `around` hooks.
|
|
19
|
-
|
|
20
|
-
Scenario: Use the example as a proc within the block passed to `around()`
|
|
21
|
-
Given a file named "example_spec.rb" with:
|
|
22
|
-
"""ruby
|
|
23
|
-
class Database
|
|
24
|
-
def self.transaction
|
|
25
|
-
puts "open transaction"
|
|
26
|
-
yield
|
|
27
|
-
puts "close transaction"
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
RSpec.describe "around filter" do
|
|
32
|
-
around(:example) do |example|
|
|
33
|
-
Database.transaction(&example)
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
it "gets run in order" do
|
|
37
|
-
puts "run the example"
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
"""
|
|
41
|
-
When I run `rspec example_spec.rb`
|
|
42
|
-
Then the output should contain:
|
|
43
|
-
"""
|
|
44
|
-
open transaction
|
|
45
|
-
run the example
|
|
46
|
-
close transaction
|
|
47
|
-
"""
|
|
48
|
-
|
|
49
|
-
Scenario: Invoke the example using `run()`
|
|
50
|
-
Given a file named "example_spec.rb" with:
|
|
51
|
-
"""ruby
|
|
52
|
-
RSpec.describe "around hook" do
|
|
53
|
-
around(:example) do |example|
|
|
54
|
-
puts "around example before"
|
|
55
|
-
example.run
|
|
56
|
-
puts "around example after"
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
it "gets run in order" do
|
|
60
|
-
puts "in the example"
|
|
61
|
-
end
|
|
62
|
-
end
|
|
63
|
-
"""
|
|
64
|
-
When I run `rspec example_spec.rb`
|
|
65
|
-
Then the output should contain:
|
|
66
|
-
"""
|
|
67
|
-
around example before
|
|
68
|
-
in the example
|
|
69
|
-
around example after
|
|
70
|
-
"""
|
|
71
|
-
|
|
72
|
-
@rspec
|
|
73
|
-
Scenario: Access the example metadata
|
|
74
|
-
Given a file named "example_spec.rb" with:
|
|
75
|
-
"""ruby
|
|
76
|
-
RSpec.describe "something" do
|
|
77
|
-
around(:example) do |example|
|
|
78
|
-
puts example.metadata[:foo]
|
|
79
|
-
example.run
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
it "does something", :foo => "this should show up in the output" do
|
|
83
|
-
end
|
|
84
|
-
end
|
|
85
|
-
"""
|
|
86
|
-
When I run `rspec example_spec.rb`
|
|
87
|
-
Then the output should contain "this should show up in the output"
|
|
88
|
-
|
|
89
|
-
Scenario: An around hook continues to run even if the example throws an exception
|
|
90
|
-
Given a file named "example_spec.rb" with:
|
|
91
|
-
"""ruby
|
|
92
|
-
RSpec.describe "something" do
|
|
93
|
-
around(:example) do |example|
|
|
94
|
-
puts "around example setup"
|
|
95
|
-
example.run
|
|
96
|
-
puts "around example cleanup"
|
|
97
|
-
end
|
|
98
|
-
|
|
99
|
-
it "still executes the entire around hook" do
|
|
100
|
-
fail "the example blows up"
|
|
101
|
-
end
|
|
102
|
-
end
|
|
103
|
-
"""
|
|
104
|
-
When I run `rspec example_spec.rb`
|
|
105
|
-
Then the output should contain "1 example, 1 error"
|
|
106
|
-
And the output should contain:
|
|
107
|
-
"""
|
|
108
|
-
around example setup
|
|
109
|
-
around example cleanup
|
|
110
|
-
"""
|
|
111
|
-
|
|
112
|
-
@rspec
|
|
113
|
-
Scenario: Define a global `around` hook
|
|
114
|
-
Given a file named "example_spec.rb" with:
|
|
115
|
-
"""ruby
|
|
116
|
-
RSpec.configure do |c|
|
|
117
|
-
c.around(:example) do |example|
|
|
118
|
-
puts "around example before"
|
|
119
|
-
example.run
|
|
120
|
-
puts "around example after"
|
|
121
|
-
end
|
|
122
|
-
end
|
|
123
|
-
|
|
124
|
-
RSpec.describe "around filter" do
|
|
125
|
-
it "gets run in order" do
|
|
126
|
-
puts "in the example"
|
|
127
|
-
end
|
|
128
|
-
end
|
|
129
|
-
"""
|
|
130
|
-
When I run `rspec example_spec.rb`
|
|
131
|
-
Then the output should contain:
|
|
132
|
-
"""
|
|
133
|
-
around example before
|
|
134
|
-
in the example
|
|
135
|
-
around example after
|
|
136
|
-
"""
|
|
137
|
-
|
|
138
|
-
Scenario: Per example hooks are wrapped by the `around` hook
|
|
139
|
-
Given a file named "example_spec.rb" with:
|
|
140
|
-
"""ruby
|
|
141
|
-
RSpec.describe "around filter" do
|
|
142
|
-
around(:example) do |example|
|
|
143
|
-
puts "around example before"
|
|
144
|
-
example.run
|
|
145
|
-
puts "around example after"
|
|
146
|
-
end
|
|
147
|
-
|
|
148
|
-
before(:example) do
|
|
149
|
-
puts "before example"
|
|
150
|
-
end
|
|
151
|
-
|
|
152
|
-
after(:example) do
|
|
153
|
-
puts "after example"
|
|
154
|
-
end
|
|
155
|
-
|
|
156
|
-
it "gets run in order" do
|
|
157
|
-
puts "in the example"
|
|
158
|
-
end
|
|
159
|
-
end
|
|
160
|
-
"""
|
|
161
|
-
When I run `rspec example_spec.rb`
|
|
162
|
-
Then the output should contain:
|
|
163
|
-
"""
|
|
164
|
-
around example before
|
|
165
|
-
before example
|
|
166
|
-
in the example
|
|
167
|
-
after example
|
|
168
|
-
around example after
|
|
169
|
-
"""
|
|
170
|
-
|
|
171
|
-
@todo
|
|
172
|
-
Scenario: Context hooks are NOT wrapped by the `around` hook
|
|
173
|
-
Given a file named "example_spec.rb" with:
|
|
174
|
-
"""ruby
|
|
175
|
-
RSpec.describe "around filter" do
|
|
176
|
-
around(:example) do |example|
|
|
177
|
-
puts "around example before"
|
|
178
|
-
example.run
|
|
179
|
-
puts "around example after"
|
|
180
|
-
end
|
|
181
|
-
|
|
182
|
-
before(:context) do
|
|
183
|
-
puts "before context"
|
|
184
|
-
end
|
|
185
|
-
|
|
186
|
-
after(:context) do
|
|
187
|
-
puts "after context"
|
|
188
|
-
end
|
|
189
|
-
|
|
190
|
-
it "gets run in order" do
|
|
191
|
-
puts "in the example"
|
|
192
|
-
end
|
|
193
|
-
end
|
|
194
|
-
"""
|
|
195
|
-
When I run `rspec --format progress example_spec.rb`
|
|
196
|
-
Then the output should contain:
|
|
197
|
-
"""
|
|
198
|
-
before context
|
|
199
|
-
around example before
|
|
200
|
-
in the example
|
|
201
|
-
around example after
|
|
202
|
-
.after context
|
|
203
|
-
"""
|
|
204
|
-
|
|
205
|
-
@rspec
|
|
206
|
-
Scenario: Examples run by an `around` block are run in the configured context
|
|
207
|
-
Given a file named "example_spec.rb" with:
|
|
208
|
-
"""ruby
|
|
209
|
-
module IncludedInConfigureBlock
|
|
210
|
-
def included_in_configure_block; true; end
|
|
211
|
-
end
|
|
212
|
-
|
|
213
|
-
RSpec.configure do |c|
|
|
214
|
-
c.include IncludedInConfigureBlock
|
|
215
|
-
end
|
|
216
|
-
|
|
217
|
-
RSpec.describe "around filter" do
|
|
218
|
-
around(:example) do |example|
|
|
219
|
-
example.run
|
|
220
|
-
end
|
|
221
|
-
|
|
222
|
-
it "runs the example in the correct context" do
|
|
223
|
-
expect(included_in_configure_block).to be_truthy
|
|
224
|
-
end
|
|
225
|
-
end
|
|
226
|
-
"""
|
|
227
|
-
When I run `rspec example_spec.rb`
|
|
228
|
-
Then the output should contain "1 example, 0 failure"
|
|
229
|
-
|
|
230
|
-
@rspec
|
|
231
|
-
Scenario: Implicitly pending examples are detected as Not yet implemented
|
|
232
|
-
Given a file named "example_spec.rb" with:
|
|
233
|
-
"""ruby
|
|
234
|
-
RSpec.describe "implicit pending example" do
|
|
235
|
-
around(:example) do |example|
|
|
236
|
-
example.run
|
|
237
|
-
end
|
|
238
|
-
|
|
239
|
-
it "should be detected as Not yet implemented"
|
|
240
|
-
end
|
|
241
|
-
"""
|
|
242
|
-
When I run `rspec example_spec.rb`
|
|
243
|
-
Then the output should contain "1 example, 0 failures, 1 pending"
|
|
244
|
-
And the output should contain:
|
|
245
|
-
"""
|
|
246
|
-
Pending: (Failures listed here are expected and do not affect your suite's status)
|
|
247
|
-
|
|
248
|
-
1) implicit pending example should be detected as Not yet implemented
|
|
249
|
-
# Not yet implemented
|
|
250
|
-
# ./example_spec.rb:6
|
|
251
|
-
"""
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
@rspec
|
|
255
|
-
Scenario: Explicitly pending examples are detected as pending
|
|
256
|
-
Given a file named "example_spec.rb" with:
|
|
257
|
-
"""ruby
|
|
258
|
-
RSpec.describe "explicit pending example" do
|
|
259
|
-
around(:example) do |example|
|
|
260
|
-
example.run
|
|
261
|
-
end
|
|
262
|
-
|
|
263
|
-
it "should be detected as pending" do
|
|
264
|
-
pending
|
|
265
|
-
fail
|
|
266
|
-
end
|
|
267
|
-
end
|
|
268
|
-
"""
|
|
269
|
-
When I run `rspec example_spec.rb`
|
|
270
|
-
Then the output should contain "1 example, 0 failures, 1 pending"
|
|
271
|
-
And the output should contain:
|
|
272
|
-
"""
|
|
273
|
-
Pending: (Failures listed here are expected and do not affect your suite's status)
|
|
274
|
-
|
|
275
|
-
1) explicit pending example should be detected as pending
|
|
276
|
-
# No reason given
|
|
277
|
-
"""
|
|
278
|
-
|
|
279
|
-
Scenario: Multiple `around` hooks in the same scope
|
|
280
|
-
Given a file named "example_spec.rb" with:
|
|
281
|
-
"""ruby
|
|
282
|
-
RSpec.describe "if there are multiple around hooks in the same scope" do
|
|
283
|
-
around(:example) do |example|
|
|
284
|
-
puts "first around hook before"
|
|
285
|
-
example.run
|
|
286
|
-
puts "first around hook after"
|
|
287
|
-
end
|
|
288
|
-
|
|
289
|
-
around(:example) do |example|
|
|
290
|
-
puts "second around hook before"
|
|
291
|
-
example.run
|
|
292
|
-
puts "second around hook after"
|
|
293
|
-
end
|
|
294
|
-
|
|
295
|
-
it "they should all be run" do
|
|
296
|
-
puts "in the example"
|
|
297
|
-
expect(1).to eq(1)
|
|
298
|
-
end
|
|
299
|
-
end
|
|
300
|
-
"""
|
|
301
|
-
When I run `rspec example_spec.rb`
|
|
302
|
-
Then the output should contain "1 example, 0 failure"
|
|
303
|
-
And the output should contain:
|
|
304
|
-
"""
|
|
305
|
-
first around hook before
|
|
306
|
-
second around hook before
|
|
307
|
-
in the example
|
|
308
|
-
second around hook after
|
|
309
|
-
first around hook after
|
|
310
|
-
"""
|
|
311
|
-
|
|
312
|
-
Scenario: `around` hooks in multiple scopes
|
|
313
|
-
Given a file named "example_spec.rb" with:
|
|
314
|
-
"""ruby
|
|
315
|
-
RSpec.describe "if there are around hooks in an outer scope" do
|
|
316
|
-
around(:example) do |example|
|
|
317
|
-
puts "first outermost around hook before"
|
|
318
|
-
example.run
|
|
319
|
-
puts "first outermost around hook after"
|
|
320
|
-
end
|
|
321
|
-
|
|
322
|
-
around(:example) do |example|
|
|
323
|
-
puts "second outermost around hook before"
|
|
324
|
-
example.run
|
|
325
|
-
puts "second outermost around hook after"
|
|
326
|
-
end
|
|
327
|
-
|
|
328
|
-
describe "outer scope" do
|
|
329
|
-
around(:example) do |example|
|
|
330
|
-
puts "first outer around hook before"
|
|
331
|
-
example.run
|
|
332
|
-
puts "first outer around hook after"
|
|
333
|
-
end
|
|
334
|
-
|
|
335
|
-
around(:example) do |example|
|
|
336
|
-
puts "second outer around hook before"
|
|
337
|
-
example.run
|
|
338
|
-
puts "second outer around hook after"
|
|
339
|
-
end
|
|
340
|
-
|
|
341
|
-
describe "inner scope" do
|
|
342
|
-
around(:example) do |example|
|
|
343
|
-
puts "first inner around hook before"
|
|
344
|
-
example.run
|
|
345
|
-
puts "first inner around hook after"
|
|
346
|
-
end
|
|
347
|
-
|
|
348
|
-
around(:example) do |example|
|
|
349
|
-
puts "second inner around hook before"
|
|
350
|
-
example.run
|
|
351
|
-
puts "second inner around hook after"
|
|
352
|
-
end
|
|
353
|
-
|
|
354
|
-
it "they should all be run" do
|
|
355
|
-
puts "in the example"
|
|
356
|
-
end
|
|
357
|
-
end
|
|
358
|
-
end
|
|
359
|
-
end
|
|
360
|
-
"""
|
|
361
|
-
When I run `rspec example_spec.rb`
|
|
362
|
-
Then the output should contain "1 example, 0 failure"
|
|
363
|
-
And the output should contain:
|
|
364
|
-
"""
|
|
365
|
-
first outermost around hook before
|
|
366
|
-
second outermost around hook before
|
|
367
|
-
first outer around hook before
|
|
368
|
-
second outer around hook before
|
|
369
|
-
first inner around hook before
|
|
370
|
-
second inner around hook before
|
|
371
|
-
in the example
|
|
372
|
-
second inner around hook after
|
|
373
|
-
first inner around hook after
|
|
374
|
-
second outer around hook after
|
|
375
|
-
first outer around hook after
|
|
376
|
-
second outermost around hook after
|
|
377
|
-
first outermost around hook after
|
|
378
|
-
"""
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
require 'tempfile'
|
|
2
|
-
|
|
3
|
-
Given(/^a file named "(.*?)" with:$/) do |filename, content|
|
|
4
|
-
write_test_file(filename, content)
|
|
5
|
-
end
|
|
6
|
-
|
|
7
|
-
When(/^I run `rspec.*?(\S+)`$/) do |filename|
|
|
8
|
-
path = path_for(filename)
|
|
9
|
-
@output = `ruby #{path}`
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
Then(/^the output should contain:$/) do |content|
|
|
13
|
-
assert_includes @output, content, @output
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
Then(/^the output should contain "(.*?)"$/) do |content|
|
|
17
|
-
# 1 runs, 0 assertions, 0 failures, 0 errors, 0 skips
|
|
18
|
-
runs = $1 if content =~ /(\d+) examples?/
|
|
19
|
-
errors = $1 if content =~ /(\d+) errors?/
|
|
20
|
-
failures = $1 if content =~ /(\d+) failures?/
|
|
21
|
-
skips = $1 if content =~ /(\d+) pending/
|
|
22
|
-
content = /#{runs} runs, \d+ assertions, #{failures || 0} failures, #{errors || 0} errors, #{skips || 0} skips/
|
|
23
|
-
assert_match content, @output, @output
|
|
24
|
-
end
|
data/features/support/env.rb
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
require 'minitest/spec'
|
|
2
|
-
|
|
3
|
-
class MyWorld
|
|
4
|
-
include Minitest::Assertions
|
|
5
|
-
|
|
6
|
-
attr_accessor :assertions
|
|
7
|
-
|
|
8
|
-
def initialize
|
|
9
|
-
self.assertions = 0
|
|
10
|
-
@temp_pathes = {}
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def write_test_file(filename, content)
|
|
14
|
-
# RSpec.describe -> describe
|
|
15
|
-
content.gsub!("RSpec.describe", "describe")
|
|
16
|
-
# example.run -> example.call
|
|
17
|
-
content.gsub!("example.run", "example.call")
|
|
18
|
-
# expect(..).to .. -> expect(..).must_equal ..
|
|
19
|
-
content.gsub!("to eq", "must_equal")
|
|
20
|
-
|
|
21
|
-
content = <<-RUBY + content
|
|
22
|
-
require 'minitest/autorun'
|
|
23
|
-
require '#{File.expand_path("../../../lib/minitest/around/spec", __FILE__)}'
|
|
24
|
-
RUBY
|
|
25
|
-
write_file(filename, content)
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def write_file(filename, content)
|
|
29
|
-
Tempfile.open(filename) do |file|
|
|
30
|
-
file.write content
|
|
31
|
-
assoc_tempfile filename, file.path
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def path_for(filename)
|
|
36
|
-
@temp_pathes.fetch(filename)
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
private
|
|
40
|
-
|
|
41
|
-
def assoc_tempfile(filename, temp_path)
|
|
42
|
-
@temp_pathes[filename] = temp_path
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
World do
|
|
47
|
-
MyWorld.new
|
|
48
|
-
end
|
data/minitest-around.gemspec
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
require './lib/minitest/around/version'
|
|
2
|
-
|
|
3
|
-
Gem::Specification.new "minitest-around", MinitestAround::VERSION do |s|
|
|
4
|
-
s.authors = ["Peter Leitzen"]
|
|
5
|
-
s.email = ["peter-minitest-around@suschlik.de"]
|
|
6
|
-
s.homepage = "https://github.com/splattael/minitest-around"
|
|
7
|
-
s.summary = "Around block for minitest."
|
|
8
|
-
s.description = "Alternative for setup/teardown dance."
|
|
9
|
-
s.license = 'MIT'
|
|
10
|
-
s.files = `git ls-files`.split("\n")
|
|
11
|
-
|
|
12
|
-
s.add_dependency 'minitest', '~> 5.0'
|
|
13
|
-
|
|
14
|
-
s.add_development_dependency 'rdoc'
|
|
15
|
-
s.add_development_dependency 'rake'
|
|
16
|
-
s.add_development_dependency 'cucumber', '~> 2.4.0'
|
|
17
|
-
s.add_development_dependency 'bump'
|
|
18
|
-
end
|
data/test/around_spec.rb
DELETED
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
require_relative 'helper'
|
|
2
|
-
require 'minitest/around/spec'
|
|
3
|
-
|
|
4
|
-
describe "Minitest Around" do
|
|
5
|
-
describe "without around" do
|
|
6
|
-
it "works w/o defining parameters" do
|
|
7
|
-
assert true
|
|
8
|
-
end
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
describe "simple" do
|
|
12
|
-
around do |test|
|
|
13
|
-
$before = true
|
|
14
|
-
test.call
|
|
15
|
-
$before = false
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
it "runs around" do
|
|
19
|
-
$before.must_equal true
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
describe "context" do
|
|
24
|
-
before { @x = 1 }
|
|
25
|
-
|
|
26
|
-
around do |test|
|
|
27
|
-
@x = 2
|
|
28
|
-
test.call
|
|
29
|
-
assert_equal 2, @x
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
it "stays in context" do
|
|
33
|
-
@x.must_equal 2
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
describe "nested fun" do
|
|
38
|
-
let(:list) { [] }
|
|
39
|
-
before { list << 1 }
|
|
40
|
-
before { list << 2 }
|
|
41
|
-
after do
|
|
42
|
-
if @xxx == 1
|
|
43
|
-
list.must_equal [1, 2, 3, 4, 5, 9, 8, 7, 6]
|
|
44
|
-
elsif @xxx == 2
|
|
45
|
-
list.must_equal [1, 2, 3, 4, 5, 51, 9, 8, 7, 6]
|
|
46
|
-
else
|
|
47
|
-
raise
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
after { list << 6 }
|
|
51
|
-
around { |t| list << 3; t.call; list << 7 }
|
|
52
|
-
before { list << 4 }
|
|
53
|
-
around { |t| list << 5; t.call; list << 8 }
|
|
54
|
-
after { list << 9 }
|
|
55
|
-
|
|
56
|
-
it "orders" do
|
|
57
|
-
@xxx = 1
|
|
58
|
-
list.must_equal [1, 2, 3, 4, 5]
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
describe "more nesting fun" do
|
|
62
|
-
before { list << 51 }
|
|
63
|
-
|
|
64
|
-
it "orders" do
|
|
65
|
-
@xxx = 2
|
|
66
|
-
list.must_equal [1, 2, 3, 4, 5, 51]
|
|
67
|
-
end
|
|
68
|
-
end
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
describe "fail" do
|
|
72
|
-
it "does not fail with fiber error" do
|
|
73
|
-
output = spawn_test <<-RUBY
|
|
74
|
-
describe "x" do
|
|
75
|
-
around { raise ArgumentError }
|
|
76
|
-
after { puts "AFTER" }
|
|
77
|
-
it("x") { }
|
|
78
|
-
end
|
|
79
|
-
RUBY
|
|
80
|
-
|
|
81
|
-
output.must_include "ArgumentError: ArgumentError"
|
|
82
|
-
output.wont_include "FiberError"
|
|
83
|
-
end
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
describe "ensure blocks in around" do
|
|
87
|
-
it "runs the ensure block even if another teardown fails" do
|
|
88
|
-
output = spawn_test <<-RUBY
|
|
89
|
-
describe "x" do
|
|
90
|
-
around do |b|
|
|
91
|
-
begin
|
|
92
|
-
b.call
|
|
93
|
-
ensure
|
|
94
|
-
puts "ENSURE"
|
|
95
|
-
end
|
|
96
|
-
end
|
|
97
|
-
after { raise }
|
|
98
|
-
it("x") {}
|
|
99
|
-
end
|
|
100
|
-
RUBY
|
|
101
|
-
output.must_include("ENSURE")
|
|
102
|
-
end
|
|
103
|
-
end
|
|
104
|
-
end
|
|
105
|
-
|
|
106
|
-
def spawn_test(code)
|
|
107
|
-
Tempfile.open("XX") do |f|
|
|
108
|
-
f.write <<-RUBY
|
|
109
|
-
require "#{File.expand_path("../helper", __FILE__)}"
|
|
110
|
-
require 'minitest/around/spec'
|
|
111
|
-
#{code}
|
|
112
|
-
RUBY
|
|
113
|
-
f.close
|
|
114
|
-
`ruby #{f.path}`
|
|
115
|
-
end
|
|
116
|
-
end
|
data/test/around_test.rb
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
require_relative 'helper'
|
|
2
|
-
require 'minitest/around/unit'
|
|
3
|
-
|
|
4
|
-
class TestWithoutAround < Minitest::Test
|
|
5
|
-
def test_no_around_defined
|
|
6
|
-
assert true
|
|
7
|
-
end
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
class TestWithoutArgs < Minitest::Test
|
|
11
|
-
def around
|
|
12
|
-
$before = true
|
|
13
|
-
yield
|
|
14
|
-
$before = false # hard to test?
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def test_runs_around
|
|
18
|
-
assert_equal true, $before
|
|
19
|
-
end
|
|
20
|
-
end
|
data/test/helper.rb
DELETED
data/test/nested_spec.rb
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
require_relative 'helper'
|
|
2
|
-
require 'minitest/around'
|
|
3
|
-
|
|
4
|
-
describe 'Outer' do
|
|
5
|
-
let(:var) { [] }
|
|
6
|
-
|
|
7
|
-
before do
|
|
8
|
-
var << :before
|
|
9
|
-
end
|
|
10
|
-
after do
|
|
11
|
-
var << :after
|
|
12
|
-
var.must_equal [:before, :begin, :ibefore, :ibegin, :during, :iend, :iafter, :end, :after]
|
|
13
|
-
end
|
|
14
|
-
around do |test|
|
|
15
|
-
var << :begin
|
|
16
|
-
test.call
|
|
17
|
-
var << :end
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
describe 'Inner' do
|
|
21
|
-
before do
|
|
22
|
-
var << :ibefore
|
|
23
|
-
end
|
|
24
|
-
after do
|
|
25
|
-
var << :iafter
|
|
26
|
-
end
|
|
27
|
-
around do |test|
|
|
28
|
-
var << :ibegin
|
|
29
|
-
test.call
|
|
30
|
-
var << :iend
|
|
31
|
-
end
|
|
32
|
-
it 'testing' do
|
|
33
|
-
var << :during
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
end
|
data/test/nested_test.rb
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
require_relative 'helper'
|
|
2
|
-
require 'minitest/around/unit'
|
|
3
|
-
|
|
4
|
-
class OuterNestedTest < Minitest::Test
|
|
5
|
-
@@var = []
|
|
6
|
-
def setup
|
|
7
|
-
@@var << :before
|
|
8
|
-
end
|
|
9
|
-
def teardown
|
|
10
|
-
@@var << :after
|
|
11
|
-
@@var.must_equal [:before, :ibefore, :begin, :ibegin, :during, :iend, :end, :iafter, :after]
|
|
12
|
-
end
|
|
13
|
-
def around
|
|
14
|
-
@@var << :begin
|
|
15
|
-
yield
|
|
16
|
-
@@var << :end
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
class InnerNestedTest < OuterNestedTest
|
|
21
|
-
def setup
|
|
22
|
-
@@var << :ibefore
|
|
23
|
-
end
|
|
24
|
-
def teardown
|
|
25
|
-
@@var << :iafter
|
|
26
|
-
end
|
|
27
|
-
def around
|
|
28
|
-
@@var << :ibegin
|
|
29
|
-
yield
|
|
30
|
-
@@var << :iend
|
|
31
|
-
end
|
|
32
|
-
def test_nesting
|
|
33
|
-
@@var << :during
|
|
34
|
-
end
|
|
35
|
-
end
|