Class: ZenTest

Class | ZenTest
In: | lib/zentest.rb
Parent: | Object

ZenTest scans your target and unit-test code and writes your missing code based on simple naming rules, enabling XP at a much quicker pace. ZenTest only works with Ruby and Test::Unit.

## RULES

ZenTest uses the following rules to figure out what code should be generated:

- Definition:
  - CUT = Class Under Test
  - TC = Test Class (for CUT)
- TC‘s name is the same as CUT w/ "Test" prepended at every scope level.
  - Example: TestA::TestB vs A::B.
- CUT method names are used in CT, with "test_" prependend and optional "_ext" extensions for differentiating test case edge boundaries.
  - Example:
    - A::B#blah
    - TestA::TestB#test_blah_normal
    - TestA::TestB#test_blah_missing_file
- All naming conventions are bidirectional with the exception of test extensions.

See ZenTestMapping for documentation on method naming.

### Methods

add_missing_method analyze analyze_impl analyze_test autotest convert_class_name create_method fix generate_code get_class get_inherited_methods_for get_methods_for is_test_class load_file methods_and_tests missing_methods new process_class result scan_files test_to_normal

### Included Modules

ZenTestMapping

### Constants

VERSION | = | '4.1.4'

### Public Class methods

autotest(*klasses)

Process all the supplied classes for methods etc, and analyse the results. Generate the skeletal code and eval it to put the methods into the runtime environment.

fix(*files)

Runs ZenTest over all the supplied files so that they are analysed and the missing methods have skeleton code written.

new()

### Public Instance methods

add_missing_method(klassname, methodname)

Adds a missing method to the collected results.

analyze()

Walk each known class and test that each method has a test method Then do it in the other direction…

analyze_impl(klassname)

Checks, for the given class klassname, that each method has a corrsponding test method. If it doesn‘t this is added to the information for that class

analyze_test(testklassname)

For the given test class testklassname, ensure that all the test methods have corresponding (normal) methods. If not, add them to the information about that class.

convert_class_name(name)

Generate the name of a testclass from non-test class so that Foo::Blah => TestFoo::TestBlah, etc. It the name is already a test class, convert it the other way.

create_method(indentunit, indent, name)

create a given method at a given indentation. Returns an array containing the lines of the method.

generate_code()

Using the results gathered during analysis generate skeletal code with methods raising NotImplementedError, so that they can be filled in later, and so the tests will fail to start with.

get_class(klassname)

obtain the class klassname, either from Module or using ObjectSpace to search for it.

get_inherited_methods_for(klass, full)

Return the methods for class klass, as a hash with the method nemas as keys, and true as the value for all keys. Unless full is true, leave out the methods for Object which all classes get.

get_methods_for(klass, full=false)

Get the public instance, class and singleton methods for class klass. If full is true, include the methods from Kernel and other modules that get included. The methods suite, new, pretty_print, pretty_print_cycle will not be included in the resuting array.

is_test_class(klass)

Check the class klass is a testing class (by inspecting its name).

load_file(file)

load_file wraps require, skipping the loading of $0.

methods_and_tests(klassname, testklassname)

looks up the methods and the corresponding test methods in the collection already built. To reduce duplication and hide implementation details.

missing_methods()
process_class(klassname, full=false)

Does all the work of finding a class by name, obtaining its methods and those of its superclass. The full parameter determines if all the methods including those of Object and mixed in modules are obtained (true if they are, false by default).

result()

presents results in a readable manner.

scan_files(*files)

Work through files, collecting class names, method names and assertions. Detects ZenTest (SKIP|FULL) comments in the bodies of classes. For each class a count of methods and test methods is kept, and the ratio noted.

test_to_normal(_name, klassname=nil)

[Validate]