Class: Test::Advice

Inherits:
Object
  • Object
show all
Defined in:
lib/rubytest/advice.rb

Overview

The Advice class is an observer that can be customized to initiate before, after and upon procedures for all of RubyTests observable points.

Only one procedure is allowed per-point.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAdvice

Returns a new instance of Advice.



33
34
35
# File 'lib/rubytest/advice.rb', line 33

def initialize
  @table = {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missingObject

Ignore any other signals (precautionary).



92
93
# File 'lib/rubytest/advice.rb', line 92

def method_missing(*)
end

Class Method Details

.joinpoint(name) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'lib/rubytest/advice.rb', line 21

def self.joinpoint(name)
  joinpoints << name.to_sym

  class_eval %{
    def #{name}(*args)
      procedure = @table[:#{name}]
      procedure.call(*args) if procedure
    end
  }
end

.joinpointsObject



12
13
14
# File 'lib/rubytest/advice.rb', line 12

def self.joinpoints
  @joinpoints ||= []
end

Instance Method Details

#begin_caseObject



41
# File 'lib/rubytest/advice.rb', line 41

joinpoint :begin_case

#begin_suite(suite) ⇒ Object



38
# File 'lib/rubytest/advice.rb', line 38

joinpoint :begin_suite

#begin_test(test) ⇒ Object



47
# File 'lib/rubytest/advice.rb', line 47

joinpoint :begin_test

#end_caseObject



65
# File 'lib/rubytest/advice.rb', line 65

joinpoint :end_case

#end_suite(suite) ⇒ Object



68
# File 'lib/rubytest/advice.rb', line 68

joinpoint :end_suite

#end_test(test) ⇒ Object



62
# File 'lib/rubytest/advice.rb', line 62

joinpoint :end_test

#error(test, exception) ⇒ Object



56
# File 'lib/rubytest/advice.rb', line 56

joinpoint :error

#fail(test, exception) ⇒ Object



53
# File 'lib/rubytest/advice.rb', line 53

joinpoint :fail

#join(type, &block) ⇒ Object

Add a procedure to one of the join-points.



76
77
78
79
# File 'lib/rubytest/advice.rb', line 76

def join(type, &block)
  type = valid_type(type) 
  @table[type] = block
end

#join_after(type, &block) ⇒ Object

Add a procedure to one of the after join-points.



87
88
89
# File 'lib/rubytest/advice.rb', line 87

def join_after(type, &block)
  join("end_#{type}", &block)
end

#join_before(type, &block) ⇒ Object

Add a procedure to one of the before join-points.



82
83
84
# File 'lib/rubytest/advice.rb', line 82

def join_before(type, &block)
  join("begin_#{type}", &block) 
end

#pass(test) ⇒ Object



50
# File 'lib/rubytest/advice.rb', line 50

joinpoint :pass

#skip_test(test, reason) ⇒ Object



44
# File 'lib/rubytest/advice.rb', line 44

joinpoint :skip_test

#todo(test, exception) ⇒ Object



59
# File 'lib/rubytest/advice.rb', line 59

joinpoint :todo