Class: TestRail::TestCaseResult
- Inherits:
-
Object
- Object
- TestRail::TestCaseResult
- Defined in:
- lib/test_rail_integration/generator/test_case_result.rb
Instance Attribute Summary collapse
-
#assign_to ⇒ Object
Returns the value of attribute assign_to.
-
#comment ⇒ Object
Returns the value of attribute comment.
-
#exception_message ⇒ Object
Returns the value of attribute exception_message.
-
#previous_comment ⇒ Object
Returns the value of attribute previous_comment.
-
#scenario ⇒ Object
Returns the value of attribute scenario.
-
#test_case_id ⇒ Object
Returns the value of attribute test_case_id.
-
#test_results ⇒ Object
Returns the value of attribute test_results.
-
#title ⇒ Object
Returns the value of attribute title.
Instance Method Summary collapse
- #failed? ⇒ Boolean
-
#get_indexes_of_fails ⇒ Object
Get indexes of failed results.
- #get_indexes_of_passes ⇒ Object
-
#get_last_failed_comment ⇒ Object
Get last failed comment for test case.
-
#get_previous_comments ⇒ Object
Parse results and returns previous comment.
-
#get_previous_test_result ⇒ Object
Parse results and returns Failed if this test was marked as failed.
-
#initialize(scenario) ⇒ TestCaseResult
constructor
A new instance of TestCaseResult.
- #passed? ⇒ Boolean
-
#to_test_rail_api ⇒ Object
Send status to TestRail.
- #unchanged_pass? ⇒ Boolean
- #update ⇒ Object
Constructor Details
#initialize(scenario) ⇒ TestCaseResult
Returns a new instance of TestCaseResult.
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/test_rail_integration/generator/test_case_result.rb', line 31 def initialize(scenario) self.test_case_id = scenario.source_tag_names.find { |e| e.match(TEST_RAIL_ID_REGEX) }[2..-1] self.scenario = scenario if scenario.kind_of? Cucumber::Ast::OutlineTable::ExampleRow self.title = scenario.scenario_outline.title self. = scenario.scenario_exception unless defined?(scenario.scenario_exception).nil? else self.title = scenario.title self. = scenario.steps.exception unless defined?(scenario.steps).nil? end self.test_results = TestRail::Connection.get_test_results(self.test_case_id) self.previous_comment = get_last_failed_comment unless get_indexes_of_fails.empty? end |
Instance Attribute Details
#assign_to ⇒ Object
Returns the value of attribute assign_to.
7 8 9 |
# File 'lib/test_rail_integration/generator/test_case_result.rb', line 7 def assign_to @assign_to end |
#comment ⇒ Object
Returns the value of attribute comment.
7 8 9 |
# File 'lib/test_rail_integration/generator/test_case_result.rb', line 7 def comment @comment end |
#exception_message ⇒ Object
Returns the value of attribute exception_message.
7 8 9 |
# File 'lib/test_rail_integration/generator/test_case_result.rb', line 7 def @exception_message end |
#previous_comment ⇒ Object
Returns the value of attribute previous_comment.
7 8 9 |
# File 'lib/test_rail_integration/generator/test_case_result.rb', line 7 def previous_comment @previous_comment end |
#scenario ⇒ Object
Returns the value of attribute scenario.
7 8 9 |
# File 'lib/test_rail_integration/generator/test_case_result.rb', line 7 def scenario @scenario end |
#test_case_id ⇒ Object
Returns the value of attribute test_case_id.
7 8 9 |
# File 'lib/test_rail_integration/generator/test_case_result.rb', line 7 def test_case_id @test_case_id end |
#test_results ⇒ Object
Returns the value of attribute test_results.
7 8 9 |
# File 'lib/test_rail_integration/generator/test_case_result.rb', line 7 def test_results @test_results end |
#title ⇒ Object
Returns the value of attribute title.
7 8 9 |
# File 'lib/test_rail_integration/generator/test_case_result.rb', line 7 def title @title end |
Instance Method Details
#failed? ⇒ Boolean
45 46 47 |
# File 'lib/test_rail_integration/generator/test_case_result.rb', line 45 def failed? !scenario.passed? end |
#get_indexes_of_fails ⇒ Object
Get indexes of failed results
60 61 62 63 |
# File 'lib/test_rail_integration/generator/test_case_result.rb', line 60 def get_indexes_of_fails indexes = self.test_results.map.with_index { |result, index| result["status_id"] == COMMENT[:fail][:status] ? index : nil } indexes.compact end |
#get_indexes_of_passes ⇒ Object
65 66 67 68 |
# File 'lib/test_rail_integration/generator/test_case_result.rb', line 65 def get_indexes_of_passes indexes = self.test_results.map.with_index { |result, index| result["status_id"] == COMMENT[:pass][:status] ? index : nil } indexes.compact end |
#get_last_failed_comment ⇒ Object
Get last failed comment for test case
83 84 85 86 87 |
# File 'lib/test_rail_integration/generator/test_case_result.rb', line 83 def get_last_failed_comment comments = get_previous_comments index = get_indexes_of_fails.first comments[index] end |
#get_previous_comments ⇒ Object
Parse results and returns previous comment.
73 74 75 76 77 78 |
# File 'lib/test_rail_integration/generator/test_case_result.rb', line 73 def get_previous_comments test_comment = self.test_results.map { |hash| hash["comment"] } comment = test_comment comment ||= [] comment end |
#get_previous_test_result ⇒ Object
Parse results and returns Failed if this test was marked as failed.
92 93 94 95 96 97 98 |
# File 'lib/test_rail_integration/generator/test_case_result.rb', line 92 def get_previous_test_result test_results = self.test_results.map { |status_hash| status_hash["status_id"] } status = FAILED if test_results.include?(FAILED) status ||= PASS if test_results.first == PASS status ||= NEW status end |
#passed? ⇒ Boolean
49 50 51 |
# File 'lib/test_rail_integration/generator/test_case_result.rb', line 49 def passed? scenario.passed? && get_previous_test_result != FAILED end |
#to_test_rail_api ⇒ Object
Send status to TestRail
1, comment: “Test passed”
122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/test_rail_integration/generator/test_case_result.rb', line 122 def to_test_rail_api = "#{self.comment[:comment]} \"#{self.title}\"" = "**[#{Fixtures.instance['venture']}]** #{self.comment[:comment]} for \"#{self.title}\"" unless defined?(Fixtures.instance['venture']).nil? += "\n Exception : #{self.}" unless self..nil? += "\n #{self.previous_comment}" if self.comment[:status] == COMMENT[:fail][:status] || self.comment[:status] == COMMENT[:unchanged_pass][:status] if self.comment[:status] == COMMENT_STATUS {comment: } else {status_id: self.comment[:status], comment: } end end |
#unchanged_pass? ⇒ Boolean
53 54 55 |
# File 'lib/test_rail_integration/generator/test_case_result.rb', line 53 def unchanged_pass? scenario.passed? && get_previous_test_result == FAILED end |
#update ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/test_rail_integration/generator/test_case_result.rb', line 100 def update self.comment = COMMENT[:pass] if passed? self.comment ||= COMMENT[:unchanged_pass] if unchanged_pass? if failed? self.comment ||= COMMENT[:fail] self. = self. rescue nil self.assign_to = ASSIGN_TO end raise("Invalid test case result : scenario.passed? #{self.scenario.passed?}, prev_result? #{get_previous_test_result}, run_result? #{self.scenario.passed?}") if self.comment.nil? TestRail::Connection.commit_test_result(self) self end |