Module: ExampleCall

Included in:
DefaultTests2
Defined in:
app/models/default_test_case.rb

Instance Method Summary collapse

Instance Method Details

#assert_optional_method(object, symbol) ⇒ Object

named_object?


53
54
55
56
57
58
59
60
61
62
# File 'app/models/default_test_case.rb', line 53

def assert_optional_method(object, symbol)
 if object.respond_to?(symbol) then
   info "method #{symbol.inspect} does exist for object of type #{object.class.name}"
   assert_respond_to(object, symbol)
   object.method(symbol).call
 else
	message="method #{symbol} does not exist for object "+named_object?
   warn message
 end #if
end

#each_example(&block) ⇒ Object


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/models/default_test_case.rb', line 11

def each_example(&block)
  included_module_names=model_class?.included_modules.map{|m| m.name}
  if  included_module_names.include?("#{model_class?}::Examples") then
#    info "model_class?.constants=#{model_class?.constants}"
    constant_objects=model_class?.constants.map{|c| model_class?.class_eval(c.to_s)}
#verbose    info "constant_objects=#{constant_objects}"
    examples=constant_objects.select{|c| c.instance_of?(Regexp)}
    if examples.empty? then
#once      warn "There are no example constants of type #{model_class?} in #{model_class?}::Examples."
    else
      examples.each do |c|
        info "calling block on #{c.inspect}"
        block.call(c)
      end #each
    end #if
  else
    warn "There is no module #{model_class?}::Examples."
  end #if
end

#existing_call(object, symbol) ⇒ Object

Call method symbol on object if method exists


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/models/default_test_case.rb', line 31

def existing_call(object, symbol)
 if object.respond_to?(symbol) then
   info "method #{symbol.inspect} does  exist for object of type #{object.class.name}"
   assert_respond_to(object, symbol)
   object.method(symbol).call
 else
	message="method #{symbol} does not exist for object "
	if object.respond_to?(:name) then
		message+="named #{object.name}"
	else
		message+="of type #{object.class.name}"
	end #if
   warn message
 end #if
end

#named_object?Boolean

existing_call


46
47
48
49
50
51
52
# File 'app/models/default_test_case.rb', line 46

def named_object?
	if object.respond_to?(:name) then
		"named #{object.name}"
	else
		"of type #{object.class.name}"
	end #if
end