module Tunit::Assertions

Public Instance Methods

assert(test, msg = nil) click to toggle source
# File lib/tunit/assertions.rb, line 11
def assert test, msg = nil
  msg ||= "Failed assertion, no message given."
  self.assertions += 1
  unless test
    msg = msg.call if Proc === msg
    fail ::Tunit::Assertion, msg
  end
  true
end
assert_equal(exp, act, msg = nil) click to toggle source
# File lib/tunit/assertions.rb, line 21
def assert_equal exp, act, msg = nil
  msg ||= "Failed assertion, no message given."
  assert exp == act, msg
end
assert_includes(collection, obj, msg = nil) click to toggle source
# File lib/tunit/assertions.rb, line 26
def assert_includes collection, obj, msg = nil
  msg ||= "Expected #{collection.inspect} to include #{obj}"
  assert_respond_to collection, :include?
  assert collection.include?(obj), msg
end
assert_instance_of(klass, obj, msg = nil) click to toggle source
# File lib/tunit/assertions.rb, line 37
def assert_instance_of klass, obj, msg = nil
  msg ||= "Expected #{obj.inspect} to be an instance of #{klass}, not #{obj.class}"
  assert obj.instance_of?(klass), msg
end
assert_respond_to(obj, meth, msg = nil) click to toggle source
# File lib/tunit/assertions.rb, line 32
def assert_respond_to obj, meth, msg = nil
  msg ||= "Expected #{obj.inspect} (#{obj.class}) to respond to ##{meth}"
  assert obj.respond_to?(meth), msg
end
refute(test, msg = nil) click to toggle source
# File lib/tunit/assertions.rb, line 42
def refute test, msg = nil
  msg ||= "Failed assertion, no message given."
  ! assert !test, msg
end
refute_equal(exp, act, msg = nil) click to toggle source
# File lib/tunit/assertions.rb, line 47
def refute_equal exp, act, msg = nil
  msg ||= "Failed assertion, no message given."
  refute exp == act, msg
end
refute_includes(collection, obj, msg = nil) click to toggle source
# File lib/tunit/assertions.rb, line 52
def refute_includes collection, obj, msg = nil
  msg ||= "Expected #{collection.inspect} to not include #{obj}"
  assert_respond_to collection, :include?
  refute collection.include?(obj), msg
end
refute_instance_of(klass, obj, msg = nil) click to toggle source
# File lib/tunit/assertions.rb, line 63
def refute_instance_of klass, obj, msg = nil
  msg ||= "Expected #{obj.inspect} not to be an instance of #{klass}"
  refute obj.instance_of?(klass), msg
end
refute_respond_to(obj, meth, msg = nil) click to toggle source
# File lib/tunit/assertions.rb, line 58
def refute_respond_to obj, meth, msg = nil
  msg ||= "Expected #{obj.inspect} (#{obj.class}) to not respond to #{meth}"
  refute obj.respond_to?(meth), msg
end
skip(msg = nil, bt = caller) click to toggle source
# File lib/tunit/assertions.rb, line 5
def skip msg = nil, bt = caller
  method_responsible = bt[0][/`.*'/][1..-2]
  msg ||= "Skipped '#{method_responsible}'"
  fail ::Tunit::Skip, msg, bt
end