Class: Rgot::T

Inherits:
Common show all
Defined in:
lib/rgot/t.rb

Instance Attribute Summary

Attributes inherited from Common

#output

Instance Method Summary collapse

Methods inherited from Common

#error, #errorf, #fail!, #fail_now, #failed?, #fatal, #fatalf, #finish!, #finished?, #log, #logf, #skip, #skip!, #skip_now, #skipf, #skipped?

Constructor Details

#initialize(test_module, name) ⇒ T

Returns a new instance of T.



5
6
7
8
9
10
# File 'lib/rgot/t.rb', line 5

def initialize(test_module, name)
  super()
  @module = test_module
  @name = name
  @module.extend @module
end

Instance Method Details

#callObject



37
38
39
40
41
42
43
44
45
# File 'lib/rgot/t.rb', line 37

def call
  test_method = @module.instance_method(@name).bind(@module)
  if test_method.arity == 0
    path, line = test_method.source_location
    warn "#{path}:#{line} `#{test_method.name}' is not running. It's a testing method name, But not have argument"
  else
    test_method.call(self)
  end
end

#reportObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/rgot/t.rb', line 22

def report
  puts @output if Rgot.verbose? && !@output.empty?
  duration = Rgot.now - @start
  template = "--- \e[%sm%s\e[m: %s (%.2fs)\n"
  if failed?
    printf template, [41, 1].join(';'), "FAIL", @name, duration
  elsif Rgot.verbose?
    if skipped?
      printf template, [44, 1].join(';'), "SKIP", @name, duration
    else
      printf template, [42, 1].join(';'), "PASS", @name, duration
    end
  end
end

#runObject



12
13
14
15
16
17
18
19
20
# File 'lib/rgot/t.rb', line 12

def run
  catch(:skip) { call }
  finish!
  report
rescue => e
  fail!
  report
  raise e
end