Class: MiniTest::Unit::TestCase
- Inherits:
-
Object
- Object
- MiniTest::Unit::TestCase
- Defined in:
- lib/test/unit.rb
Instance Attribute Summary collapse
-
#_assertions ⇒ Object
Returns the value of attribute _assertions.
Class Method Summary collapse
Instance Method Summary collapse
- #_increment_assertions ⇒ Object
- #assert(test, msg = "failed assertion (no message given)") ⇒ Object
- #assert_block(msg = "assert_block failed.") ⇒ Object
- #assert_equal(exp, act, msg = "") ⇒ Object
- #assert_in_delta(exp, act, delta, msg = "Expected #{exp} to be within #{delta} of #{act}") ⇒ Object
- #assert_instance_of(cls, obj, msg = "Expected #{obj.inspect} to be an instance of #{cls}") ⇒ Object
- #assert_kind_of(cls, obj, msg = "Expected #{obj.inspect} to be a kind of #{cls}") ⇒ Object
- #assert_match(exp, act, msg = "Expected #{act.inspect} to match #{exp.inspect}") ⇒ Object
- #assert_nil(obj, msg = "Expected #{obj.inspect} to be nil") ⇒ Object
- #assert_no_match(exp, act, msg = "Expected #{act.inspect} to not match #{exp.inspect}") ⇒ Object
- #assert_not_equal(exp, act, msg = "Expected #{act.inspect} to not be equal to #{exp.inspect}") ⇒ Object
- #assert_not_nil(obj, msg = "Expected #{obj.inspect} to not be nil") ⇒ Object
- #assert_not_same(exp, act, msg = "Expected #{act.inspect} to not be the same as #{exp.inspect}") ⇒ Object
- #assert_nothing_raised ⇒ Object (also: #assert_nothing_thrown)
- #assert_operator(o1, op, o2, msg = "<#{o1.inspect}> expected to be\n#{op.inspect}\n<#{o2.inspect}>.") ⇒ Object
- #assert_raises(*exp) ⇒ Object (also: #assert_raise)
- #assert_respond_to(obj, meth, msg = "Expected #{obj.inspect} of type #{obj.class} to respond_to? #{meth.inspect}") ⇒ Object
- #assert_same(exp, act, msg = "Expected #{act.inspect} to be the same as #{exp.inspect}.") ⇒ Object
- #assert_send(send, msg = nil) ⇒ Object
- #assert_throws(sym, msg = "<#{sym.inspect}> should have been thrown.") ⇒ Object
- #exception_details(e, msg) ⇒ Object
- #flunk(msg = "Flunked") ⇒ Object
- #setup ⇒ Object
- #teardown ⇒ Object
Instance Attribute Details
#_assertions ⇒ Object
Returns the value of attribute _assertions.
182 183 184 |
# File 'lib/test/unit.rb', line 182 def _assertions @_assertions end |
Class Method Details
.inherited(klass) ⇒ Object
174 175 176 |
# File 'lib/test/unit.rb', line 174 def self.inherited klass @@test_suites[klass] = true end |
.reset ⇒ Object
168 169 170 |
# File 'lib/test/unit.rb', line 168 def self.reset @@test_suites = {} end |
.test_suites ⇒ Object
178 179 180 |
# File 'lib/test/unit.rb', line 178 def self.test_suites @@test_suites.keys.sort_by { |ts| ts.name } end |
Instance Method Details
#_increment_assertions ⇒ Object
186 187 188 189 |
# File 'lib/test/unit.rb', line 186 def _increment_assertions @_assertions ||= 0 @_assertions += 1 end |
#assert(test, msg = "failed assertion (no message given)") ⇒ Object
191 192 193 194 |
# File 'lib/test/unit.rb', line 191 def assert test, msg = "failed assertion (no message given)" _increment_assertions raise MiniTest::Assertion, msg unless test end |
#assert_block(msg = "assert_block failed.") ⇒ Object
196 197 198 |
# File 'lib/test/unit.rb', line 196 def assert_block msg = "assert_block failed." assert yield, msg end |
#assert_equal(exp, act, msg = "") ⇒ Object
200 201 202 203 |
# File 'lib/test/unit.rb', line 200 def assert_equal exp, act, msg = "" msg += '.' unless msg.empty? assert exp == act, "#{msg}\n<#{exp.inspect}> expected but was\n<#{act.inspect}>.".strip end |
#assert_in_delta(exp, act, delta, msg = "Expected #{exp} to be within #{delta} of #{act}") ⇒ Object
205 206 207 |
# File 'lib/test/unit.rb', line 205 def assert_in_delta exp, act, delta, msg = "Expected #{exp} to be within #{delta} of #{act}" assert delta.to_f > (exp.to_f - act.to_f).abs, msg end |
#assert_instance_of(cls, obj, msg = "Expected #{obj.inspect} to be an instance of #{cls}") ⇒ Object
209 210 211 |
# File 'lib/test/unit.rb', line 209 def assert_instance_of cls, obj, msg = "Expected #{obj.inspect} to be an instance of #{cls}" assert cls === obj, msg end |
#assert_kind_of(cls, obj, msg = "Expected #{obj.inspect} to be a kind of #{cls}") ⇒ Object
213 214 215 |
# File 'lib/test/unit.rb', line 213 def assert_kind_of cls, obj, msg = "Expected #{obj.inspect} to be a kind of #{cls}" assert obj.kind_of?(cls), msg end |
#assert_match(exp, act, msg = "Expected #{act.inspect} to match #{exp.inspect}") ⇒ Object
217 218 219 |
# File 'lib/test/unit.rb', line 217 def assert_match exp, act, msg = "Expected #{act.inspect} to match #{exp.inspect}" assert act =~ exp, msg end |
#assert_nil(obj, msg = "Expected #{obj.inspect} to be nil") ⇒ Object
221 222 223 |
# File 'lib/test/unit.rb', line 221 def assert_nil obj, msg = "Expected #{obj.inspect} to be nil" assert obj.nil?, msg end |
#assert_no_match(exp, act, msg = "Expected #{act.inspect} to not match #{exp.inspect}") ⇒ Object
225 226 227 |
# File 'lib/test/unit.rb', line 225 def assert_no_match exp, act, msg = "Expected #{act.inspect} to not match #{exp.inspect}" assert act !~ exp, msg end |
#assert_not_equal(exp, act, msg = "Expected #{act.inspect} to not be equal to #{exp.inspect}") ⇒ Object
229 230 231 |
# File 'lib/test/unit.rb', line 229 def assert_not_equal exp, act, msg = "Expected #{act.inspect} to not be equal to #{exp.inspect}" assert exp != act, msg end |
#assert_not_nil(obj, msg = "Expected #{obj.inspect} to not be nil") ⇒ Object
233 234 235 |
# File 'lib/test/unit.rb', line 233 def assert_not_nil obj, msg = "Expected #{obj.inspect} to not be nil" assert ! obj.nil?, msg end |
#assert_not_same(exp, act, msg = "Expected #{act.inspect} to not be the same as #{exp.inspect}") ⇒ Object
237 238 239 |
# File 'lib/test/unit.rb', line 237 def assert_not_same exp, act, msg = "Expected #{act.inspect} to not be the same as #{exp.inspect}" assert ! exp.equal?(act), msg end |
#assert_nothing_raised ⇒ Object Also known as: assert_nothing_thrown
241 242 243 244 245 246 |
# File 'lib/test/unit.rb', line 241 def assert_nothing_raised _increment_assertions yield rescue => e raise MiniTest::Assertion, exception_details(e, "Exception raised:") end |
#assert_operator(o1, op, o2, msg = "<#{o1.inspect}> expected to be\n#{op.inspect}\n<#{o2.inspect}>.") ⇒ Object
250 251 252 |
# File 'lib/test/unit.rb', line 250 def assert_operator o1, op, o2, msg = "<#{o1.inspect}> expected to be\n#{op.inspect}\n<#{o2.inspect}>." assert o1.__send__(op, o2), msg end |
#assert_raises(*exp) ⇒ Object Also known as: assert_raise
258 259 260 261 262 263 264 265 266 267 268 269 270 271 |
# File 'lib/test/unit.rb', line 258 def assert_raises *exp msg = String === exp.last ? exp.pop : nil exp = exp.first if exp.size == 1 begin yield raise MiniTest::Assertion, "<#{exp.inspect}> exception expected but none was thrown." rescue Exception => e assert((Array === exp ? exp.include?(e) : exp === e), exception_details(e, "<#{exp.inspect}> exception expected but was")) return e end end |
#assert_respond_to(obj, meth, msg = "Expected #{obj.inspect} of type #{obj.class} to respond_to? #{meth.inspect}") ⇒ Object
274 275 276 |
# File 'lib/test/unit.rb', line 274 def assert_respond_to obj, meth, msg = "Expected #{obj.inspect} of type #{obj.class} to respond_to? #{meth.inspect}" assert obj.respond_to?(meth), msg end |
#assert_same(exp, act, msg = "Expected #{act.inspect} to be the same as #{exp.inspect}.") ⇒ Object
278 279 280 |
# File 'lib/test/unit.rb', line 278 def assert_same exp, act, msg = "Expected #{act.inspect} to be the same as #{exp.inspect}." assert exp.equal?(act), msg end |
#assert_send(send, msg = nil) ⇒ Object
282 283 284 285 286 |
# File 'lib/test/unit.rb', line 282 def assert_send send, msg = nil recv, meth, *args = send assert(recv.__send__(meth, *args), msg || "<#{recv.inspect}> expected to respond to\n<#{meth.inspect}> with a true value.") end |
#assert_throws(sym, msg = "<#{sym.inspect}> should have been thrown.") ⇒ Object
288 289 290 291 292 293 294 295 |
# File 'lib/test/unit.rb', line 288 def assert_throws sym, msg = "<#{sym.inspect}> should have been thrown." caught = true catch(sym) do yield rescue nil caught = false end assert caught, msg end |
#exception_details(e, msg) ⇒ Object
254 255 256 |
# File 'lib/test/unit.rb', line 254 def exception_details e, msg "#{msg}\nClass: <#{e.class}>\nMessage: <#{e..inspect}>\n---Backtrace---\n#{filter_backtrace(e.backtrace).join("\n")}\n---------------" end |
#flunk(msg = "Flunked") ⇒ Object
297 298 299 |
# File 'lib/test/unit.rb', line 297 def flunk msg = "Flunked" assert false, msg end |
#setup ⇒ Object
183 |
# File 'lib/test/unit.rb', line 183 def setup; end |
#teardown ⇒ Object
184 |
# File 'lib/test/unit.rb', line 184 def teardown; end |