class SleepingKingStudios::Tasks::Ci::RSpecResults
Encapsulates the results of an RSpec call.
Public Class Methods
@param results [Hash] The raw results of the RSpec call.
# File lib/sleeping_king_studios/tasks/ci/rspec_results.rb, line 9 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/rspec_results.rb, line 16 def == other if other.is_a?(Hash) empty? ? other.empty? : to_h == other elsif other.is_a?(RSpecResults) to_h == other.to_h else false end # if-elsif-else end
@return [Float] The duration value.
# File lib/sleeping_king_studios/tasks/ci/rspec_results.rb, line 27 def duration @results.fetch('duration', 0.0) end
@return [Boolean] True if there are no examples, otherwise false.
# File lib/sleeping_king_studios/tasks/ci/rspec_results.rb, line 32 def empty? example_count.zero? end
@return [Integer] The number of errors that occurred outside of examples.
# File lib/sleeping_king_studios/tasks/ci/rspec_results.rb, line 43 def error_count @results.fetch('error_count', 0) end
@return [Boolean] True if there are no results or if errors occurred
outside of examples, otherwise false.
# File lib/sleeping_king_studios/tasks/ci/rspec_results.rb, line 38 def errored? @results.empty? || !error_count.zero? end
@return [Integer] The total number of examples.
# File lib/sleeping_king_studios/tasks/ci/rspec_results.rb, line 48 def example_count @results.fetch('example_count', 0) end
@return [Boolean] True if there are any failing examples, otherwise false.
# File lib/sleeping_king_studios/tasks/ci/rspec_results.rb, line 53 def failing? !failure_count.zero? end
@return [Integer] The number of failing examples.
# File lib/sleeping_king_studios/tasks/ci/rspec_results.rb, line 58 def failure_count @results.fetch('failure_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/rspec_results.rb, line 68 def merge other self.class.new( 'duration' => duration + other.duration, 'example_count' => example_count + other.example_count, 'failure_count' => failure_count + other.failure_count, 'pending_count' => pending_count + other.pending_count ) # end new end
@return [Boolean] True if there are any pending examples, otherwise false.
# File lib/sleeping_king_studios/tasks/ci/rspec_results.rb, line 78 def pending? !pending_count.zero? end
@return [Intger] The number of pending examples.
# File lib/sleeping_king_studios/tasks/ci/rspec_results.rb, line 83 def pending_count @results.fetch('pending_count', 0) end
# File lib/sleeping_king_studios/tasks/ci/rspec_results.rb, line 87 def pluralize count, singular, plural = nil "#{count} #{tools.int.pluralize count, singular, plural}" end
@return [Hash] The hash representation of the results.
# File lib/sleeping_king_studios/tasks/ci/rspec_results.rb, line 92 def to_h { 'duration' => duration, 'example_count' => example_count, 'failure_count' => failure_count, 'pending_count' => pending_count, 'error_count' => error_count } # end hash end
@return [String] The string representation of the results.
# File lib/sleeping_king_studios/tasks/ci/rspec_results.rb, line 105 def to_s str = pluralize(example_count, 'example') str << ', ' << pluralize(failure_count, 'failure') str << ', ' << pending_count.to_s << ' pending' if pending? if error_count.zero? str << " in #{duration.round(2)} seconds" else str << ', ' << pluralize(error_count, 'error') << ' occurred outside of examples' end # if-else end
rubocop:enable Metrics/AbcSize
# File lib/sleeping_king_studios/tasks/ci/rspec_results.rb, line 122 def tools SleepingKingStudios::Tools::Toolbelt.instance end