Class: Runyoufools::Test

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(testFile, retries, command) ⇒ Test

Returns a new instance of Test.



7
8
9
10
11
12
# File 'lib/runyoufools/test.rb', line 7

def initialize( testFile, retries, command )
  @file = testFile 
  @ok = nil
       @retries = retries
       @command = command
end

Instance Attribute Details

#okObject (readonly)

Returns the value of attribute ok.



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

def ok
  @ok
end

#trialsObject (readonly)

Returns the value of attribute trials.



5
6
7
# File 'lib/runyoufools/test.rb', line 5

def trials
  @trials
end

Instance Method Details

#_runObject



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/runyoufools/test.rb', line 24

def _run
  Runyoufools.log :info, "RUNNING #{@file}"
       if @command
           toRun = "#{@command} #{@file}"
       else
           toRun = @file
       end
       @ok = system( toRun )
       if @ok == nil
           Runyoufools.log :error, "could not execute: #{toRun}"
       end
  Runyoufools.log :info,( "#{self}" )
end

#runObject



14
15
16
17
18
19
20
21
22
# File 'lib/runyoufools/test.rb', line 14

def run
  @trials = 0
  @retries.times do
    Runyoufools.log :info, "retrying #{@file}..." if @trials > 0
    @trials += 1
    _run
    return if @ok
  end
end

#to_sObject



38
39
40
41
# File 'lib/runyoufools/test.rb', line 38

def to_s
       result = { true => "OK   ".green.bold, false => "FAIL ".red.bold, nil => "ERROR".white.bold.on_red }[ @ok ]
  "#{result}: #{@trials} trial(s) : #{@file}"
end