class SleepingKingStudios::Tasks::Ci::CucumberResults
Encapsulates the results of a Cucumber call.
Public Class Methods
@param results [Hash] The raw results of the RSpec call.
# File lib/sleeping_king_studios/tasks/ci/cucumber_results.rb, line 11 def initialize results @results = results end
Public Instance Methods
@param other [RSpecResults] The other results object to compare.
@return [Boolean] True if the results are equal, otherwise false.
# File lib/sleeping_king_studios/tasks/ci/cucumber_results.rb, line 18 def == other if other.is_a?(Hash) empty? ? other.empty? : to_h == other elsif other.is_a?(CucumberResults) to_h == other.to_h else false end # if-elsif-else end
@return [Float] The duration value.
# File lib/sleeping_king_studios/tasks/ci/cucumber_results.rb, line 29 def duration @results.fetch('duration', 0.0) end
@return [Boolean] True if there are no scenarios, otherwise false.
# File lib/sleeping_king_studios/tasks/ci/cucumber_results.rb, line 34 def empty? scenario_count.zero? end
@return [Boolean] True if there are any failing scenarios, otherwise
false.
# File lib/sleeping_king_studios/tasks/ci/cucumber_results.rb, line 40 def failing? !failing_scenario_count.zero? end
@return [Integer] The number of failing scenarios.
# File lib/sleeping_king_studios/tasks/ci/cucumber_results.rb, line 50 def failing_scenario_count failing_scenarios.count end
@return [Integer] The list of failing scenarios.
# File lib/sleeping_king_studios/tasks/ci/cucumber_results.rb, line 45 def failing_scenarios @results.fetch('failing_scenarios', []) end
@return [Integer] The number of failing steps.
# File lib/sleeping_king_studios/tasks/ci/cucumber_results.rb, line 55 def failing_step_count @results.fetch('failing_step_count', 0) end
Adds the given result values and returns a new results object with the sums.
@param other [RSpecResults] The results to add.
@return [RSpecResults] The total results.
# File lib/sleeping_king_studios/tasks/ci/cucumber_results.rb, line 65 def merge other merged = {} keys.each do |key| merged[key] = public_send(key) + other.public_send(key) end # each self.class.new(merged) end
@return [Boolean] True if there are any pending scenarios, otherwise
false.
# File lib/sleeping_king_studios/tasks/ci/cucumber_results.rb, line 77 def pending? !pending_scenario_count.zero? end
@return [Integer] The number of pending scenarios.
# File lib/sleeping_king_studios/tasks/ci/cucumber_results.rb, line 82 def pending_scenario_count pending_scenarios.count end
@return [Integer] The list of pending scenarios.
# File lib/sleeping_king_studios/tasks/ci/cucumber_results.rb, line 87 def pending_scenarios @results.fetch('pending_scenarios', []) end
@return [Integer] The number of pending steps.
# File lib/sleeping_king_studios/tasks/ci/cucumber_results.rb, line 92 def pending_step_count @results.fetch('pending_step_count', 0) end
@return [Integer] The total number of scenarios.
# File lib/sleeping_king_studios/tasks/ci/cucumber_results.rb, line 97 def scenario_count @results.fetch('scenario_count', 0) end
@return [String] A brief summary of the scenario results.
# File lib/sleeping_king_studios/tasks/ci/cucumber_results.rb, line 102 def scenarios_summary build_summary( 'scenario', scenario_count, failing_scenario_count, pending_scenario_count ) # end build_summary end
@return [Integer] The total number of steps.
# File lib/sleeping_king_studios/tasks/ci/cucumber_results.rb, line 112 def step_count @results.fetch('step_count', 0) end
@return [String] A brief summary of the scenario results.
# File lib/sleeping_king_studios/tasks/ci/cucumber_results.rb, line 117 def steps_summary build_summary( 'step', step_count, failing_step_count, pending_step_count ) # end build_summary end
@return [String] A brief summary of the results.
# File lib/sleeping_king_studios/tasks/ci/cucumber_results.rb, line 127 def summary str = scenarios_summary str << ', ' str << steps_summary str << " in #{duration.round(2)} seconds" end
@return [Hash] The hash representation of the results.
# File lib/sleeping_king_studios/tasks/ci/cucumber_results.rb, line 139 def to_h hsh = {} keys.each { |key| hsh[key] = public_send(key) } hsh end
Private Instance Methods
# File lib/sleeping_king_studios/tasks/ci/cucumber_results.rb, line 149 def build_summary name, count, failing_count, pending_count str = pluralize(count, name) return str if failing_count.zero? && pending_count.zero? str << build_summary_details(failing_count, pending_count) end
# File lib/sleeping_king_studios/tasks/ci/cucumber_results.rb, line 157 def build_summary_details failing_count, pending_count str = ' (' str << pluralize(failing_count, 'failure') unless failing_count.zero? str << ', ' if !failing_count.zero? && !pending_count.zero? str << "#{pending_count} pending" unless pending_count.zero? str << ')' end
# File lib/sleeping_king_studios/tasks/ci/cucumber_results.rb, line 169 def keys %w[ duration step_count pending_step_count failing_step_count scenario_count pending_scenarios failing_scenarios ] # end keys end
# File lib/sleeping_king_studios/tasks/ci/cucumber_results.rb, line 181 def pluralize count, singular, plural = nil "#{count} #{tools.int.pluralize count, singular, plural}" end
# File lib/sleeping_king_studios/tasks/ci/cucumber_results.rb, line 185 def tools SleepingKingStudios::Tools::Toolbelt.instance end