Module: Test

Defined in:
lib/pretty_debug.rb

Class Method Summary collapse

Class Method Details

.raise?(exception = Exception, &pr) ⇒ Boolean

Returns:

  • (Boolean)


187
188
189
190
191
# File 'lib/pretty_debug.rb', line 187

def self.raise? exception = Exception, &pr
  pr.call; false
  rescue Exception => e
     e.kind_of?(exception)
end

.test(title = "Test", &pr) ⇒ Object



194
195
196
197
198
199
200
201
202
203
204
205
206
# File 'lib/pretty_debug.rb', line 194

def self.test title = "Test", &pr
  testee_clear
  t = Time.now
  if pr.call == true
    puts "#{title}. Succeeded (#{"%.2e" % t.till_now} secs)".color(:green)
  else
    puts "#{title}. Failed".color(:red),
    *(testee_refer.map{|o| o.inspect.color(:red)} unless testee_refer.empty?)
  end
rescue Exception
    puts "#{title} ... Test Error".color(:red),
    [$!.message, *PrettyDebug.clean($@).align.map{|row| row.join(":")}].map{|l| l.color(:red)}
end

.testeeObject



186
# File 'lib/pretty_debug.rb', line 186

def self.testee; @@testee end

.testee_clearObject



192
# File 'lib/pretty_debug.rb', line 192

def self.testee_clear; @@testee = [] end

.testee_referObject



193
# File 'lib/pretty_debug.rb', line 193

def self.testee_refer; @@testee end