minitest-around

0.5.0last stable release 6 years ago
Complexity Score
Low
Open Issues
2
Dependent Projects
48
Weekly Downloadsglobal
115

License

  • MIT
    • Yesattribution
    • Permissivelinking
    • Permissivedistribution
    • Permissivemodification
    • Nopatent grant
    • Yesprivate use
    • Permissivesublicensing
    • Notrademark grant

Downloads

Readme

minitest-around

Gem | Source

Around block for minitest 5.X.

Alternative for setup/teardown dance.

Installation

gem install minitest-around

Usage

Unit tests

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

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

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 only

minitest-around currently supports only minitest 5.X.

Please see the mt4 branch for minitest 4.7.X support.

License

MIT License

Authors

  • Peter Leitzen

Contributors

  • Michael Grosser
  • Hendra Uzia
  • Rick Martínez
  • Philip Nelson

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

bundle exec rake test

Release

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

Dependencies

CVE IssuesActive
0
Scorecards Score
3.20
Test Coverage
No Data
Follows Semver
No
Github Stars
41
Dependenciestotal
5
DependenciesOutdated
1
DependenciesDeprecated
0
Threat Modelling
No
Repo Audits
No

Learn how to distribute minitest-around in your own private RubyGems registry

gem install minitest-around
Processing...
Done

19 Releases

RubyGems on Cloudsmith

Getting started with RubyGems on Cloudsmith is fast and easy.