Class: Overseer::Test

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, &block) ⇒ Test

Returns a new instance of Test.



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

def initialize(name, &block)
  @name = name
  @code = block
  @suite = Overseer.current_suite
  @errors = []
  @failures = []
  @assertions = 0
end

Instance Attribute Details

#assertionsObject

Returns the value of attribute assertions.



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

def assertions
  @assertions
end

#codeObject (readonly)

Returns the value of attribute code.



3
4
5
# File 'lib/overseer/test.rb', line 3

def code
  @code
end

#errorsObject

Returns the value of attribute errors.



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

def errors
  @errors
end

#failuresObject

Returns the value of attribute failures.



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

def failures
  @failures
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/overseer/test.rb', line 3

def name
  @name
end

#suiteObject (readonly)

Returns the value of attribute suite.



3
4
5
# File 'lib/overseer/test.rb', line 3

def suite
  @suite
end

#timeObject (readonly)

Returns the value of attribute time.



3
4
5
# File 'lib/overseer/test.rb', line 3

def time
  @time
end

Instance Method Details

#errors?Boolean

Returns true or +false depending if the test have outstanding errors or not

Returns:

  • (Boolean)


25
26
27
# File 'lib/overseer/test.rb', line 25

def errors?
  errors.any?
end

#failures?Boolean

Returns true or +false depending if the test have outstanding failures or not

Returns:

  • (Boolean)


31
32
33
# File 'lib/overseer/test.rb', line 31

def failures?
  failures.any?
end

#passed?Boolean

Returns true or false depending if the test is passed or not

Returns:

  • (Boolean)


18
19
20
# File 'lib/overseer/test.rb', line 18

def passed?
  !errors? && !failures?
end

#runObject

Run the test, record the run time and store possible exceptions



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/overseer/test.rb', line 38

def run
  Overseer.current_test = self
  start_time = Time.now
  suite.before.call if suite.before
  begin
    @code.call
  rescue Exception => e
    errors << e
  ensure
    begin
      suite.after.call if suite.after
    rescue Exception => e
      errors << e if passed?
    end
    @time = Time.now - start_time
  end
end