Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If Scope extends MustExpectations - it causes failing tests to look like running and **passing** #321

Closed
maximn opened this issue Jan 18, 2015 · 6 comments

Comments

@maximn
Copy link

maximn commented Jan 18, 2015

Here's a sample code -

package com.sample

import org.specs2.matcher.MustExpectations
import org.specs2.mutable.SpecificationWithJUnit
import org.specs2.specification.Scope


class BadTest extends SpecificationWithJUnit {

  trait ctx extends Scope with MustExpectations {}

  "Wrong statement" should {
    "be failed by a test" in new ctx {
      true must be_===(false)
    }
  }
}


//trait ctx extends Scope with Matchers with MustExpectations {
//  def someThingThatUsesMust(x: AnyRef) = x must beNull
//}

As you can see in the screenshot - IntelliJ shows the test as running and green.
IntelliJ screenshot

@etorreborre
Copy link
Owner

Yes, it needs to extend MustThrownExpectations for exceptions to be thrown and caught outside of the Scope trait.

@etorreborre
Copy link
Owner

Also, in this specific example you shouldn't need to create MustExpectations because MustThrownExpectations is already mixed in org.specs2.mutable.SpecificationWithJUnit and allows to create expectations already. So I guess that you are creating the ctx trait outside of a specific Specification to be able to reuse it, right?

@maximn
Copy link
Author

maximn commented Jan 20, 2015

Maybe I shouldn't use MustExpectations, but if I do, I expect to get an error somewhere.
Yes, I use it outside. Actually in my case my context extends a trait that extends MustExpectations but I wanted to provide the most simple example.

@etorreborre
Copy link
Owner

There are 2 traits offering the same API but having different implementations: MustExpectations and MustThrownExpectations. As the name indicates MustThrownExpectations must be used where exceptions are expected for control flow. Typically in this situation where code is being placed in the body of a trait (the ctx trait); if no exception is thrown there is no way to get notified of failures.

It would be better to have a compilation error when MustExpectations is being mixed-in with Scope but I don't know how to do that.

@etorreborre
Copy link
Owner

I have added 2 methods on Scope and MustExpectations to detect this issue at compile-time. I'm not sure this is the best way to do it but that should work for now.

etorreborre added a commit that referenced this issue Jan 21, 2015
@etorreborre
Copy link
Owner

My fix is incorrect. I need a bit more time to find something else. In any case I would like a fix for this issue to happen at compile time rather than runtime (I thank you for your PR though :-)).

@etorreborre etorreborre reopened this Jan 21, 2015
etorreborre added a commit that referenced this issue Feb 3, 2015
#324

Conflicts:
	matcher/src/main/scala/org/specs2/matcher/MustExpectations.scala
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants