Module: Test::Spec::TestCase::ClassMethods

### Home Classes Methods

### In Files

- lib/test/spec.rb

### Methods

- #after
- #before
- #behaves_like
- #context
- #describe
- #describe_shared
- #init
- #it
- #it_should_behave_like
- #setup
- #shared_context
- #specify
- #teardown
- #xcontext
- #xit
- #xspecify

### Files

- README
- ROADMAP
- SPECS

### Class/Module Index

Quicksearch

- Test
- Test::Spec
- Test::Spec::CustomShould
- Test::Spec::DefinitionError
- Test::Spec::Should
- Test::Spec::ShouldNot
- Test::Spec::TestCase
- Test::Spec::TestCase::ClassMethods
- Test::Spec::TestCase::InstanceMethods
- Test::Unit
- Test::Unit::UI
- Test::Unit::UI::RDox
- Test::Unit::UI::RDox::TestRunner
- Test::Unit::UI::SpecDox
- Test::Unit::UI::SpecDox::TestRunner
- Object

No matching classes.

# Test::Spec::TestCase::ClassMethods

### Attributes

after_all[RW]
before_all[RW]
count[RW]
name[RW]
parent[RW]
position[RW]
setups[RW]
teardowns[RW]

### Public Instance Methods

after(kind=:each, &block) click to toggle source

    # 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) click to toggle source

    # 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) click to toggle source

    # 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

Also aliased as: it_should_behave_like
context(name, superclass=Test::Unit::TestCase, klass=Test::Spec::TestCase, &block) click to toggle source

old-style (RSpec <1.0):

    # 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

Also aliased as: describe
describe(name, superclass=Test::Unit::TestCase, klass=Test::Spec::TestCase, &block) click to toggle source

new-style (RSpec 1.0+):

Alias for: context
describe_shared(name, &block) click to toggle source
Alias for: shared_context
init(name, position, parent) click to toggle source

    # 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

it(specname, &block) click to toggle source
Alias for: specify
it_should_behave_like(shared_context) click to toggle source
Alias for: behaves_like
setup(&block) click to toggle source

    # File lib/test/spec.rb, line 422
    def setup(&block)
      setups << block
    end

shared_context(name, &block) click to toggle source

    # File lib/test/spec.rb, line 430
    def shared_context(name, &block)
      Test::Spec::SHARED_CONTEXTS[self.name + "\t" + name] << block
    end

Also aliased as: describe_shared
specify(specname, &block) click to toggle source

    # 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

Also aliased as: it
teardown(&block) click to toggle source

    # File lib/test/spec.rb, line 426
    def teardown(&block)
      teardowns << block
    end

xcontext(name, superclass=Test::Unit::TestCase, &block) click to toggle source

    # File lib/test/spec.rb, line 404
    def xcontext(name, superclass=Test::Unit::TestCase, &block)
      context(name, superclass, Test::Spec::DisabledTestCase, &block)
    end

xit(specname, &block) click to toggle source
Alias for: xspecify
xspecify(specname, &block) click to toggle source

    # File lib/test/spec.rb, line 416
    def xspecify(specname, &block)
      specify specname do
        @_result.add_disabled(specname)
      end
    end

Also aliased as: xit

[Validate]

Generated with the Darkfish Rdoc Generator 2.