minitest-matchers 1.1.3 → 1.2.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.
- data/README.txt +12 -0
- data/lib/minitest/matchers.rb +72 -7
- data/test/test_minitest_matchers.rb +32 -0
- metadata +11 -11
data/README.txt
CHANGED
@@ -80,6 +80,18 @@ For use with Rails check out (ValidAttribute + Capybara):
|
|
80
80
|
wont { have_valid(:title).when("", nil, "Bad") }
|
81
81
|
end
|
82
82
|
|
83
|
+
You can also register matcher so that it works similar to built-in
|
84
|
+
assertions and expectations. Note subject must be the first argument in assertion.
|
85
|
+
|
86
|
+
MiniTest::Unit::TestCase.register_matcher HaveContent, :have_content
|
87
|
+
MiniTest::Unit::TestCase.register_matcher :have_selector, :have_selector
|
88
|
+
|
89
|
+
assert_have_content page, "Hello"
|
90
|
+
assert_Have_selector page, :xpath, "//table/tr"
|
91
|
+
|
92
|
+
page.must_have_content "Hello"
|
93
|
+
page.must_Have_selector :xpath, "//table/tr"
|
94
|
+
|
83
95
|
== REQUIREMENTS:
|
84
96
|
|
85
97
|
* minitest >= 2.7.0
|
data/lib/minitest/matchers.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require "minitest/spec"
|
2
2
|
|
3
3
|
module MiniTest::Matchers
|
4
|
-
VERSION = "1.
|
4
|
+
VERSION = "1.2.0" # :nodoc:
|
5
5
|
end
|
6
6
|
|
7
7
|
module MiniTest
|
@@ -19,10 +19,10 @@ module MiniTest
|
|
19
19
|
result = matcher.matches? subject
|
20
20
|
|
21
21
|
msg = message(msg) do
|
22
|
-
if matcher.respond_to? :
|
23
|
-
matcher.failure_message
|
24
|
-
else
|
22
|
+
if matcher.respond_to? :failure_message_for_should
|
25
23
|
matcher.failure_message_for_should
|
24
|
+
else
|
25
|
+
matcher.failure_message
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
@@ -40,10 +40,10 @@ module MiniTest
|
|
40
40
|
|
41
41
|
def assert_wont matcher, subject, msg = nil
|
42
42
|
msg = message(msg) do
|
43
|
-
if matcher.respond_to? :
|
44
|
-
matcher.negative_failure_message
|
45
|
-
else
|
43
|
+
if matcher.respond_to? :failure_message_for_should_not
|
46
44
|
matcher.failure_message_for_should_not
|
45
|
+
else
|
46
|
+
matcher.negative_failure_message
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
@@ -136,6 +136,71 @@ class MiniTest::Spec
|
|
136
136
|
end
|
137
137
|
end
|
138
138
|
|
139
|
+
class MiniTest::Unit::TestCase
|
140
|
+
##
|
141
|
+
# Defines assert_* assetion and must_* expectation for a matcher
|
142
|
+
#
|
143
|
+
# Example:
|
144
|
+
#
|
145
|
+
# # Say you're implementing Capybara's HaveContent matcher
|
146
|
+
#
|
147
|
+
# class HaveContent
|
148
|
+
# # ...
|
149
|
+
# end
|
150
|
+
#
|
151
|
+
# MiniTest::Unit::TestCase.register_matcher HaveContent, :have_content
|
152
|
+
#
|
153
|
+
# class MyTest < Test::Unit::TestCase
|
154
|
+
# def test_index
|
155
|
+
# visit "/"
|
156
|
+
# assert_have_content page, "Hello"
|
157
|
+
# assert_have_selector page, :xpath, "//table/tr"
|
158
|
+
# end
|
159
|
+
# end
|
160
|
+
#
|
161
|
+
# describe "my test" do
|
162
|
+
# test "index" do
|
163
|
+
# visit "/"
|
164
|
+
# page.must_have_content "Hello"
|
165
|
+
# page.must_have_selector :xpath, "//table/tr"
|
166
|
+
#
|
167
|
+
# # if you set `page` to be implicit subject, following works too:
|
168
|
+
# must_have_content "Hello"
|
169
|
+
# end
|
170
|
+
# end
|
171
|
+
#
|
172
|
+
|
173
|
+
def self.register_matcher matcher, name, exp_name=name
|
174
|
+
define_method :"assert_#{name}" do |*args|
|
175
|
+
subject = args.shift
|
176
|
+
|
177
|
+
x = if Symbol === matcher
|
178
|
+
send matcher, *args
|
179
|
+
else
|
180
|
+
matcher.new(*args)
|
181
|
+
end
|
182
|
+
|
183
|
+
assert_must x, subject
|
184
|
+
end
|
185
|
+
|
186
|
+
Object.infect_an_assertion :"assert_#{name}", :"must_#{exp_name}", true
|
187
|
+
|
188
|
+
define_method :"refute_#{name}" do |*args|
|
189
|
+
subject = args.shift
|
190
|
+
|
191
|
+
x = if Symbol === matcher
|
192
|
+
send matcher, *args
|
193
|
+
else
|
194
|
+
matcher.new(*args)
|
195
|
+
end
|
196
|
+
|
197
|
+
assert_wont x, subject
|
198
|
+
end
|
199
|
+
|
200
|
+
Object.infect_an_assertion :"refute_#{name}", :"wont_#{exp_name}", true
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
139
204
|
class MiniTest::Spec # :nodoc:
|
140
205
|
include MiniTest::Matchers
|
141
206
|
end
|
@@ -43,6 +43,38 @@ describe MiniTest::Unit::TestCase do
|
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
|
+
describe MiniTest::Unit::TestCase, :register_matcher do
|
47
|
+
MiniTest::Unit::TestCase.register_matcher KindOfMatcher, :my_kind_of, :be_my_kind_of
|
48
|
+
MiniTest::Unit::TestCase.register_matcher :be_kind_of, :meth_kind_of, :meth_my_kind_of
|
49
|
+
|
50
|
+
it "needs to verify assert_<matcher>" do
|
51
|
+
assert_my_kind_of("", String).must_equal true
|
52
|
+
proc { assert_my_kind_of [], String }.must_raise MiniTest::Assertion
|
53
|
+
end
|
54
|
+
|
55
|
+
it "needs to verify must_<matcher>" do
|
56
|
+
"".must_be_my_kind_of(String).must_equal true
|
57
|
+
proc { [].must_be_my_kind_of String }.must_raise MiniTest::Assertion
|
58
|
+
end
|
59
|
+
|
60
|
+
it "needs to verify refute_<matcher>" do
|
61
|
+
refute_my_kind_of("", Array).must_equal false
|
62
|
+
proc { refute_my_kind_of [], Array }.must_raise MiniTest::Assertion
|
63
|
+
end
|
64
|
+
|
65
|
+
it "needs to verify wont<matcher>" do
|
66
|
+
"".wont_be_my_kind_of(Array).must_equal false
|
67
|
+
proc { [].wont_be_my_kind_of(Array) }.must_raise MiniTest::Assertion
|
68
|
+
end
|
69
|
+
|
70
|
+
it "accepts method as matcher" do
|
71
|
+
assert_meth_kind_of("", String).must_equal true
|
72
|
+
proc { assert_meth_kind_of [], String }.must_raise MiniTest::Assertion
|
73
|
+
refute_meth_kind_of("", Array).must_equal false
|
74
|
+
proc { refute_my_kind_of [], Array }.must_raise MiniTest::Assertion
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
46
78
|
describe MiniTest::Spec do
|
47
79
|
it "needs to verify must" do
|
48
80
|
[].must(be_kind_of(Array)).must_equal true
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: minitest-matchers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,11 +10,11 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2012-01-22 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: minitest
|
17
|
-
requirement: &
|
17
|
+
requirement: &70195242850820 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,21 +22,21 @@ dependencies:
|
|
22
22
|
version: 2.5.0
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *70195242850820
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
|
-
name:
|
28
|
-
requirement: &
|
27
|
+
name: rdoc
|
28
|
+
requirement: &70195242850000 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ~>
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '3.10'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *70195242850000
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: hoe
|
39
|
-
requirement: &
|
39
|
+
requirement: &70195242849340 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ~>
|
@@ -44,7 +44,7 @@ dependencies:
|
|
44
44
|
version: '2.12'
|
45
45
|
type: :development
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *70195242849340
|
48
48
|
description: ! 'minitest-matchers adds support for RSpec/Shoulda-style matchers to
|
49
49
|
|
50
50
|
minitest/unit and minitest/spec.
|
@@ -101,7 +101,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
101
101
|
version: '0'
|
102
102
|
requirements: []
|
103
103
|
rubyforge_project: minitest-matchers
|
104
|
-
rubygems_version: 1.8.
|
104
|
+
rubygems_version: 1.8.11
|
105
105
|
signing_key:
|
106
106
|
specification_version: 3
|
107
107
|
summary: minitest-matchers adds support for RSpec/Shoulda-style matchers to minitest/unit
|