"fail" method gone (when upgrading from specs 1)

2,048 views
Skip to first unread message

Mathias

unread,
Jul 18, 2011, 9:52:33 AM7/18/11
to specs2-users
Eric,

specs 1 Specifications implemented the FailOrSkip trait which defined
a `fail` method with this signature:

def fail(msg: String): Nothing

This was nice since ScalaTest also defines such a method (as do TestNG
and JUnit), which makes it easy to write general test support code
that works with all major test frameworks (by simply hooking into the
fail method with a structural type),

Unfortunately specs2 doesn't seem to provide a `fail` method with the
above signature.
Is there a specific reason for this?

Would it be possible to re-add the `fail` method` ?

Cheers,
Mathias

etorreborre

unread,
Jul 18, 2011, 4:14:04 PM7/18/11
to specs2...@googlegroups.com
Hi Mathias,

Those methods exist on the ThrownExpectations trait and are called `failure` and `skipped` (to match with the corresponding org.specs2.execute.Result names).

Eric.

Mathias

unread,
Jul 19, 2011, 5:22:16 AM7/19/11
to specs2-users
I see...
Wouldn't it be good to add "fail" and "skip" alias methods for
providing compatibility with ScalaTest and Specs?

As a library author I'd like to leave the decision, which test
framework to use, to my users and still provide some test support
code.
The easiest way, which so far (with Specs 1, ScalaTest, TestNG, JUnit)
worked nicely, was to have a `TestSupport` trait that you can mix into
your tests:

trait TestSupport {
this: { def fail(msg: String): Nothing } =>
...
}

This trait can be mixed into all test classes from frameworks that
define a `fail` method taking a String.
All major frameworks do this, except (so far) specs2.

If you decide that two or three more aliases would clutter up the
Specs2 API too much I'll have to resort to some structural type class
solution, which would probably still work but introduce more overhead.

What do you think?

Cheers,
Mathias

etorreborre

unread,
Jul 19, 2011, 6:42:41 AM7/19/11
to specs2...@googlegroups.com
I get it now. That's a very good idea.

I just published a snapshot (1.6-SNAPSHOT) with an additional trait that people can mix when required. Something like:

  import org.specs2.mutable._
  import org.specs2.matcher._

  class MySpec extends Specification with ThrownMessages with SprayTesting {
    ...
  }

Eric.

Mathias

unread,
Jul 19, 2011, 8:06:26 AM7/19/11
to specs2-users
Thanks, Eric, that should do it.

Cheers,
Mathias
Reply all
Reply to author
Forward
0 new messages