Class: RoxClient::TestRun

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project) ⇒ TestRun

Returns a new instance of TestRun.



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

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

Instance Attribute Details

#durationObject

Returns the value of attribute duration.



5
6
7
# File 'lib/rox-client-ruby/test_run.rb', line 5

def duration
  @duration
end

#projectObject (readonly)

Returns the value of attribute project.



4
5
6
# File 'lib/rox-client-ruby/test_run.rb', line 4

def project
  @project
end

#resultsObject (readonly)

Returns the value of attribute results.



4
5
6
# File 'lib/rox-client-ruby/test_run.rb', line 4

def results
  @results
end

#uidObject

Returns the value of attribute uid.



5
6
7
# File 'lib/rox-client-ruby/test_run.rb', line 5

def uid
  @uid
end

Instance Method Details

#add_result(options = {}) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/rox-client-ruby/test_run.rb', line 12

def add_result options = {}

  if options[:grouped] && existing_result = @results.find{ |r| r.grouped? && r.key == options[:key] }
    existing_result.update options
  else
    @results << TestResult.new(@project, options)
  end
end

#results_by_keyObject



25
26
27
28
29
30
# File 'lib/rox-client-ruby/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/rox-client-ruby/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
44
45
46
47
# File 'lib/rox-client-ruby/test_run.rb', line 32

def to_h options = {}
  validate!

  {
    '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