Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Enhance 'spec' mode class names #8

Closed
bitprophet opened this Issue · 0 comments

1 participant

@bitprophet
Owner

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.
  2. 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.
  2. Ye olde "use a decorator argument string" approach, e.g. @test('Foo') \n class <Whatever>(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.
@bitprophet bitprophet closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.