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



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)

Raises:

  • EqualityAssay



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.

Raises:

  • FalseAssay



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)

Raises:

  • InstanceAssay



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

Raises:

  • KindAssay



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)

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



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)

Raises:

  • IdentityAssay



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

Raises:

  • TrueAssay



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

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_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



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

Raises:

  • IncludeAssay



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

Raises:

  • MatchAssay



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.

Examples:

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

Raises:

  • OutputAssay



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)

Raises:

  • RaiseAssay



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)

Raises:

  • RespondAssay



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 }

Raises:

  • ExecutionAssay



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

Raises:

  • ExecutionAssay



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

Raises:

  • ThrowAssay



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?

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



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

Raises:

  • EqualityAssay



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)

Raises:

  • FalseAssay



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)

Raises:

  • InstanceAssay



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

Raises:

  • KindAssay



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)

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



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)

Raises:

  • IdentityAssay



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

Raises:

  • TrueAssay



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

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

Passes if expected != actual

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

Raises:

  • EqualAssay



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

Raises:

  • IncludeAssay



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

Raises:

  • MatchAssay



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)

Raises:

  • RaiseAssay



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)

Raises:

  • RespondAssay



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 }

Raises:

  • ExecutionAssay



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

Raises:

  • ExecutionAssay



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

Raises:

  • ThrowAssay



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