Skip to content

Commit

Permalink
Update for Minitest 5.0.x
Browse files Browse the repository at this point in the history
General updates for Minitest 5.0 compatibility and updates for implicit
subject testing.

* Update dependency to ~> 5.0
* MiniTest -> Minitest
* MiniTest::Unit::TestCase -> Minitest::Test
* Remove anonymous classes for testing the implicit subject
* Add tests for `.must` and `.wont`
* Add true cases for `must` and `wont` with implicit subject
  • Loading branch information
elskwid committed Jun 30, 2013
1 parent 72aa0a0 commit 0de37c4
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 46 deletions.
4 changes: 2 additions & 2 deletions Gemfile.lock
Expand Up @@ -2,12 +2,12 @@ PATH
remote: .
specs:
minitest-matchers (1.3.0)
minitest (~> 4.7)
minitest (~> 5.0)

GEM
remote: https://rubygems.org/
specs:
minitest (4.7.5)
minitest (5.0.6)
rake (10.1.0)

PLATFORMS
Expand Down
14 changes: 7 additions & 7 deletions lib/minitest/matchers.rb
Expand Up @@ -53,7 +53,7 @@ def assert_wont matcher, subject, msg = nil

module Expectations
##
# See MiniTest::Assertions#assert_must
# See Minitest::Assertions#assert_must
#
# user.must have_valid(:email).when("user@example.com")
#
Expand All @@ -62,7 +62,7 @@ module Expectations
infect_an_assertion :assert_must, :must

##
# See MiniTest::Assertions#assert_wont
# See Minitest::Assertions#assert_wont
#
# user.wont have_valid(:email).when("bad@email")
#
Expand All @@ -72,7 +72,7 @@ module Expectations
end
end

class MiniTest::Spec
class Minitest::Spec
##
# Expects that matcher matches the subject
#
Expand Down Expand Up @@ -132,7 +132,7 @@ def wont(*args, &block)
end
end

class MiniTest::Unit::TestCase
class Minitest::Test
##
# Defines assert_* assertion and must_* expectation for a matcher
#
Expand All @@ -144,7 +144,7 @@ class MiniTest::Unit::TestCase
# # ...
# end
#
# MiniTest::Unit::TestCase.register_matcher HaveContent, :have_content
# Minitest::Unit::TestCase.register_matcher HaveContent, :have_content
#
# class MyTest < Test::Unit::TestCase
# def test_index
Expand Down Expand Up @@ -197,6 +197,6 @@ def self.register_matcher matcher, name, exp_name=name
end
end

class MiniTest::Spec # :nodoc:
include MiniTest::Matchers
class Minitest::Spec # :nodoc:
include Minitest::Matchers
end
2 changes: 1 addition & 1 deletion lib/minitest/matchers/version.rb
@@ -1,4 +1,4 @@
module MiniTest
module Minitest
module Matchers
VERSION = File.read(File.expand_path("../../../../VERSION", __FILE__)).strip
end
Expand Down
4 changes: 2 additions & 2 deletions minitest-matchers.gemspec
Expand Up @@ -4,7 +4,7 @@ require "minitest/matchers/version"

Gem::Specification.new do |s|
s.name = "minitest-matchers"
s.version = MiniTest::Matchers::VERSION
s.version = Minitest::Matchers::VERSION
s.authors = ["Wojciech Mach", "Ryan Davis"]
s.email = ["wojtek@wojtekmach.pl", "ryand-ruby@zenspider.com"]
s.homepage = ""
Expand All @@ -18,7 +18,7 @@ Gem::Specification.new do |s|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]

s.add_dependency "minitest", "~> 4.7"
s.add_dependency "minitest", "~> 5.0"

s.add_development_dependency "rake"
end
60 changes: 26 additions & 34 deletions test/minitest/matchers_test.rb
@@ -1,5 +1,4 @@
gem "minitest"
require "minitest/spec"
require "minitest/autorun"
require "minitest/matchers"

Expand Down Expand Up @@ -31,82 +30,75 @@ def be_kind_of klass
KindOfMatcher.new klass
end

