Class: ProbeDockRSpec::TestRun

Inherits:
Object
  • Object
show all
Defined in:
lib/probe_dock_rspec/test_run.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project) ⇒ TestRun

Returns a new instance of TestRun.



8
9
10
11
# File 'lib/probe_dock_rspec/test_run.rb', line 8

def initialize project
  @results = []
  @project = project
end

Instance Attribute Details

#durationObject

Returns the value of attribute duration.



6
7
8
# File 'lib/probe_dock_rspec/test_run.rb', line 6

def duration
  @duration
end

#projectObject (readonly)

Returns the value of attribute project.



5
6
7
# File 'lib/probe_dock_rspec/test_run.rb', line 5

def project
  @project
end

#resultsObject (readonly)

Returns the value of attribute results.



5
6
7
# File 'lib/probe_dock_rspec/test_run.rb', line 5

def results
  @results
end

#uidObject

Returns the value of attribute uid.



6
7
8
# File 'lib/probe_dock_rspec/test_run.rb', line 6

def uid
  @uid
end

Instance Method Details

#add_result(example, groups = [], options = {}) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/probe_dock_rspec/test_run.rb', line 13

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_keyObject



25
26
27
28
29
30
# File 'lib/probe_dock_rspec/test_run.rb', line 25

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_keyObject



21
22
23
# File 'lib/probe_dock_rspec/test_run.rb', line 21

def results_without_key
  @results.select{ |r| !r.key or r.key.to_s.strip.empty? }
end

#to_h(options = {}) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/probe_dock_rspec/test_run.rb', line 32

def to_h options = {}
  validate!

  {
    'projectId' => @project.api_id,
    'version' => @project.version,
    'duration' => @duration,
    'results' => @results.collect{ |r| r.to_h options }
  }.tap do |h|
    h['reports'] = [ { 'uid' => @uid } ] if @uid
  end
end