bitprophet/spec — Issue #8: Enhance 'spec' mode class names
Author: bitprophet
Created: 2011-11-06 23:11:38+00:00
State: open

When running via `spec`, any public name is accepted as a test class. However, in the normal use case of "class Foo does x, has attribute y", naming the *test class* Foo causes a conflict with the class under test.

Solutions not requiring any code change:

1. Continue naming test classes as `TestFoo`, since spec-the-plugin strips out the test prefix automagically when printing.
* Verbose-ish, code doesn't read the same way as output does, but no work needed.
1. Import class under test as a different name, e.g. `from whatever.package import Foo as Foo_`.
* Less verbose, allows test class to "read" normally, but if one is referring to the real class a lot, it looks kind of gross; and makes it easier to accidentally type `Foo` when you mean `Foo_`.

Solutions that could be supported by `spec:

1. Extend the automatic test-class name munging to support additional patterns, e.g. `Foo_` prints as `Foo`
* Reads a little better than `TestFoo` while remaining distinct; no obvious downside besides confusion with `_PrivateNames`.
1. Ye olde "use a decorator argument string" approach, e.g. `@test('Foo') \n class (object): [...]`.
* Has ye olde decorator problem: bound name of decorated object becomes completely pointless and thus ugly/boilerplate, even if using e.g. `class _(object):`, or duplicative if both are similar (e.g. `@tests('Foo') \n class Foo_ [...]`)

----

This is all pretty over-thinky. Feels like the best thing to do is:

* Make the `TestFoo` prints as `Foo` feature obviously documented (it's just implied via example right now)
* Implement the extension of same to trim trailing underscores, as mentioned above, and document that too.