Class: RoxClient::RSpec::TestRun
- Inherits:
-
Object
- Object
- RoxClient::RSpec::TestRun
- Defined in:
- lib/rox-client-rspec/test_run.rb
Instance Attribute Summary collapse
-
#duration ⇒ Object
Returns the value of attribute duration.
-
#end_time ⇒ Object
Returns the value of attribute end_time.
-
#project ⇒ Object
readonly
TODO: remove end time once API v0 is dead.
-
#results ⇒ Object
readonly
TODO: remove end time once API v0 is dead.
-
#uid ⇒ Object
Returns the value of attribute uid.
Instance Method Summary collapse
- #add_result(example, groups = [], options = {}) ⇒ Object
-
#initialize(project) ⇒ TestRun
constructor
A new instance of TestRun.
- #results_by_key ⇒ Object
- #results_without_key ⇒ Object
- #to_h(options = {}) ⇒ Object
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
#duration ⇒ Object
Returns the value of attribute duration.
7 8 9 |
# File 'lib/rox-client-rspec/test_run.rb', line 7 def duration @duration end |
#end_time ⇒ Object
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 |
#project ⇒ Object (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 |
#results ⇒ Object (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 |
#uid ⇒ Object
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 = [], = {} if TestResult.extract_grouped(example, groups) and (existing_result = @results.find{ |r| r.grouped? && r.key == TestResult.extract_key(example, groups) }) existing_result.update else @results << TestResult.new(@project, example, groups, ) end end |
#results_by_key ⇒ Object
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_key ⇒ Object
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 = {} validate! case [: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 } }.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 } } ] }.tap do |h| h['u'] = @uid if @uid end end end |