module InlineTester::Assertions

Public Instance Methods

assert(boolean, message=nil) click to toggle source
# File lib/assertions.rb, line 8
def assert boolean, message=nil
  unless boolean
    # MESSAGE::: Assertion did not pass.
    $stdout.print(message || 
      "Expected a truthy value, but instead got #{boolean}")
    stack_trace_print
  else

  end
end
assert_matches(string, pattern, message=nil) click to toggle source
# File lib/assertions.rb, line 42
def assert_matches string, pattern, message=nil
  $__stack_+=1
  assert(string =~ pattern, message || 
    "Expected #{string} to match #{pattern}, but it did not.")
  $__stack_-=1
end
assert_something_raised(message=nil) { || ... } click to toggle source
# File lib/assertions.rb, line 30
def assert_something_raised message=nil, &block
  begin
    yield
    # Message::: Nothing raised.
    $stdout.print(message || 
      "Expected #{block} to raise an Exception, but it did not.")
    stack_trace_print
  rescue => e
    
  end
end
refute(boolean, message=nil) click to toggle source
# File lib/assertions.rb, line 19
def refute boolean, message=nil
  if boolean
    # MESSAGE::: Refution did not pass.
    $stdout.print(message || 
      "Expected a falsy value, but instead got #{boolean}")
    stack_trace_print
  else

  end
end
skip(message=nil) { || ... } click to toggle source
# File lib/assertions.rb, line 49
def skip message=nil, &block
  $stdout.print message || "Skipped assertion."
  if block_given?
    yield
  end
end
todo(message=nil) click to toggle source
# File lib/assertions.rb, line 56
def todo message=nil
  $stdout.print message || "TODO!"
  stack_trace_print
end

Private Instance Methods

stack_trace_print() click to toggle source
# File lib/assertions.rb, line 62
def stack_trace_print
  puts " from:"
  # Print stack trace from _stack_ with at most 3 more deep
  caller_locations($__stack_, 3).map do |call|
    $stdout.puts "===> #{call.to_s}"
  end
end