Class: RoxClient::RSpec::TestRun

Inherits:
Object
  • Object
show all
Defined in:
lib/rox-client-rspec/test_run.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project) ⇒ TestRun

Returns a new instance of TestRun.



9
10
11
12
# File 'lib/rox-client-rspec/test_run.rb', line 9

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

Instance Attribute Details

#durationObject

Returns the value of attribute duration.



7
8
9
# File 'lib/rox-client-rspec/test_run.rb', line 7

def duration
  @duration
end

#end_timeObject

Returns the value of attribute end_time.



7
8
9
# File 'lib/rox-client-rspec/test_run.rb', line 7

def end_time
  @end_time
end

#projectObject (readonly)

TODO: remove end time once API v0 is dead



6
7
8
# File 'lib/rox-client-rspec/test_run.rb', line 6

def project
  @project
end

#resultsObject (readonly)

TODO: remove end time once API v0 is dead



6
7
8
# File 'lib/rox-client-rspec/test_run.rb', line 6

def results
  @results
end

#uidObject

Returns the value of attribute uid.



7
8
9
# File 'lib/rox-client-rspec/test_run.rb', line 7

def uid
  @uid
end

Instance Method Details

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



14
15
16
17
18
19
20
21
# 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_keyObject



27
28
29
30
31
32
# 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_keyObject



23
24
25
# 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 = {}) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# 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