module TOTS::Asserts

The standard assertions

Public Instance Methods

assert(smth, msg="No message given") click to toggle source
# File lib/tots/asserts.rb, line 5
def assert(smth, msg="No message given")
  TOTS::Printer.asserting(msg)

  unless smth
    raise TOTS::Test::Fail, msg
  end
end
assert_empty(v, msg=nil) click to toggle source
# File lib/tots/asserts.rb, line 17
def assert_empty(v, msg=nil)
  assert_respond_to v, :empty?
  assert v.empty?, msg || "#{v.inspect} supposed to be empty"
end
assert_equal(v1, v2, msg=nil) click to toggle source
# File lib/tots/asserts.rb, line 13
def assert_equal(v1, v2, msg=nil)
  assert v1 == v2, msg || "#{v1.inspect} supposed to be equal to #{v2.inspect}"
end
assert_includes(list, value, msg=nil) click to toggle source
# File lib/tots/asserts.rb, line 30
def assert_includes(list, value, msg=nil)
  assert_respond_to list, :include?
  assert list.include?(value), msg || "#{list.inspect} supposed to include #{value.inspect}"
end
assert_instance_of(obj, klass, msg=nil) click to toggle source
# File lib/tots/asserts.rb, line 40
def assert_instance_of(obj, klass, msg=nil)
  assert obj.instance_of?(klass), msg || "#{obj.inspect} supposed to be instance of #{klass}"
end
assert_match(obj, re, msg=nil) click to toggle source
# File lib/tots/asserts.rb, line 35
def assert_match(obj, re, msg=nil)
  assert_respond_to re, :=~
  assert re =~ obj, msg || "#{obj.inspect} supposed to match #{re.inspect}"
end
assert_nil(v, msg=nil) click to toggle source
# File lib/tots/asserts.rb, line 26
def assert_nil(v, msg=nil)
  assert v === nil, msg || "#{v.inspect} supposed to be nil"
end
assert_raises(type, msg=nil) { || ... } click to toggle source
# File lib/tots/asserts.rb, line 44
def assert_raises(type, msg=nil, &block)
  raise ArgumentError, "no block given" if !block_given?

  begin
    yield

    assert false, msg || "expected to raise #{type}, but nothing was raised"

  rescue Exception => e
    if type && !(e.is_a?(type))
      assert false, msg || "expected to raise #{type}, but got #{e.class} instead"
    end
  end
end
assert_respond_to(obj, method, msg=nil) click to toggle source
# File lib/tots/asserts.rb, line 22
def assert_respond_to(obj, method, msg=nil)
  assert obj.respond_to?(method), msg || "#{obj.inspect} supposed to respond to the #{method} method"
end