Class: Res::IR

Inherits:
Object
  • Object
show all
Defined in:
lib/res/ir.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ IR

Expects hash of: :results => { } :type => test_runner :start_time => Time the tests started :end_time => Time they completed



19
20
21
22
23
24
25
# File 'lib/res/ir.rb', line 19

def initialize( options = {} )
  @results     = options[:results]     or raise "No results data"
  @type        = options[:type]        or raise "No type provided (e.g. 'Cucumber')"
  @started     = options[:started]     or raise "Need to provide a start time"
  @finished    = options[:finished]    or raise "Need to provide an end time"
  @values      = initialize_values( options[:values], options[:results] )
end

Instance Attribute Details

#end_timeObject

Returns the value of attribute end_time.



5
6
7
# File 'lib/res/ir.rb', line 5

def end_time
  @end_time
end

#hashObject

Returns the value of attribute hash.



5
6
7
# File 'lib/res/ir.rb', line 5

def hash
  @hash
end

#hive_job_idObject

Returns the value of attribute hive_job_id.



6
7
8
# File 'lib/res/ir.rb', line 6

def hive_job_id
  @hive_job_id
end

#projectObject

Returns the value of attribute project.



6
7
8
# File 'lib/res/ir.rb', line 6

def project
  @project
end

#resultsObject

Returns the value of attribute results.



5
6
7
# File 'lib/res/ir.rb', line 5

def results
  @results
end

#start_timeObject

Returns the value of attribute start_time.



5
6
7
# File 'lib/res/ir.rb', line 5

def start_time
  @start_time
end

#suiteObject

Returns the value of attribute suite.



6
7
8
# File 'lib/res/ir.rb', line 6

def suite
  @suite
end

#targetObject

Returns the value of attribute target.



6
7
8
# File 'lib/res/ir.rb', line 6

def target
  @target
end

#typeObject

Returns the value of attribute type.



5
6
7
# File 'lib/res/ir.rb', line 5

def type
  @type
end

#valuesObject

Returns the value of attribute values.



5
6
7
# File 'lib/res/ir.rb', line 5

def values
  @values
end

#worldObject

Returns the value of attribute world.



5
6
7
# File 'lib/res/ir.rb', line 5

def world
  @world
end

Class Method Details

.load(file) ⇒ Object



8
9
10
11
12
# File 'lib/res/ir.rb', line 8

def self.load(file)
  f = File.open file
  hash = JSON.load(f, nil, :symbolize_names => true )
  Res::IR.new( hash )
end

Instance Method Details

#count(status) ⇒ Object



66
67
68
# File 'lib/res/ir.rb', line 66

def count(status)
  tests.count { |t| t[:status].to_sym == status.to_sym  }
end

#flat_formatObject

Returns a simple array of test information [ { :name => ‘test1’, :urn => ‘file/tests.t:32’, :status => ‘passed’, :time => 12.04 },

{ :name => 'test2', :urn => 'file/tests.t:36', :status => 'failed', :time =>  } ]


73
74
75
76
77
78
79
# File 'lib/res/ir.rb', line 73

def flat_format
  self.tests.collect do |t|
    { :name   => t[:name],
      :urn    => t[:urn],
      :status => t[:status] }
  end
end

#initialize_values(initial_values, results_hash) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/res/ir.rb', line 27

def initialize_values( initial_values, results_hash )
  h = {}
  if initial_values && !initial_values.empty?
    initial_values.each do |k,v|
      h[k.to_s] = v
    end
  end
  
  IR.find_values( results_hash ).each do |i|
    if !i.empty?
      i.each do |k,v|
        h[k.to_s] = v
      end           
    end
  end
  
  h
end

#jsonObject

Dump as json



47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/res/ir.rb', line 47

def json
  hash = {
    :started     => @started,
    :finished    => @finished,
    :results     => @results,
    :type        => @type }
  
  # Merge in the world information if it's available
  hash[:world] = world if world
  hash[:hive_job_id] = hive_job_id if hive_job_id
  
  JSON.pretty_generate( hash )
end

#testsObject

Pluck out the actual test nodes from the contexts



62
63
64
# File 'lib/res/ir.rb', line 62

def tests
  IR.find_tests(results).flatten
end