Class: Offshore::Test

Inherits:
Object
  • Object
show all
Defined in:
lib/offshore/client/test.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.currentObject



4
5
6
# File 'lib/offshore/client/test.rb', line 4

def self.current
  @test ||= Test.new
end

.flushObject



8
9
10
11
12
13
14
# File 'lib/offshore/client/test.rb', line 8

def self.flush
  if @test && @test.run? && !@test.stopped?
    # run again because it crashed in execution
    @test.stop
  end
  @test = nil
end

.start(example) ⇒ Object



16
17
18
19
20
# File 'lib/offshore/client/test.rb', line 16

def self.start(example)
  flush
  current.start(example)
  current
end

.stopObject



22
23
24
25
# File 'lib/offshore/client/test.rb', line 22

def self.stop
  current.stop
  current
end

Instance Method Details

#get_name(example) ⇒ Object



33
34
35
36
37
38
# File 'lib/offshore/client/test.rb', line 33

def get_name(example)
  name = nil
  name = example.full_description if example.respond_to?(:full_description)
  name ||= "unknown"
  "#{uuid} #{name}"
end

#run?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/offshore/client/test.rb', line 40

def run?
  !!@run_example
end

#start(example = nil) ⇒ Object



48
49
50
51
52
# File 'lib/offshore/client/test.rb', line 48

def start(example=nil)
  raise "already run test: #{get_name(@run_example)}" if @run_example
  @run_example = example
  Offshore.suite.all_hosts!(:test_start, get_name(example))
end

#stopObject



54
55
56
57
58
59
# File 'lib/offshore/client/test.rb', line 54

def stop
  raise "have not run!" unless @run_example
  raise "already stopped!" if @stopped
  @stopped = true
  Offshore.suite.all_hosts!(:test_stop, get_name(@run_example))
end

#stopped?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/offshore/client/test.rb', line 44

def stopped?
  !!@stopped
end

#uuidObject



29
30
31
# File 'lib/offshore/client/test.rb', line 29

def uuid
  @uid ||= rand(99999999).to_s
end