Class: MinitestLog::Element
- Inherits:
-
Object
- Object
- MinitestLog::Element
- Defined in:
- lib/minitest_log.rb
Instance Attribute Summary collapse
-
#args ⇒ Object
Returns the value of attribute args.
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#block_to_be_rescued ⇒ Object
Returns the value of attribute block_to_be_rescued.
-
#duration_to_be_included ⇒ Object
Returns the value of attribute duration_to_be_included.
-
#element_name ⇒ Object
Returns the value of attribute element_name.
-
#log ⇒ Object
Returns the value of attribute log.
-
#pcdata ⇒ Object
Returns the value of attribute pcdata.
-
#start_time ⇒ Object
Returns the value of attribute start_time.
Instance Method Summary collapse
- #do_block ⇒ Object
- #do_duration ⇒ Object
-
#initialize(log, element_name, *args) ⇒ Element
constructor
A new instance of Element.
- #log_filter_backtrace(backtrace) ⇒ Object
- #log_put_attributes(attributes) ⇒ Object
-
#log_puts(s) ⇒ Object
The called methods are private.
- #process_args ⇒ Object
- #put_attributes ⇒ Object
- #put_element ⇒ Object
- #put_pcdata ⇒ Object
Constructor Details
#initialize(log, element_name, *args) ⇒ Element
Returns a new instance of Element.
479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 |
# File 'lib/minitest_log.rb', line 479 def initialize(log, element_name, *args) self.log = log self.element_name = element_name self.args = args self.attributes = {} self.block_to_be_rescued = false self.duration_to_be_included = false self.pcdata = '' self.start_time = nil process_args put_element do put_attributes put_pcdata do_duration do do_block(&Proc.new) if block_given? end end end |
Instance Attribute Details
#args ⇒ Object
Returns the value of attribute args.
469 470 471 |
# File 'lib/minitest_log.rb', line 469 def args @args end |
#attributes ⇒ Object
Returns the value of attribute attributes.
469 470 471 |
# File 'lib/minitest_log.rb', line 469 def attributes @attributes end |
#block_to_be_rescued ⇒ Object
Returns the value of attribute block_to_be_rescued.
469 470 471 |
# File 'lib/minitest_log.rb', line 469 def block_to_be_rescued @block_to_be_rescued end |
#duration_to_be_included ⇒ Object
Returns the value of attribute duration_to_be_included.
469 470 471 |
# File 'lib/minitest_log.rb', line 469 def duration_to_be_included @duration_to_be_included end |
#element_name ⇒ Object
Returns the value of attribute element_name.
469 470 471 |
# File 'lib/minitest_log.rb', line 469 def element_name @element_name end |
#log ⇒ Object
Returns the value of attribute log.
469 470 471 |
# File 'lib/minitest_log.rb', line 469 def log @log end |
#pcdata ⇒ Object
Returns the value of attribute pcdata.
469 470 471 |
# File 'lib/minitest_log.rb', line 469 def pcdata @pcdata end |
#start_time ⇒ Object
Returns the value of attribute start_time.
469 470 471 |
# File 'lib/minitest_log.rb', line 469 def start_time @start_time end |
Instance Method Details
#do_block ⇒ Object
548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 |
# File 'lib/minitest_log.rb', line 548 def do_block if block_to_be_rescued begin yield rescue Exception => x log.put_element('rescued_exception', {:class => x.class, :message => x.}) do log.put_element('backtrace') do backtrace = log_filter_backtrace(x.backtrace) log.put_pre(backtrace.join("\n")) end end log.counts[:error] += 1 end else yield end end |
#do_duration ⇒ Object
537 538 539 540 541 542 543 544 545 546 |
# File 'lib/minitest_log.rb', line 537 def do_duration self.start_time = Time.new yield if duration_to_be_included end_time = Time.now duration_f = end_time.to_f - start_time.to_f duration_s = format('%.3f', duration_f) log_put_attributes({:duration_seconds => duration_s}) end end |
#log_filter_backtrace(backtrace) ⇒ Object
576 577 578 |
# File 'lib/minitest_log.rb', line 576 def log_filter_backtrace(backtrace) log.send(:filter_backtrace, backtrace) end |
#log_put_attributes(attributes) ⇒ Object
572 573 574 |
# File 'lib/minitest_log.rb', line 572 def log_put_attributes(attributes) log.send(:put_attributes, attributes) end |
#log_puts(s) ⇒ Object
The called methods are private.
568 569 570 |
# File 'lib/minitest_log.rb', line 568 def log_puts(s) log.send(:log_puts, s) end |
#process_args ⇒ Object
502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 |
# File 'lib/minitest_log.rb', line 502 def process_args args.each do |arg| case when arg.kind_of?(Hash) self.attributes.merge!(arg) when arg.kind_of?(String) self.pcdata += arg when arg == :timestamp self.attributes[:timestamp] = MinitestLog. when arg == :duration self.duration_to_be_included = true when arg == :rescue self.block_to_be_rescued = true else self.pcdata = self.pcdata + arg.inspect end end end |
#put_attributes ⇒ Object
527 528 529 |
# File 'lib/minitest_log.rb', line 527 def put_attributes log_put_attributes(attributes) end |
#put_element ⇒ Object
521 522 523 524 525 |
# File 'lib/minitest_log.rb', line 521 def put_element log_puts("BEGIN\t#{element_name}") yield log_puts("END\t#{element_name}") end |
#put_pcdata ⇒ Object
531 532 533 534 535 |
# File 'lib/minitest_log.rb', line 531 def put_pcdata unless pcdata.empty? log.send(:put_pcdata, pcdata) end end |