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.
396 397 398 |
# File 'lib/test/spec.rb', line 396 def after_all @after_all end |
#before_all ⇒ Object
Returns the value of attribute before_all.
395 396 397 |
# File 'lib/test/spec.rb', line 395 def before_all @before_all end |
#count ⇒ Object
Returns the value of attribute count.
387 388 389 |
# File 'lib/test/spec.rb', line 387 def count @count end |
#name ⇒ Object
Returns the value of attribute name.
388 389 390 |
# File 'lib/test/spec.rb', line 388 def name @name end |
#parent ⇒ Object
Returns the value of attribute parent.
390 391 392 |
# File 'lib/test/spec.rb', line 390 def parent @parent end |
#position ⇒ Object
Returns the value of attribute position.
389 390 391 |
# File 'lib/test/spec.rb', line 389 def position @position end |
#setups ⇒ Object
Returns the value of attribute setups.
392 393 394 |
# File 'lib/test/spec.rb', line 392 def setups @setups end |
#teardowns ⇒ Object
Returns the value of attribute teardowns.
393 394 395 |
# File 'lib/test/spec.rb', line 393 def teardowns @teardowns end |
Instance Method Details
#after(kind = :each, &block) ⇒ Object
467 468 469 470 471 472 473 474 475 476 |
# File 'lib/test/spec.rb', line 467 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
456 457 458 459 460 461 462 463 464 465 |
# File 'lib/test/spec.rb', line 456 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
434 435 436 437 438 439 440 441 442 443 444 445 446 |
# File 'lib/test/spec.rb', line 434 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):
400 401 402 |
# File 'lib/test/spec.rb', line 400 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
479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 |
# File 'lib/test/spec.rb', line 479 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
422 423 424 |
# File 'lib/test/spec.rb', line 422 def setup(&block) setups << block end |
#shared_context(name, &block) ⇒ Object Also known as:
430 431 432 |
# File 'lib/test/spec.rb', line 430 def shared_context(name, &block) Test::Spec::SHARED_CONTEXTS[self.name + "\t" + name] << block end |
#specify(specname, &block) ⇒ Object Also known as: it
408 409 410 411 412 413 414 |
# File 'lib/test/spec.rb', line 408 def specify(specname, &block) raise ArgumentError, "specify needs a block" 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
426 427 428 |
# File 'lib/test/spec.rb', line 426 def teardown(&block) teardowns << block end |
#xcontext(name, superclass = Test::Unit::TestCase, &block) ⇒ Object
404 405 406 |
# File 'lib/test/spec.rb', line 404 def xcontext(name, superclass=Test::Unit::TestCase, &block) context(name, superclass, Test::Spec::DisabledTestCase, &block) end |
#xspecify(specname, &block) ⇒ Object Also known as: xit
416 417 418 419 420 |
# File 'lib/test/spec.rb', line 416 def xspecify(specname, &block) specify specname do @_result.add_disabled(specname) end end |