class TestRail::TestCaseResult
Attributes
assign_to[RW]
comment[RW]
exception_message[RW]
previous_comment[RW]
scenario[RW]
test_case_id[RW]
test_results[RW]
title[RW]
Public Class Methods
new(scenario)
click to toggle source
# 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.exception_message = scenario.scenario_exception unless defined?(scenario.scenario_exception).nil? else self.title = scenario.title self.exception_message = 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
Public Instance Methods
failed?()
click to toggle source
# File lib/test_rail_integration/generator/test_case_result.rb, line 45 def failed? !scenario.passed? end
get_indexes_of_fails()
click to toggle source
Get indexes of failed results
# 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()
click to toggle source
# 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()
click to toggle source
Get last failed comment for test case
# 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()
click to toggle source
Parse results and returns previous comment.
# 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()
click to toggle source
Parse results and returns Failed if this test was marked as failed.
# 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?()
click to toggle source
# 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()
click to toggle source
Send status to TestRail
{status_id: 1, comment: “Test passed”}
# File lib/test_rail_integration/generator/test_case_result.rb, line 122 def to_test_rail_api comment_message = "#{self.comment[:comment]} \"#{self.title}\"" comment_message = "**[#{Fixtures.instance['venture']}]** #{self.comment[:comment]} for \"#{self.title}\"" unless defined?(Fixtures.instance['venture']).nil? comment_message += "\n Exception : #{self.exception_message}" unless self.exception_message.nil? comment_message += "\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: comment_message} else {status_id: self.comment[:status], comment: comment_message} end end
unchanged_pass?()
click to toggle source
# File lib/test_rail_integration/generator/test_case_result.rb, line 53 def unchanged_pass? scenario.passed? && get_previous_test_result == FAILED end
update()
click to toggle source
# 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.exception_message = self.exception_message 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