Module: Assay::MiniTest::Extensions
- Included in:
- Extensions
- Defined in:
- lib/assay-minitest/extensions.rb
Overview
This module provides extensions for MiniTest compatiblity.
The set is not fully compataible, but provides most of MiniTest extensions.
Compatability will improve with time.
Instance Method Summary collapse
-
#must_be(operator, argument = nil, msg = nil) ⇒ Object
Passes it operator with optional argument returns successfully.
-
#must_be_empty(msg = nil) ⇒ Object
Passes if object is empty.
-
#must_be_equivalent_to(criterion, msg = nil) ⇒ Object
(also: #must_eql)
Passes if ‘criterion.eql?(actual)`.
-
#must_be_false(msg = nil) ⇒ Object
Passed if object is
false
. -
#must_be_instance_of(cls, msg = nil) ⇒ Object
Passes if object is an instance of class.
-
#must_be_kind_of(cls, msg = nil) ⇒ Object
Passes if object is a kind of class.
-
#must_be_like(exp, msg = nil) ⇒ Object
Passes if object is like criterion.
-
#must_be_nil(msg = nil) ⇒ Object
Passed if object is
nil
. -
#must_be_same_as(exp, msg = nil) ⇒ Object
Passes if ‘self` is the same exact object as expected.
-
#must_be_true(msg = nil) ⇒ Object
Passed if object is
true
. -
#must_be_within_delta(exp, delta, msg = nil) ⇒ Object
Passes if expected and actual are equal within delta tolerance.
-
#must_equal(exp, msg = nil) ⇒ Object
Passes if expected == +actual.
-
#must_include(object, msg = nil) ⇒ Object
Passes if ‘self.include?(object)`.
-
#must_match(exp, msg = nil) ⇒ Object
Passes if object matches pattern using ‘#=~` method.
-
#must_output(pattern, msg = nil) ⇒ Object
Passes if output matches
pattern
. -
#must_raise(exp, msg = nil, call = nil) ⇒ Object
Passes if the procedure raises a given exception.
-
#must_respond_to(method, msg = nil) ⇒ Object
Passes if
object
respond_to?methods
. -
#must_satisfy(msg = nil, &block) ⇒ Object
Passes if the block yields successfully.
-
#must_send(send_array, msg = nil) ⇒ Object
Passes if method call returns successfully.
-
#must_throw(sym, msg = nil) ⇒ Object
Passes if the block throws expected_symbol.
-
#wont_be(operator, argument = nil, msg = nil) ⇒ Object
Passes it operator with optional argument returns negatively.
-
#wont_be_empty(msg = nil) ⇒ Object
Passes if object is not empty.
-
#wont_be_equivalent_to(criterion, msg = nil) ⇒ Object
(also: #wont_eql)
Passes if NOT ‘criterion.eql?(actual)`.
-
#wont_be_false(msg = nil) ⇒ Object
Passed if object is not
false
. -
#wont_be_instance_of(cls, msg = nil) ⇒ Object
Passes if object is not an instance of class.
-
#wont_be_kind_of(cls, msg = nil) ⇒ Object
Passes if object is not a kind of class.
-
#wont_be_like(exp, msg = nil) ⇒ Object
Passes if object is not like criterion using CompareAssay.
-
#wont_be_nil(msg = nil) ⇒ Object
Passed if object is not
nil
. -
#wont_be_same_as(exp, msg = nil) ⇒ Object
Passes if actual is not the same exact object as expected.
-
#wont_be_true(msg = nil) ⇒ Object
Passed if object is not
true
. -
#wont_be_within_delta(exp, delta, msg = nil) ⇒ Object
Passes if expected and actual are equal not within delta tolerance.
-
#wont_equal(exp, msg = nil) ⇒ Object
Passes if expected != actual.
-
#wont_include(object, msg = nil) ⇒ Object
Passes if ‘self.include?(object)`.
-
#wont_match(exp, msg = nil) ⇒ Object
Passes if object does not match pattern using ‘#=~` method.
-
#wont_raise(exp, msg = nil, call = nil) ⇒ Object
Passes if the procedure *does not* raise a given exceptions.
-
#wont_respond_to(method, msg = nil) ⇒ Object
Passes if
object
does not respond_to?methods
. -
#wont_satisfy(msg = nil, &block) ⇒ Object
Passes if the block does not yield successfully.
-
#wont_send(send_array, msg = nil) ⇒ Object
Passes if method call does not return successfully.
-
#wont_throw(sym, msg = nil) ⇒ Object
Passes if the block throws expected_symbol.
Instance Method Details
#must_be(operator, argument = nil, msg = nil) ⇒ Object
Passes it operator with optional argument returns successfully.
10.must_be :>, 4
10.must_be :even?
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/assay-minitest/extensions.rb', line 20 def must_be(operator, argument=nil, msg=nil) if argument ExecutionAssay.assert!(:message=>msg) do __send__(operator, argument) end else ExecutionAssay.assert!(:message=>msg) do __send__(operator) end end end |
#must_be_empty(msg = nil) ⇒ Object
Passes if object is empty.
object.must_be_empty
103 104 105 |
# File 'lib/assay-minitest/extensions.rb', line 103 def must_be_empty(msg=nil) EmptyAssay.assert!(self, :message=>msg, :backtrace=>caller) end |
#must_be_equivalent_to(criterion, msg = nil) ⇒ Object Also known as: must_eql
Passes if ‘criterion.eql?(actual)`.
Note that the ordering of arguments is important, since a helpful error message is generated when this one fails that tells you the values of expected and actual.
'MY STRING'.must_be_equivalent_to('my string'.upcase)
375 376 377 |
# File 'lib/assay-minitest/extensions.rb', line 375 def must_be_equivalent_to(criterion, msg=nil) EqualityAssay.assert!(self, criterion, :message=>msg, :backtrace=>caller) end |
#must_be_false(msg = nil) ⇒ Object
Passed if object is false
.
197 198 199 |
# File 'lib/assay-minitest/extensions.rb', line 197 def must_be_false(msg=nil) FalseAssay.assert!(self, :message=>msg, :backtrace=>caller) end |
#must_be_instance_of(cls, msg = nil) ⇒ Object
Passes if object is an instance of class.
'foo'.must_be_instance_of(String)
241 242 243 |
# File 'lib/assay-minitest/extensions.rb', line 241 def must_be_instance_of(cls, msg=nil) InstanceAssay.assert!(self, cls, :message=>msg, :backtrace=>caller) end |
#must_be_kind_of(cls, msg = nil) ⇒ Object
Passes if object is a kind of class.
assert_kind_of(Object, 'foo')
263 264 265 |
# File 'lib/assay-minitest/extensions.rb', line 263 def must_be_kind_of(cls, msg=nil) KindAssay.assert!(self, cls, :message=>msg, :backtrace=>caller) end |
#must_be_like(exp, msg = nil) ⇒ Object
Passes if object is like criterion.
object.must_be_like(criterion)
59 60 61 |
# File 'lib/assay-minitest/extensions.rb', line 59 def must_be_like(exp, msg=nil) LikeAssay.assert!(self, exp, :message=>msg, :backtrace=>caller) end |
#must_be_nil(msg = nil) ⇒ Object
Passed if object is nil
.
305 306 307 |
# File 'lib/assay-minitest/extensions.rb', line 305 def must_be_nil(msg=nil) NilAssay.assert!(self, :message=>msg, :backtrace=>caller) end |
#must_be_same_as(exp, msg = nil) ⇒ Object
Passes if ‘self` is the same exact object as expected.
object.must_be_same_as(object)
219 220 221 |
# File 'lib/assay-minitest/extensions.rb', line 219 def must_be_same_as(exp, msg=nil) IdentityAssay.assert!(self, exp, :message=>msg, :backtrace=>caller) end |
#must_be_true(msg = nil) ⇒ Object
Passed if object is true
.
object.must_be_true
427 428 429 |
# File 'lib/assay-minitest/extensions.rb', line 427 def must_be_true(msg=nil) TrueAssay.assert!(self, :message=>msg, :backtrace=>caller) end |
#must_be_within_delta(exp, delta, msg = nil) ⇒ Object
Passes if expected and actual are equal within delta tolerance.
assert_in_delta 0.05, (50000.0 / 10**6), 0.00001
81 82 83 |
# File 'lib/assay-minitest/extensions.rb', line 81 def must_be_within_delta(exp, delta, msg=nil) WithinAssay.assert!(self, exp, delta, :message=>msg, :backtrace=>caller) end |
#must_equal(exp, msg = nil) ⇒ Object
Passes if expected == +actual.
Note that the ordering of arguments is important, since a helpful error message is generated when this one fails that tells you the values of expected and actual.
'MY STRING'.must_equal('my string'.upcase)
129 130 131 |
# File 'lib/assay-minitest/extensions.rb', line 129 def must_equal(exp, msg=nil) EqualAssay.assert!(self, exp, :message=>msg, :backtrace=>caller) end |
#must_include(object, msg = nil) ⇒ Object
Passes if ‘self.include?(object)`.
447 448 449 |
# File 'lib/assay-minitest/extensions.rb', line 447 def must_include(object, msg=nil) IncludeAssay.assert!(self, object, :message=>msg, :backtrace=>caller) end |
#must_match(exp, msg = nil) ⇒ Object
Passes if object matches pattern using ‘#=~` method.
'one 2 three'.must_match(/two/)
285 286 287 |
# File 'lib/assay-minitest/extensions.rb', line 285 def must_match(exp, msg=nil) MatchAssay.assert!(self, exp, :message=>msg, :backtrace=>caller) end |
#must_output(pattern, msg = nil) ⇒ Object
Passes if output matches pattern
.
468 469 470 |
# File 'lib/assay-minitest/extensions.rb', line 468 def must_output(pattern, msg=nil) OutputAssay.assert!(pattern, :message=>msg, :backtrace=>caller, &self) end |
#must_raise(exp, msg = nil, call = nil) ⇒ Object
Passes if the procedure raises a given exception.
lambda{ raise 'Boom!!!' }.must_raise(RuntimeError)
327 328 329 |
# File 'lib/assay-minitest/extensions.rb', line 327 def must_raise(exp, msg=nil, call=nil) RaiseAssay.assert!(exp, msg=nil, call=nil, &self) end |
#must_respond_to(method, msg = nil) ⇒ Object
Passes if object
respond_to? methods
.
'bugbear'.must_respond_to(:slice)
349 350 351 |
# File 'lib/assay-minitest/extensions.rb', line 349 def must_respond_to(method, msg=nil) RespondAssay.assert!(self, method, :message=>msg, :backtrace=>caller) end |
#must_satisfy(msg = nil, &block) ⇒ Object
Passes if the block yields successfully.
5.must_satisfy{ |x| x > 3 }
177 178 179 |
# File 'lib/assay-minitest/extensions.rb', line 177 def must_satisfy(msg=nil, &block) ExecutionAssay.assert!(self, :message=>msg, :backtrace=>caller, &block) end |
#must_send(send_array, msg = nil) ⇒ Object
Passes if method call returns successfully.
"string".must_send([:upcase], "Doesn't upcase!")
151 152 153 154 155 |
# File 'lib/assay-minitest/extensions.rb', line 151 def must_send(send_array, msg=nil) ExecutionAssay.assert!(:message=>msg, :backtrace=>caller) do self.__send__(*send_array) end end |
#must_throw(sym, msg = nil) ⇒ Object
Passes if the block throws expected_symbol
assert_throws :done do
throw :done
end
403 404 405 |
# File 'lib/assay-minitest/extensions.rb', line 403 def must_throw(sym, msg=nil) ThrowAssay.assert!(sym, :message=>msg, :backtrace=>caller, &self) end |
#wont_be(operator, argument = nil, msg = nil) ⇒ Object
Passes it operator with optional argument returns negatively.
10.wont_be :>, 20
10.wont_be :odd?
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/assay-minitest/extensions.rb', line 40 def wont_be(operator, argument=nil, msg=nil) if argument ExecutionAssay.refute!(:message=>msg) do self.__send__(operator, argument) end else ExecutionAssay.refute!(:message=>msg) do self.__send__(operator) end end end |
#wont_be_empty(msg = nil) ⇒ Object
Passes if object is not empty.
object.wont_be_empty
114 115 116 |
# File 'lib/assay-minitest/extensions.rb', line 114 def wont_be_empty(msg=nil) EmptyAssay.refute!(self, :message=>msg, :backtrace=>caller) end |
#wont_be_equivalent_to(criterion, msg = nil) ⇒ Object Also known as: wont_eql
Passes if NOT ‘criterion.eql?(actual)`.
'MY STRING'.wont_be_equivalent_to('some other string')
388 389 390 |
# File 'lib/assay-minitest/extensions.rb', line 388 def wont_be_equivalent_to(criterion, msg=nil) EqualityAssay.refute!(self, criterion, :message=>msg, :backtrace=>caller) end |
#wont_be_false(msg = nil) ⇒ Object
Passed if object is not false
.
assert_not_false(false)
208 209 210 |
# File 'lib/assay-minitest/extensions.rb', line 208 def wont_be_false(msg=nil) FalseAssay.refute!(self, :message=>msg, :backtrace=>caller) end |
#wont_be_instance_of(cls, msg = nil) ⇒ Object
Passes if object is not an instance of class.
'foo'.wont_be_instance_of(Integer)
252 253 254 |
# File 'lib/assay-minitest/extensions.rb', line 252 def wont_be_instance_of(cls, msg=nil) InstanceAssay.refute!(self, cls, :message=>msg, :backtrace=>caller) end |
#wont_be_kind_of(cls, msg = nil) ⇒ Object
Passes if object is not a kind of class.
assert_not_kind_of(Object, 'foo')
274 275 276 |
# File 'lib/assay-minitest/extensions.rb', line 274 def wont_be_kind_of(cls, msg=nil) KindAssay.refute!(self, cls, :message=>msg, :backtrace=>caller) end |
#wont_be_like(exp, msg = nil) ⇒ Object
Passes if object is not like criterion using CompareAssay.
object.wont_be_like(criterion)
70 71 72 |
# File 'lib/assay-minitest/extensions.rb', line 70 def wont_be_like(exp, msg=nil) LikeAssay.refute!(self, exp, :message=>msg, :backtrace=>caller) end |
#wont_be_nil(msg = nil) ⇒ Object
Passed if object is not nil
.
assert_not_nil(true)
316 317 318 |
# File 'lib/assay-minitest/extensions.rb', line 316 def wont_be_nil(msg=nil) NilAssay.refute!(self, :message=>msg, :backtrace=>caller) end |
#wont_be_same_as(exp, msg = nil) ⇒ Object
Passes if actual is not the same exact object as expected.
object.wont_be_same_as(other)
230 231 232 |
# File 'lib/assay-minitest/extensions.rb', line 230 def wont_be_same_as(exp, msg=nil) IdentityAssay.refute!(self, exp, :message=>msg, :backtrace=>caller) end |
#wont_be_true(msg = nil) ⇒ Object
Passed if object is not true
.
object.wont_be_true
438 439 440 |
# File 'lib/assay-minitest/extensions.rb', line 438 def wont_be_true(msg=nil) TrueAssay.refute!(self, :message=>msg, :backtrace=>caller) end |
#wont_be_within_delta(exp, delta, msg = nil) ⇒ Object
Passes if expected and actual are equal not within delta tolerance.
assert_not_in_delta 0.05, (50000.0 / 10**6), 0.00001
92 93 94 |
# File 'lib/assay-minitest/extensions.rb', line 92 def wont_be_within_delta(exp, delta, msg=nil) WithinAssay.refute!(self, exp, delta, :message=>msg, :backtrace=>caller) end |
#wont_equal(exp, msg = nil) ⇒ Object
Passes if expected != actual
'some string'.wont_equal('some other string')
140 141 142 |
# File 'lib/assay-minitest/extensions.rb', line 140 def wont_equal(exp, msg=nil) EqualAssay.refute!(self, exp, :message=>msg, :backtrace=>caller) end |
#wont_include(object, msg = nil) ⇒ Object
Passes if ‘self.include?(object)`.
456 457 458 |
# File 'lib/assay-minitest/extensions.rb', line 456 def wont_include(object, msg=nil) IncludeAssay.refute!(self, object, :message=>msg, :backtrace=>caller) end |
#wont_match(exp, msg = nil) ⇒ Object
Passes if object does not match pattern using ‘#=~` method.
'one 2 three'.wont_match(/two/)
296 297 298 |
# File 'lib/assay-minitest/extensions.rb', line 296 def wont_match(exp, msg=nil) MatchAssay.refute!(self, exp, :message=>msg, :backtrace=>caller) end |
#wont_raise(exp, msg = nil, call = nil) ⇒ Object
Passes if the procedure *does not* raise a given exceptions.
lambda{ raise 'Boom!!!' }.wont_raise(IOError)
338 339 340 |
# File 'lib/assay-minitest/extensions.rb', line 338 def wont_raise(exp, msg=nil, call=nil) RaiseAssay.refute!(exp, msg, call, &self) end |
#wont_respond_to(method, msg = nil) ⇒ Object
Passes if object
does not respond_to? methods
.
'bugbear'.wont_respond_to(:slice)
360 361 362 |
# File 'lib/assay-minitest/extensions.rb', line 360 def wont_respond_to(method, msg=nil) RespondAssay.refute!(self, method, :message=>msg, :backtrace=>caller) end |
#wont_satisfy(msg = nil, &block) ⇒ Object
Passes if the block does not yield successfully.
5.wont_satisfy{ |x| x < 3 }
188 189 190 |
# File 'lib/assay-minitest/extensions.rb', line 188 def wont_satisfy(msg=nil, &block) ExecutionAssay.refute!(self, :message=>msg, :backtrace=>caller, &block) end |
#wont_send(send_array, msg = nil) ⇒ Object
Passes if method call does not return successfully.
"string".wont_send([:upcase], "Damn you, Uppercase!")
164 165 166 167 168 |
# File 'lib/assay-minitest/extensions.rb', line 164 def wont_send(send_array, msg=nil) ExecutionAssay.refute!(:message=>msg, :backtrace=>caller) do self.__send__(*send_array) end end |
#wont_throw(sym, msg = nil) ⇒ Object
Passes if the block throws expected_symbol
refute_throws :done do
throw :chimp
end
416 417 418 |
# File 'lib/assay-minitest/extensions.rb', line 416 def wont_throw(sym, msg=nil) ThrowAssay.refute!(sym, :message=>msg, :backtrace=>caller, &self) end |