class Shindo::Tests
def assert(type, expectation, description, &block)
def assert(type, expectation, description, &block) return if Thread.main[:exit] || Thread.current[:reload] description = [@description, description].compact.join(' ') if block_given? begin for before in @befores.flatten.compact before.call end value, success = case type when :raises value = begin instance_eval(&block) rescue Shindo::Pending @pending = true rescue Exception => error error end [value, value.is_a?(expectation)] when :returns [value = instance_eval(&block), value == expectation] end for after in @afters.flatten.compact after.call end rescue Shindo::Pending @pending = true rescue => error success = false value = error end if @pending @pending = false display_pending(description) elsif success display_success(description) else display_failure(description) case value when Exception, Interrupt display_error(value) else @message ||= [ "expected => #{expectation.inspect}", "returned => #{value.inspect}" ] Formatador.indent do Formatador.display_lines([*@message].map {|message| "[red]#{message}[/]"}) end @message = nil end if Thread.current[:interactive] && STDOUT.tty? prompt(description, &block) end end else display_pending(description) end success end