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?(include_retry: false) ⇒ Boolean
- #failed? ⇒ Boolean
- #failure ⇒ Object
- #failure?(include_retry: false) ⇒ 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.
579 580 581 582 583 584 585 586 |
# File 'lib/megatest/state.rb', line 579 def initialize(test_case) @test_id = test_case.id @test_location = test_case.location_id @assertions_count = 0 @duration = 0.0 @retried = false @failures = [] end |
Instance Attribute Details
#assertions_count ⇒ Object
Returns the value of attribute assertions_count.
576 577 578 |
# File 'lib/megatest/state.rb', line 576 def assertions_count @assertions_count end |
#duration ⇒ Object (readonly)
Returns the value of attribute duration.
577 578 579 |
# File 'lib/megatest/state.rb', line 577 def duration @duration end |
#failures ⇒ Object (readonly)
Returns the value of attribute failures.
577 578 579 |
# File 'lib/megatest/state.rb', line 577 def failures @failures end |
#test_id ⇒ Object (readonly)
Returns the value of attribute test_id.
577 578 579 |
# File 'lib/megatest/state.rb', line 577 def test_id @test_id end |
#test_location ⇒ Object (readonly)
Returns the value of attribute test_location.
577 578 579 |
# File 'lib/megatest/state.rb', line 577 def test_location @test_location end |
Class Method Details
.load(payload) ⇒ Object
571 572 573 |
# File 'lib/megatest/state.rb', line 571 def load(payload) allocate._load(Marshal.load(payload)) end |
Instance Method Details
#_load(members) ⇒ Object
588 589 590 591 592 593 594 595 596 |
# File 'lib/megatest/state.rb', line 588 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
629 630 631 |
# File 'lib/megatest/state.rb', line 629 def bad? !@retried && !@failures.empty? end |
#did_not_run(reason) ⇒ Object
654 655 656 657 |
# File 'lib/megatest/state.rb', line 654 def did_not_run(reason) @failures << Failure.new(DidNotRun.new(reason)) self end |
#dump ⇒ Object
598 599 600 601 602 603 604 605 606 607 608 609 |
# File 'lib/megatest/state.rb', line 598 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
647 648 649 650 651 652 |
# File 'lib/megatest/state.rb', line 647 def ensure_assertions if @assertions_count.zero? && success? @failures << Failure.new(NoAssertion.new) end self end |
#error?(include_retry: false) ⇒ Boolean
680 681 682 |
# File 'lib/megatest/state.rb', line 680 def error?(include_retry: false) (include_retry || !@retried) && @failures.first&.name == UnexpectedError.name end |
#failed? ⇒ Boolean
672 673 674 |
# File 'lib/megatest/state.rb', line 672 def failed? !@failures.empty? end |
#failure ⇒ Object
621 622 623 |
# File 'lib/megatest/state.rb', line 621 def failure @failures.first end |
#failure?(include_retry: false) ⇒ Boolean
676 677 678 |
# File 'lib/megatest/state.rb', line 676 def failure?(include_retry: false) (include_retry || !@retried) && !skipped? && !@failures.empty? && @failures.first&.name != UnexpectedError.name end |
#lost ⇒ Object
659 660 661 662 |
# File 'lib/megatest/state.rb', line 659 def lost @failures << Failure.new(LostTest.new(@test_id)) self end |
#lost? ⇒ Boolean
684 685 686 |
# File 'lib/megatest/state.rb', line 684 def lost? @failures.first&.name == LostTest.name end |
#ok? ⇒ Boolean
625 626 627 |
# File 'lib/megatest/state.rb', line 625 def ok? success? || retried? || skipped? end |
#record_time ⇒ Object
611 612 613 614 615 616 617 618 619 |
# File 'lib/megatest/state.rb', line 611 def record_time start_time = Megatest.now begin yield ensure @duration = Megatest.now - start_time end self end |
#retried? ⇒ Boolean
668 669 670 |
# File 'lib/megatest/state.rb', line 668 def retried? @retried end |
#retry ⇒ Object
692 693 694 695 696 |
# File 'lib/megatest/state.rb', line 692 def retry copy = dup copy.retried = true copy end |
#skipped? ⇒ Boolean
688 689 690 |
# File 'lib/megatest/state.rb', line 688 def skipped? @failures.first&.name == Skip.name end |
#status ⇒ Object
633 634 635 636 637 638 639 640 641 642 643 644 645 |
# File 'lib/megatest/state.rb', line 633 def status if skipped? :skipped elsif retried? :retried elsif error? :error elsif failed? :failure else :success end end |
#success? ⇒ Boolean
664 665 666 |
# File 'lib/megatest/state.rb', line 664 def success? @failures.empty? end |