Class: MiniTest::Spec
Constant Summary
collapse
- @@describe_stack =
[MiniTest::Spec]
- @@description_stack =
[]
Unit::TestCase::PASSTHROUGH_EXCEPTIONS, Unit::TestCase::SUPPORTS_INFO_SIGNAL
Instance Attribute Summary
#__name__
Class Method Summary
collapse
Instance Method Summary
collapse
inherited, #passed?, reset, #run, #setup, #teardown, test_methods, test_order, test_suites
Methods included from Assertions
#_assertions, #_assertions=, #assert, #assert_block, #assert_empty, #assert_equal, #assert_in_delta, #assert_in_epsilon, #assert_includes, #assert_instance_of, #assert_kind_of, #assert_match, #assert_nil, #assert_operator, #assert_raises, #assert_respond_to, #assert_same, #assert_send, #assert_throws, #capture_io, #exception_details, #flunk, #message, #mu_pp, #pass, #refute, #refute_empty, #refute_equal, #refute_in_delta, #refute_in_epsilon, #refute_includes, #refute_instance_of, #refute_kind_of, #refute_match, #refute_nil, #refute_operator, #refute_respond_to, #refute_same, #skip
Constructor Details
#initialize(name) ⇒ Spec
Returns a new instance of Spec.
83
84
85
86
|
# File 'lib/minitest/spec.rb', line 83
def initialize name
super
@@current_spec = self
end
|
Class Method Details
.after(type = :each, &block) ⇒ Object
108
109
110
111
|
# File 'lib/minitest/spec.rb', line 108
def self.after(type = :each, &block)
raise "unsupported after type: #{type}" unless type == :each
define_inheritable_method :teardown, &block
end
|
.before(type = :each, &block) ⇒ Object
103
104
105
106
|
# File 'lib/minitest/spec.rb', line 103
def self.before(type = :each, &block)
raise "unsupported before type: #{type}" unless type == :each
define_inheritable_method :setup, &block
end
|
79
80
81
|
# File 'lib/minitest/spec.rb', line 79
def self.current
@@current_spec
end
|
.define_inheritable_method(name, &block) ⇒ Object
94
95
96
97
98
99
100
101
|
# File 'lib/minitest/spec.rb', line 94
def self.define_inheritable_method name, &block
super_method = self.superclass.instance_method name
define_method name do
super_method.bind(self).call if super_method instance_eval(&block)
end
end
|
.describe_stack ⇒ Object
70
71
72
|
# File 'lib/minitest/spec.rb', line 70
def self.describe_stack
@@describe_stack
end
|
.description_stack ⇒ Object
75
76
77
|
# File 'lib/minitest/spec.rb', line 75
def self.description_stack
@@description_stack
end
|
.expect(desc = nil, &block) ⇒ Object
beacuse test names are really just comments, and therefore a code smell
118
119
120
121
122
123
|
# File 'lib/minitest/spec.rb', line 118
def self.expect(desc=nil, &block)
@minitest_expectation_counter ||= 0; @minitest_expectation_counter += 1
desc ||= "[#{@minitest_expectation_counter}]"
name = ["test_", description_stack, desc].flatten.join(' ').gsub(/\W+/, '_').downcase
define_method name, &block
end
|
.it(desc, &block) ⇒ Object
113
114
115
|
# File 'lib/minitest/spec.rb', line 113
def self.it desc, &block
define_method "test_#{description_stack.join(' ').gsub(/\W+/, '_')}_#{desc.gsub(/\W+/, '_').downcase}", &block
end
|
.nuke_test_methods! ⇒ Object
88
89
90
91
92
|
# File 'lib/minitest/spec.rb', line 88
def self.nuke_test_methods!
self.public_instance_methods.grep(/^test_/).each do |name|
send :undef_method, name rescue nil
end
end
|