Module: Test::Spec::TestCase::ClassMethods
- Defined in:
- lib/test/spec.rb
Instance Attribute Summary collapse
-
#after_all ⇒ Object
Returns the value of attribute after_all.
-
#before_all ⇒ Object
Returns the value of attribute before_all.
-
#count ⇒ Object
Returns the value of attribute count.
-
#name ⇒ Object
Returns the value of attribute name.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#position ⇒ Object
Returns the value of attribute position.
-
#setups ⇒ Object
Returns the value of attribute setups.
-
#teardowns ⇒ Object
Returns the value of attribute teardowns.
Instance Method Summary collapse
- #after(kind = :each, &block) ⇒ Object
- #before(kind = :each, &block) ⇒ Object
- #behaves_like(shared_context) ⇒ Object (also: #it_should_behave_like)
-
#context(name, superclass = Test::Unit::TestCase, klass = Test::Spec::TestCase, &block) ⇒ Object
(also: #describe)
old-style (RSpec <1.0):.
- #init(name, position, parent) ⇒ Object
- #setup(&block) ⇒ Object
- #shared_context(name, &block) ⇒ Object (also: #describe_shared)
- #specify(specname, &block) ⇒ Object (also: #it)
- #teardown(&block) ⇒ Object
- #xcontext(name, superclass = Test::Unit::TestCase, &block) ⇒ Object
- #xspecify(specname, &block) ⇒ Object (also: #xit)
Instance Attribute Details
#after_all ⇒ Object
Returns the value of attribute after_all.
394 395 396 |
# File 'lib/test/spec.rb', line 394 def after_all @after_all end |
#before_all ⇒ Object
Returns the value of attribute before_all.
393 394 395 |
# File 'lib/test/spec.rb', line 393 def before_all @before_all end |
#count ⇒ Object
Returns the value of attribute count.
385 386 387 |
# File 'lib/test/spec.rb', line 385 def count @count end |
#name ⇒ Object
Returns the value of attribute name.
386 387 388 |
# File 'lib/test/spec.rb', line 386 def name @name end |
#parent ⇒ Object
Returns the value of attribute parent.
388 389 390 |
# File 'lib/test/spec.rb', line 388 def parent @parent end |
#position ⇒ Object
Returns the value of attribute position.
387 388 389 |
# File 'lib/test/spec.rb', line 387 def position @position end |
#setups ⇒ Object
Returns the value of attribute setups.
390 391 392 |
# File 'lib/test/spec.rb', line 390 def setups @setups end |
#teardowns ⇒ Object
Returns the value of attribute teardowns.
391 392 393 |
# File 'lib/test/spec.rb', line 391 def teardowns @teardowns end |
Instance Method Details
#after(kind = :each, &block) ⇒ Object
465 466 467 468 469 470 471 472 473 474 |
# File 'lib/test/spec.rb', line 465 def after(kind=:each, &block) case kind when :each teardown(&block) when :all after_all << block else raise ArgumentError, "invalid argument: after(#{kind.inspect})" end end |
#before(kind = :each, &block) ⇒ Object
454 455 456 457 458 459 460 461 462 463 |
# File 'lib/test/spec.rb', line 454 def before(kind=:each, &block) case kind when :each setup(&block) when :all before_all << block else raise ArgumentError, "invalid argument: before(#{kind.inspect})" end end |
#behaves_like(shared_context) ⇒ Object Also known as: it_should_behave_like
432 433 434 435 436 437 438 439 440 441 442 443 444 |
# File 'lib/test/spec.rb', line 432 def behaves_like(shared_context) if Test::Spec::SHARED_CONTEXTS.include?(shared_context) Test::Spec::SHARED_CONTEXTS[shared_context].each { |block| instance_eval(&block) } elsif Test::Spec::SHARED_CONTEXTS.include?(self.name + "\t" + shared_context) Test::Spec::SHARED_CONTEXTS[self.name + "\t" + shared_context].each { |block| instance_eval(&block) } else raise NameError, "Shared context #{shared_context} not found." end end |
#context(name, superclass = Test::Unit::TestCase, klass = Test::Spec::TestCase, &block) ⇒ Object Also known as: describe
old-style (RSpec <1.0):
398 399 400 |
# File 'lib/test/spec.rb', line 398 def context(name, superclass=Test::Unit::TestCase, klass=Test::Spec::TestCase, &block) (Test::Spec::CONTEXTS[self.name + "\t" + name] ||= klass.new(name, self, superclass)).add(&block) end |
#init(name, position, parent) ⇒ Object
477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 |
# File 'lib/test/spec.rb', line 477 def init(name, position, parent) self.position = position self.parent = parent if parent self.name = parent.name + "\t" + name else self.name = name end self.count = 0 self.setups = [] self.teardowns = [] self.before_all = [] self.after_all = [] end |
#setup(&block) ⇒ Object
420 421 422 |
# File 'lib/test/spec.rb', line 420 def setup(&block) setups << block end |
#shared_context(name, &block) ⇒ Object Also known as:
428 429 430 |
# File 'lib/test/spec.rb', line 428 def shared_context(name, &block) Test::Spec::SHARED_CONTEXTS[self.name + "\t" + name] << block end |
#specify(specname, &block) ⇒ Object Also known as: it
406 407 408 409 410 411 412 |
# File 'lib/test/spec.rb', line 406 def specify(specname, &block) xspecify(specname) and return if block.nil? self.count += 1 # Let them run in order of definition define_method("test_spec {%s} %03d [%s]" % [name, count, specname], &block) end |
#teardown(&block) ⇒ Object
424 425 426 |
# File 'lib/test/spec.rb', line 424 def teardown(&block) teardowns << block end |
#xcontext(name, superclass = Test::Unit::TestCase, &block) ⇒ Object
402 403 404 |
# File 'lib/test/spec.rb', line 402 def xcontext(name, superclass=Test::Unit::TestCase, &block) context(name, superclass, Test::Spec::DisabledTestCase, &block) end |
#xspecify(specname, &block) ⇒ Object Also known as: xit
414 415 416 417 418 |
# File 'lib/test/spec.rb', line 414 def xspecify(specname, &block) specify specname do @_result.add_disabled(specname) end end |