Class: Greenlight::Test

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, &block) ⇒ Test

Returns a new instance of Test.



12
13
14
15
# File 'lib/greenlight/test.rb', line 12

def initialize(name, &block)
  self.name = name
  self.body = block
end

Instance Attribute Details

#argsObject

Returns the value of attribute args.



10
11
12
# File 'lib/greenlight/test.rb', line 10

def args
  @args
end

#bodyObject

Returns the value of attribute body.



9
10
11
# File 'lib/greenlight/test.rb', line 9

def body
  @body
end

#nameObject

Returns the value of attribute name.



8
9
10
# File 'lib/greenlight/test.rb', line 8

def name
  @name
end

Instance Method Details

#error_msgObject



37
38
39
# File 'lib/greenlight/test.rb', line 37

def error_msg
  "TEST '#{name}' failed"
end

#run(args = {}) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/greenlight/test.rb', line 17

def run(args = {})
  action Colors.white("TEST ") + Colors.yellow(name)
  Console.instance.indent
  begin
    ret = Greenlight.eval(args, &body)
    success('test succeeded')
    ret
  rescue RequestException
    error error_msg
    raise TestException
  rescue StandardError => e
    error e.backtrace.inspect
    error e.message
    error error_msg
    raise TestException
  ensure
    Console.instance.unindent
  end
end