Class: Megatest::TestCaseResult
- Inherits:
-
Object
- Object
- Megatest::TestCaseResult
- Defined in:
- lib/megatest/state.rb
Instance Attribute Summary collapse
-
#assertions_count ⇒ Object
Returns the value of attribute assertions_count.
-
#duration ⇒ Object
readonly
Returns the value of attribute duration.
-
#failures ⇒ Object
readonly
Returns the value of attribute failures.
-
#test_id ⇒ Object
readonly
Returns the value of attribute test_id.
-
#test_location ⇒ Object
readonly
Returns the value of attribute test_location.
Class Method Summary collapse
Instance Method Summary collapse
- #_load(members) ⇒ Object
- #bad? ⇒ Boolean
- #did_not_run(reason) ⇒ Object
- #dump ⇒ Object
- #ensure_assertions ⇒ Object
- #error? ⇒ Boolean
- #failed? ⇒ Boolean
- #failure ⇒ Object
- #failure? ⇒ Boolean
-
#initialize(test_case) ⇒ TestCaseResult
constructor
A new instance of TestCaseResult.
- #lost ⇒ Object
- #lost? ⇒ Boolean
- #ok? ⇒ Boolean
- #record_time ⇒ Object
- #retried? ⇒ Boolean
- #retry ⇒ Object
- #skipped? ⇒ Boolean
- #status ⇒ Object
- #success? ⇒ Boolean
Constructor Details
#initialize(test_case) ⇒ TestCaseResult
Returns a new instance of TestCaseResult.
584 585 586 587 588 589 590 591 |
# File 'lib/megatest/state.rb', line 584 def initialize(test_case) @test_id = test_case.id @test_location = test_case.location_id @assertions_count = 0 @duration = nil @retried = false @failures = [] end |
Instance Attribute Details
#assertions_count ⇒ Object
Returns the value of attribute assertions_count.
581 582 583 |
# File 'lib/megatest/state.rb', line 581 def assertions_count @assertions_count end |
#duration ⇒ Object (readonly)
Returns the value of attribute duration.
582 583 584 |
# File 'lib/megatest/state.rb', line 582 def duration @duration end |
#failures ⇒ Object (readonly)
Returns the value of attribute failures.
582 583 584 |
# File 'lib/megatest/state.rb', line 582 def failures @failures end |
#test_id ⇒ Object (readonly)
Returns the value of attribute test_id.
582 583 584 |
# File 'lib/megatest/state.rb', line 582 def test_id @test_id end |
#test_location ⇒ Object (readonly)
Returns the value of attribute test_location.
582 583 584 |
# File 'lib/megatest/state.rb', line 582 def test_location @test_location end |
Class Method Details
.load(payload) ⇒ Object
576 577 578 |
# File 'lib/megatest/state.rb', line 576 def load(payload) allocate._load(Marshal.load(payload)) end |
Instance Method Details
#_load(members) ⇒ Object
593 594 595 596 597 598 599 600 601 |
# File 'lib/megatest/state.rb', line 593 def _load(members) @test_id = members[0] @test_location = members[1] @assertions_count = members[2] @duration = members[3] @failures = members[4]&.map { |m| Failure.load(m) } || [] @retried = members[5] || false self end |
#bad? ⇒ Boolean
634 635 636 |
# File 'lib/megatest/state.rb', line 634 def bad? !@retried && !@failures.empty? end |
#did_not_run(reason) ⇒ Object
659 660 661 662 |
# File 'lib/megatest/state.rb', line 659 def did_not_run(reason) @failures << Failure.new(DidNotRun.new(reason)) self end |
#dump ⇒ Object
603 604 605 606 607 608 609 610 611 612 613 614 |
# File 'lib/megatest/state.rb', line 603 def dump members = [ @test_id, @test_location, @assertions_count, @duration, @failures.empty? ? nil : @failures.map(&:dump), @retried || nil, ] members.compact! Marshal.dump(members) end |
#ensure_assertions ⇒ Object
652 653 654 655 656 657 |
# File 'lib/megatest/state.rb', line 652 def ensure_assertions if @assertions_count.zero? && success? @failures << Failure.new(NoAssertion.new) end self end |
#error? ⇒ Boolean
686 687 688 |
# File 'lib/megatest/state.rb', line 686 def error? !@retried && @failures.first&.name == UnexpectedError.name end |
#failed? ⇒ Boolean
678 679 680 |
# File 'lib/megatest/state.rb', line 678 def failed? !@failures.empty? end |
#failure ⇒ Object
626 627 628 |
# File 'lib/megatest/state.rb', line 626 def failure @failures.first end |
#failure? ⇒ Boolean
682 683 684 |
# File 'lib/megatest/state.rb', line 682 def failure? !@retried && !skipped? && !@failures.empty? && @failures.first&.name != UnexpectedError.name end |
#lost ⇒ Object
664 665 666 667 668 |
# File 'lib/megatest/state.rb', line 664 def lost @failures << Failure.new(LostTest.new(@test_id)) @duration = 0.0 self end |
#lost? ⇒ Boolean
690 691 692 |
# File 'lib/megatest/state.rb', line 690 def lost? @failures.first&.name == LostTest.name end |
#ok? ⇒ Boolean
630 631 632 |
# File 'lib/megatest/state.rb', line 630 def ok? success? || retried? || skipped? end |
#record_time ⇒ Object
616 617 618 619 620 621 622 623 624 |
# File 'lib/megatest/state.rb', line 616 def record_time start_time = Megatest.now begin yield ensure @duration = Megatest.now - start_time end self end |
#retried? ⇒ Boolean
674 675 676 |
# File 'lib/megatest/state.rb', line 674 def retried? @retried end |
#retry ⇒ Object
698 699 700 701 702 |
# File 'lib/megatest/state.rb', line 698 def retry copy = dup copy.retried = true copy end |
#skipped? ⇒ Boolean
694 695 696 |
# File 'lib/megatest/state.rb', line 694 def skipped? @failures.first&.name == Skip.name end |
#status ⇒ Object
638 639 640 641 642 643 644 645 646 647 648 649 650 |
# File 'lib/megatest/state.rb', line 638 def status if skipped? :skipped elsif retried? :retried elsif error? :error elsif failed? :failure else :success end end |
#success? ⇒ Boolean
670 671 672 |
# File 'lib/megatest/state.rb', line 670 def success? @failures.empty? end |