File: README.md

package info (click to toggle)
ruby-minitest-around 0.6.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 88 kB
  • sloc: ruby: 61; makefile: 2
file content (120 lines) | stat: -rw-r--r-- 2,596 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
[github]: https://github.com/splattael/minitest-around
[doc]: http://rubydoc.info/github/splattael/minitest-around/master/file/README.md
[gem]: https://rubygems.org/gems/minitest-around
[travis]: https://travis-ci.org/splattael/minitest-around

# minitest-around

[![Travis](https://img.shields.io/travis/splattael/minitest-around.svg?branch=master)][travis]
[![Gem Version](https://img.shields.io/gem/v/minitest-around.svg)][gem]

[Gem][gem] |
[Source][github]

Around block for minitest 5.X and later.

Alternative for setup/teardown dance.

## Installation

```Bash
gem install minitest-around
```

## Usage

### Unit tests

```Ruby
require 'minitest/autorun'
require 'minitest/around/unit'
require 'thread'

class MutexTest < Minitest::Test
  def around(&block)
    Mutex.new.synchronize(&block)
  end

  def test_synchronized
    # ...
  end
end
```

### Spec

<!-- example -->
```Ruby
require 'minitest/autorun'
require 'minitest/around/spec'
require 'tmpdir'

describe "inside new directory" do
  around do |test|
    Dir.mktmpdir do |dir|
      @dir = dir
      Dir.chdir(dir) do
        test.call
      end
    end
  end

  it "is in new directory" do
    assert_equal @dir, Dir.pwd.sub("/private/var/", "/var/")
  end
end
```
<!-- example -->

## Multiple before/after blocks

Minitest-around also enables the use of multiple before/after blocks, which normally don't work in minitest.

## Caveats

 - Test bodies won't be run if you don't test.call inside +around+.
 - around runs inside a Fiber, so use `Thread.get_thread_local` / `set_thread_local` instead of `Thread.current.[]`

### Minitest 5.X and later

`minitest-around` currently supports only `minitest` 5.X and later.

Please see the [mt4](https://github.com/splattael/minitest-around/tree/mt4) branch
for `minitest` 4.7.X support.


## License

[MIT License](http://www.opensource.org/licenses/mit-license.php)

## Authors

* [Peter Leitzen](https://github.com/splattael)

## [Contributors](https://github.com/splattael/minitest-around/graphs/contributors)

* [Michael Grosser](https://github.com/grosser)
* [Hendra Uzia](https://github.com/hendrauzia)
* [Rick Martínez](https://github.com/rickmzp)
* [Philip Nelson](https://github.com/pnelson)

## Contributing

1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Added some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request

## Test

```Bash
bundle exec rake test
```

## Release

```Bash
bundle exec rake bump:{patch|minor|major}
bundle exec rake release
```