Class: PryTest::Test

Inherits:
Object
  • Object
show all
Defined in:
lib/pry-test/test.rb

Overview

Superclass for all test classes.

Examples:

Create a subclass with a test.

class SimpleTest < PryTest::Test
  test "common sense" do
    assert 1 > 0
  end
end

Class Method Summary collapse

Class Method Details

.after(what = nil) { ... } ⇒ Object

Defines a teardown method that will run after each individual test.

Parameters:

  • what (Symbol) (defaults to: nil)

    Deprecated but maintained for backwards compatibility.

Yields:

  • A block of code that will serve as the teardown method.



40
41
42
# File 'lib/pry-test/test.rb', line 40

def after(what=nil, &block)
  @after = block
end

.before(what = nil) { ... } ⇒ Object

Defines a setup method that will run before each individual test.

Parameters:

  • what (Symbol) (defaults to: nil)

    Deprecated but maintained for backwards compatibility.

Yields:

  • A block of code that will serve as the setup method.



33
34
35
# File 'lib/pry-test/test.rb', line 33

def before(what=nil, &block)
  @before = block
end

.inherited(subclass) ⇒ Object

A callback provided by Ruby that is invoked whenever a subclass is created.



26
27
28
# File 'lib/pry-test/test.rb', line 26

def inherited(subclass)
  subclasses << subclass
end

.subclassesArray<PryTest::Test>

All subclasses of this class.

Returns:



15
16
17
# File 'lib/pry-test/test.rb', line 15

def subclasses
  @subclasses ||= []
end

.test(desc) { ... } ⇒ Object

Defines a test. Allows subclasses to define tests in their class definition.

Examples:

class SimpleTest < PryTest::Test
  test "common sense" do
    assert 1 > 0
  end
end

Parameters:

  • desc (String)

    A description for the test.

Yields:

  • A block that defines the test code.



56
57
58
59
60
61
# File 'lib/pry-test/test.rb', line 56

def test(desc, &block)
  wrapper = PryTest::TestWrapper.new(self, desc, &block)
  wrapper.create_method(:before, &@before) if @before
  wrapper.create_method(:after, &@after) if @after
  tests << wrapper
end

.testsArray<PryTest::TestWrapper>

All individual tests defined in this class.

Returns:



21
22
23
# File 'lib/pry-test/test.rb', line 21

def tests
  @tests ||= []
end