class RoxClient::RSpec::TestRun
Attributes
duration[RW]
end_time[RW]
project[R]
TODO: remove end time once API v0 is dead
results[R]
TODO: remove end time once API v0 is dead
uid[RW]
Public Class Methods
new(project)
click to toggle source
# File lib/rox-client-rspec/test_run.rb, line 9 def initialize project @results = [] @project = project end
Public Instance Methods
add_result(example, groups = [], options = {})
click to toggle source
# File lib/rox-client-rspec/test_run.rb, line 14 def add_result example, groups = [], options = {} if TestResult.extract_grouped(example, groups) and (existing_result = @results.find{ |r| r.grouped? && r.key == TestResult.extract_key(example, groups) }) existing_result.update options else @results << TestResult.new(@project, example, groups, options) end end
results_by_key()
click to toggle source
# File lib/rox-client-rspec/test_run.rb, line 27 def results_by_key @results.inject({}) do |memo,r| (memo[r.key] ||= []) << r unless !r.key or r.key.to_s.strip.empty? memo end end
results_without_key()
click to toggle source
# File lib/rox-client-rspec/test_run.rb, line 23 def results_without_key @results.select{ |r| !r.key or r.key.to_s.strip.empty? } end
to_h(options = {})
click to toggle source
# File lib/rox-client-rspec/test_run.rb, line 34 def to_h options = {} validate! case options[:version] when 0 { 'r' => ENV['ROX_RUNNER_KEY'], 'e' => @end_time, 'd' => @duration, 'j' => @project.name, 'v' => @project.version, 't' => @results.collect{ |r| r.to_h options } }.tap do |h| h['u'] = @uid if @uid end else # version 1 by default { 'd' => @duration, 'r' => [ { 'j' => @project.api_id, 'v' => @project.version, 't' => @results.collect{ |r| r.to_h options } } ] }.tap do |h| h['u'] = @uid if @uid end end end
Private Instance Methods
validate!()
click to toggle source
# File lib/rox-client-rspec/test_run.rb, line 67 def validate! # TODO: validate duration raise PayloadError.new("Missing project") if !@project @project.validate! validate_no_results_without_key validate_no_duplicate_keys end
validate_no_duplicate_keys()
click to toggle source
# File lib/rox-client-rspec/test_run.rb, line 77 def validate_no_duplicate_keys results_with_duplicate_key = results_by_key.select{ |k,r| r.length >= 2 } return if results_with_duplicate_key.none? msg = "the following keys are used by multiple test results".tap do |s| results_with_duplicate_key.each_pair do |key,results| s << "\n - #{key}" results.each{ |r| s << "\n - #{r.name}" } end end raise PayloadError.new(msg) end
validate_no_results_without_key()
click to toggle source
# File lib/rox-client-rspec/test_run.rb, line 92 def validate_no_results_without_key keyless = results_without_key return if keyless.empty? msg = "the following test results are missing a key".tap do |s| keyless.each{ |r| s << "\n - #{r.name}" } end raise PayloadError.new(msg) end