Class: Spassky::Server::TestRun

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ TestRun

Returns a new instance of TestRun.



7
8
9
10
11
12
13
14
15
# File 'lib/spassky/server/test_run.rb', line 7

def initialize(options)
  @name = options[:name]
  @contents = options[:contents]
  @status_by_device_id = {}
  @message_by_device_id = {}
  (options[:devices] || []).each do |device|
    @status_by_device_id[device] = "in progress"
  end
end

Instance Attribute Details

#contentsObject

Returns the value of attribute contents.



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

def contents
  @contents
end

#idObject

Returns the value of attribute id.



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

def id
  @id
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

Class Method Details

.create(options) ⇒ Object



41
42
43
44
45
46
# File 'lib/spassky/server/test_run.rb', line 41

def self.create(options)
  new_test_run = TestRun.new(options)
  new_test_run.id = test_runs.size
  test_runs << new_test_run
  new_test_run
end

.find(id) ⇒ Object



48
49
50
# File 'lib/spassky/server/test_run.rb', line 48

def self.find(id)
  test_runs.find { |test_run| test_run.id.to_s == id.to_s  }
end

.find_next_test_to_run_by_device_id(device_id) ⇒ Object



52
53
54
# File 'lib/spassky/server/test_run.rb', line 52

def self.find_next_test_to_run_by_device_id(device_id)
  test_runs.find { |test_run| test_run.run_by_device_id?(device_id) == false }
end

Instance Method Details

#resultObject



35
36
37
38
39
# File 'lib/spassky/server/test_run.rb', line 35

def result
  Spassky::TestSuiteResult.new(@status_by_device_id.map { |device_id, status|
    Spassky::DeviceTestStatus.new(:device_id => device_id, :status => status, :message => @message_by_device_id[device_id], :test_name => @name)
  })
end

#run_by_device_id?(device_id) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/spassky/server/test_run.rb', line 17

def run_by_device_id?(device_id)
  @status_by_device_id[device_id] != "in progress"
end

#save_result_for_device(options) ⇒ Object



21
22
23
24
25
# File 'lib/spassky/server/test_run.rb', line 21

def save_result_for_device(options)
  validate_status options[:status]
  @status_by_device_id[options[:device_identifier]] = options[:status]
  @message_by_device_id[options[:device_identifier]] = options[:message]
end

#update_connected_devices(device_ids) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/spassky/server/test_run.rb', line 27

def update_connected_devices(device_ids)
  @status_by_device_id.each do |device_id, status|
    if !device_ids.include?(device_id) && status == "in progress"
      @status_by_device_id[device_id] = "timed out"
    end
  end
end