describe MiniTest::Unit::TestCase do
describe Minitest::Test do
it "needs to verify assert_must" do
assert_must(be_kind_of(Array), []).must_equal true
proc { assert_must be_kind_of(String), [] }.must_raise MiniTest::Assertion
proc { assert_must be_kind_of(String), [] }.must_raise Minitest::Assertion
end

it "needs to verify assert_wont" do
assert_wont(be_kind_of(String), []).must_equal false
proc { assert_wont be_kind_of(Array), [] }.must_raise MiniTest::Assertion
proc { assert_wont be_kind_of(Array), [] }.must_raise Minitest::Assertion
end
end

describe MiniTest::Unit::TestCase, :register_matcher do
MiniTest::Unit::TestCase.register_matcher KindOfMatcher, :my_kind_of, :be_my_kind_of
MiniTest::Unit::TestCase.register_matcher :be_kind_of, :meth_kind_of, :meth_my_kind_of
describe Minitest::Test, :register_matcher do
Minitest::Test.register_matcher KindOfMatcher, :my_kind_of, :be_my_kind_of
Minitest::Test.register_matcher :be_kind_of, :meth_kind_of, :meth_my_kind_of

it "needs to verify assert_<matcher>" do
assert_my_kind_of("", String).must_equal true
proc { assert_my_kind_of [], String }.must_raise MiniTest::Assertion
proc { assert_my_kind_of [], String }.must_raise Minitest::Assertion
end

it "needs to verify must_<matcher>" do
"".must_be_my_kind_of(String).must_equal true
proc { [].must_be_my_kind_of String }.must_raise MiniTest::Assertion
proc { [].must_be_my_kind_of String }.must_raise Minitest::Assertion
end

it "needs to verify refute_<matcher>" do
refute_my_kind_of("", Array).must_equal false
proc { refute_my_kind_of [], Array }.must_raise MiniTest::Assertion
proc { refute_my_kind_of [], Array }.must_raise Minitest::Assertion
end

it "needs to verify wont<matcher>" do
"".wont_be_my_kind_of(Array).must_equal false
proc { [].wont_be_my_kind_of(Array) }.must_raise MiniTest::Assertion
proc { [].wont_be_my_kind_of(Array) }.must_raise Minitest::Assertion
end

it "accepts method as matcher" do
assert_meth_kind_of("", String).must_equal true
proc { assert_meth_kind_of [], String }.must_raise MiniTest::Assertion
proc { assert_meth_kind_of [], String }.must_raise Minitest::Assertion
refute_meth_kind_of("", Array).must_equal false
proc { refute_my_kind_of [], Array }.must_raise MiniTest::Assertion
proc { refute_my_kind_of [], Array }.must_raise Minitest::Assertion
end
end

describe MiniTest::Spec do
describe Minitest::Spec do
it "needs to verify must" do
[].must(be_kind_of(Array)).must_equal true
proc { [].must be_kind_of(String) }.must_raise MiniTest::Assertion
proc { [].must be_kind_of(String) }.must_raise Minitest::Assertion
end

it "needs to verify wont" do
[].wont(be_kind_of(String)).must_equal false
proc { [].wont be_kind_of(Array) }.must_raise MiniTest::Assertion
proc { [].wont be_kind_of(Array) }.must_raise Minitest::Assertion
end

it "needs to verify must with implicit subject" do
spec_class = Class.new(MiniTest::Spec) do
subject { [1, 2, 3] }
describe "implicit subject" do
subject { [1, 2, 3] }

it { must be_kind_of(String) }
end

spec = spec_class.new("A spec")

proc { spec.send spec_class.test_methods.first}.must_raise MiniTest::Assertion
end
must { be_kind_of(Array) }
wont { be_kind_of(String) }

it "needs to verify wont with implicit subject" do
spec_class = Class.new(MiniTest::Spec) do
subject { [1, 2, 3] }

it { wont be_kind_of(Array) }
it "verifies must" do
must be_kind_of(Array)
proc { must be_kind_of(String) }.must_raise Minitest::Assertion
end

spec = spec_class.new("A spec")

proc { spec.send spec_class.test_methods.first}.must_raise MiniTest::Assertion
it "verifies wont" do
wont be_kind_of(String)
proc { wont be_kind_of(Array) }.must_raise Minitest::Assertion
end
end
end

0 comments on commit 0de37c4

Please sign in to comment.