Class: RSpec::Unit::TestCase
Defined Under Namespace
Classes: ExamplesCollection
Constant Summary
collapse
- TEST_METHOD_PATTERN =
/^test_/
Constants included
from Assertions
Assertions::UncaughtThrow
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Assertions
#assert, #assert_block, #assert_equal, #assert_in_delta, #assert_instance_of, #assert_kind_of, #assert_match, #assert_nil, #assert_no_match, #assert_not_equal, #assert_not_nil, #assert_not_same, #assert_nothing_raised, #assert_nothing_thrown, #assert_operator, #assert_raise, #assert_raises, #assert_respond_to, #assert_same, #assert_send, #assert_throws, #build_message, #flunk, use_pp=
Constructor Details
Returns a new instance of TestCase.
121
122
123
124
|
# File 'lib/rspec/unit/test_case.rb', line 121
def initialize
@test_passed = true
super
end
|
Class Method Details
.ancestors ⇒ Object
53
54
55
|
# File 'lib/rspec/unit/test_case.rb', line 53
def self.ancestors
super[0..-2]
end
|
.caller_lines ⇒ Object
62
63
64
|
# File 'lib/rspec/unit/test_case.rb', line 62
def self.caller_lines
@_caller_lines ||= {}
end
|
.examples ⇒ Object
49
50
51
|
# File 'lib/rspec/unit/test_case.rb', line 49
def self.examples
@tc_examples ||= ExamplesCollection.new(self, super)
end
|
.find_caller_lines(name) ⇒ Object
66
67
68
69
70
71
72
73
74
|
# File 'lib/rspec/unit/test_case.rb', line 66
def self.find_caller_lines(name)
klass = self
while klass.respond_to?(:caller_lines)
lines = klass.caller_lines[name]
return lines unless lines.nil?
klass = klass.superclass
end
[]
end
|
.inherited(klass) ⇒ Object
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/rspec/unit/test_case.rb', line 21
def self.inherited(klass)
super
install_setup_and_teardown(klass)
klass.set_it_up(test_case_name(klass), {:caller => caller})
klass.metadata[:example_group][:test_unit] = true
children << klass
world.example_groups << klass
end
|
.install_setup_and_teardown(klass) ⇒ Object
80
81
82
83
84
85
86
87
88
89
|
# File 'lib/rspec/unit/test_case.rb', line 80
def self.install_setup_and_teardown(klass)
if self == ::RSpec::Unit::TestCase
klass.class_eval do
before {setup}
after {teardown}
end
end
end
|
.method_added(id) ⇒ Object
40
41
42
43
44
45
46
47
|
# File 'lib/rspec/unit/test_case.rb', line 40
def self.method_added(id)
name = id.to_s
if test_method?(name)
caller_lines[name] = caller
test_method_metadata[name] = @_metadata_for_next
@_metadata_for_next = nil
end
end
|
.number_of_tests ⇒ Object
101
102
103
|
# File 'lib/rspec/unit/test_case.rb', line 101
def self.number_of_tests
test_methods.size
end
|
.test_case_info(options) ⇒ Object
32
33
34
|
# File 'lib/rspec/unit/test_case.rb', line 32
def self.test_case_info(options)
metadata[:example_group].update(options)
end
|
.test_case_name(klass) ⇒ Object
57
58
59
60
|
# File 'lib/rspec/unit/test_case.rb', line 57
def self.test_case_name(klass)
class_name = klass.name
(class_name.nil? || class_name.empty?) ? '<Anonymous TestCase>' : class_name
end
|
.test_info(options) ⇒ Object
36
37
38
|
# File 'lib/rspec/unit/test_case.rb', line 36
def self.test_info(options)
@_metadata_for_next = options
end
|
.test_method?(method_name) ⇒ Boolean
91
92
93
94
95
|
# File 'lib/rspec/unit/test_case.rb', line 91
def self.test_method?(method_name)
method_name =~ TEST_METHOD_PATTERN &&
public_method_defined?(method_name) &&
(-1..0).include?(instance_method(method_name).arity)
end
|
76
77
78
|
# File 'lib/rspec/unit/test_case.rb', line 76
def self.test_method_metadata
@_test_method_metadata ||= {}
end
|
.test_methods ⇒ Object
97
98
99
|
# File 'lib/rspec/unit/test_case.rb', line 97
def self.test_methods
public_instance_methods(true).select{|m| test_method?(m)}.map{|m| m.to_s}
end
|
.tests ⇒ Object
105
106
107
108
109
110
111
112
|
# File 'lib/rspec/unit/test_case.rb', line 105
def self.tests
@tests ||= test_methods.sort.map do |m|
meta = (test_method_metadata[m] || {}).merge({:caller => find_caller_lines(m),
:full_description => "#{display_name}##{m}",
:test_unit => true})
Core::Example.new(self, m, meta, proc{execute(m)})
end
end
|
Instance Method Details
#execute(method) ⇒ Object
132
133
134
135
136
137
138
139
|
# File 'lib/rspec/unit/test_case.rb', line 132
def execute(method)
begin
send(method.to_sym)
rescue
@test_passed = false
raise
end
end
|
#setup ⇒ Object
126
127
|
# File 'lib/rspec/unit/test_case.rb', line 126
def setup
end
|
#teardown ⇒ Object
129
130
|
# File 'lib/rspec/unit/test_case.rb', line 129
def teardown
end
|