Class: Attest::TestObject

Inherits:
Object show all
Defined in:
lib/attest/test_object.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(description, test_block) ⇒ TestObject

Returns a new instance of TestObject.



9
10
11
12
13
# File 'lib/attest/test_object.rb', line 9

def initialize(description, test_block)
  @description = description
  @test_block = test_block
  @results = []
end

Instance Attribute Details

#afterObject

Returns the value of attribute after.



8
9
10
# File 'lib/attest/test_object.rb', line 8

def after
  @after
end

#beforeObject

Returns the value of attribute before.



8
9
10
# File 'lib/attest/test_object.rb', line 8

def before
  @before
end

#descriptionObject (readonly)

Returns the value of attribute description.



7
8
9
# File 'lib/attest/test_object.rb', line 7

def description
  @description
end

#disabledObject

Returns the value of attribute disabled.



8
9
10
# File 'lib/attest/test_object.rb', line 8

def disabled
  @disabled
end

#nosetupObject

Returns the value of attribute nosetup.



8
9
10
# File 'lib/attest/test_object.rb', line 8

def nosetup
  @nosetup
end

#resultsObject (readonly)

Returns the value of attribute results.



7
8
9
# File 'lib/attest/test_object.rb', line 7

def results
  @results
end

Instance Method Details

#run(persistent_context) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/attest/test_object.rb', line 15

def run(persistent_context)
  Attest.output_writer.before_test(self)
  error = nil
  context = Attest::ExecutionContext.new(persistent_context)
  begin
   #Object.class_eval do
     #define_method :itself do
       #subject = self
       #context.instance_eval {@subject = subject}
       #context
     #end
   #end
   context.instance_eval(&@before) if @before && !nosetup && !disabled
   context.instance_eval(&@test_block) if @test_block && !disabled
   context.instance_eval(&@after) if @after && !nosetup && !disabled
  rescue => e
    error = e
  ensure
    @results = context.results
    add_unexpected_error_result(error) if error
    add_pending_result unless @test_block
    add_disabled_result if disabled
    add_success_result if @results.size == 0
  end
  Attest.output_writer.after_test(self)
end