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

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?

Raises:

  • ExecutionAssay



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

Raises:

  • EmptyAssay



125
126
127
# File 'lib/assay/minitest/extensions.rb', line 125

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)

Raises:

  • EqualityAssay



397
398
399
# File 'lib/assay/minitest/extensions.rb', line 397

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.

Raises:

  • FalseAssay



219
220
221
# File 'lib/assay/minitest/extensions.rb', line 219

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)

Raises:

  • InstanceAssay



263
264
265
# File 'lib/assay/minitest/extensions.rb', line 263

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')

Raises:

  • KindAssay



285
286
287
# File 'lib/assay/minitest/extensions.rb', line 285

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)

Raises:

  • LikeAssay



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.

Raises:

  • NilAssay



327
328
329
# File 'lib/assay/minitest/extensions.rb', line 327

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)

Raises:

  • IdentityAssay



241
242
243
# File 'lib/assay/minitest/extensions.rb', line 241

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

Raises:

  • TrueAssay



449
450
451
# File 'lib/assay/minitest/extensions.rb', line 449

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 absolute delta tolerance.

0.05.must_be_within_delta (50000.0 / 10**6), 0.00001

Raises:

  • WithinAssay



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_be_within_epsilon(exp, epsilon, msg = nil) ⇒ Object

Passes if expected and actual are equal within relative epsilon tolerance.

0.05.must_be_within_epsilon (50000.0 / 10**6), 0.00001

Raises:

  • CloseAssay



103
104
105
# File 'lib/assay/minitest/extensions.rb', line 103

def must_be_within_epsilon(exp, epsilon, msg=nil)
  CloseAssay.assert!(self, exp, epsilon, :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)

Raises:

  • EqualAssay



151
152
153
# File 'lib/assay/minitest/extensions.rb', line 151

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).

Raises:

  • IncludeAssay



469
470
471
# File 'lib/assay/minitest/extensions.rb', line 469

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/)

Raises:

  • MatchAssay



307
308
309
# File 'lib/assay/minitest/extensions.rb', line 307

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.

Examples:

proc{ puts "fun!" }.must_output('fun!')

Raises:

  • OutputAssay



490
491
492
# File 'lib/assay/minitest/extensions.rb', line 490

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)

Raises:

  • RaiseAssay



349
350
351
# File 'lib/assay/minitest/extensions.rb', line 349

def must_raise(exp, msg=nil, call=nil)
  RaiseAssay.assert!(exp, :message=>msg, :backtrace=>(call || caller), &self)
end

#must_respond_to(method, msg = nil) ⇒ Object

Passes if object respond_to? methods.

'bugbear'.must_respond_to(:slice)

Raises:

  • RespondAssay



371
372
373
# File 'lib/assay/minitest/extensions.rb', line 371

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 }

Raises:

  • ExecutionAssay



199
200
201
# File 'lib/assay/minitest/extensions.rb', line 199

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!")

Raises:

  • ExecutionAssay



173
174
175
176
177
# File 'lib/assay/minitest/extensions.rb', line 173

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

Raises:

  • ThrowAssay



425
426
427
# File 'lib/assay/minitest/extensions.rb', line 425

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?

Raises:

  • ExecutionAssay



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

Raises:

  • EmptyAssay



136
137
138
# File 'lib/assay/minitest/extensions.rb', line 136

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')

Raises:

  • EqualityAssay



410
411
412
# File 'lib/assay/minitest/extensions.rb', line 410

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)

Raises:

  • FalseAssay



230
231
232
# File 'lib/assay/minitest/extensions.rb', line 230

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)

Raises:

  • InstanceAssay



274
275
276
# File 'lib/assay/minitest/extensions.rb', line 274

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')

Raises:

  • KindAssay



296
297
298
# File 'lib/assay/minitest/extensions.rb', line 296

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)

Raises:

  • LikeAssay



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)

Raises:

  • NilAssay



338
339
340
# File 'lib/assay/minitest/extensions.rb', line 338

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)

Raises:

  • IdentityAssay



252
253
254
# File 'lib/assay/minitest/extensions.rb', line 252

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

Raises:

  • TrueAssay



460
461
462
# File 'lib/assay/minitest/extensions.rb', line 460

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 NOT equal within absolute delta tolerance.

0.05.wont_be_within_delta (50000.0 / 10**6), 0.00001

Raises:

  • WithinAssay



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_be_within_epsilon(exp, epsilon, msg = nil) ⇒ Object

Passes if expected and actual are NOT equal within relative epsilon tolerance.

0.05.wont_be_within_epsilon (50000.0 / 10**6), 0.00001

Raises:

  • CloseAssay



114
115
116
# File 'lib/assay/minitest/extensions.rb', line 114

def wont_be_within_epsilon(exp, epsilon, msg=nil)
  WithinAssay.refute!(self, exp, epsilon, :message=>msg, :backtrace=>caller)
end

#wont_equal(exp, msg = nil) ⇒ Object

Passes if expected != actual

'some string'.wont_equal('some other string')

Raises:

  • EqualAssay



162
163
164
# File 'lib/assay/minitest/extensions.rb', line 162

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).

Raises:

  • IncludeAssay



478
479
480
# File 'lib/assay/minitest/extensions.rb', line 478

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/)

Raises:

  • MatchAssay



318
319
320
# File 'lib/assay/minitest/extensions.rb', line 318

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)

Raises:

  • RaiseAssay



360
361
362
# File 'lib/assay/minitest/extensions.rb', line 360

def wont_raise(exp, msg=nil, call=nil)
  RaiseAssay.refute!(exp, :message=>msg, :backtrace=>(call || caller), &self)
end

#wont_respond_to(method, msg = nil) ⇒ Object

Passes if object does not respond_to? methods.

'bugbear'.wont_respond_to(:slice)

Raises:

  • RespondAssay



382
383
384
# File 'lib/assay/minitest/extensions.rb', line 382

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 }

Raises:

  • ExecutionAssay



210
211
212
# File 'lib/assay/minitest/extensions.rb', line 210

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!")

Raises:

  • ExecutionAssay



186
187
188
189
190
# File 'lib/assay/minitest/extensions.rb', line 186

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

Raises:

  • ThrowAssay



438
439
440
# File 'lib/assay/minitest/extensions.rb', line 438

def wont_throw(sym, msg=nil)
  ThrowAssay.refute!(sym, :message=>msg, :backtrace=>caller, &self)
end