cannot compose not with beSome.like?

115 views
Skip to first unread message

yues...@gmail.com

unread,
Apr 25, 2013, 2:54:07 PM4/25/13
to specs2...@googlegroups.com
Hi,

I'm using 2.10-1.14. This is the spec that demonstrate the problem:

import org.specs2.mutable.Specification

class BrokenNotSpec extends Specification {
  "not is broken for beSome.like" in {
    Some(4) must not(beSome.like({ case x => x must_== 1 }))
  }
}

It produces a failure while pass is expected. The example is contrived, but in my real tests, I have a custom matcher built using beSome.like, and I want to be able to use "not" with it. Is this a bug or am I doing something wrong?

Thanks,

Yuesong Wang


yues...@gmail.com

unread,
Apr 25, 2013, 3:39:37 PM4/25/13
to specs2...@googlegroups.com
OK, I found a workaround:

import org.specs2.mutable.Specification

class BrokenNotSpec extends Specification {

  "not is broken for beSome.like" in {
    Some(4) must not(beSomeOneBroken)
  }

  "not is working for this workaround" in {
    None must not(beSomeOneWorking)
    Some(4) must not(beSomeOneWorking)
    Some(1) must beSomeOneWorking
  }

  val beSomeOneBroken = ({ opt: Option[Int] => opt }) ^^ beSome.like({ case x => x must_== 1 })
  val beSomeOneWorking = ({ opt: Option[Int] => opt }) ^^ beSome and ((_: Option[Int]).get) ^^ beEqualTo(1)

}

The first example is the refactored version of the original, where a custom matcher is built using beSome.like. The second example demonstrates how to build a working matcher that does not use beSome.like. I think the partial function in beSome.like throws a match failure exception that bubbles all the way up (not negated by "not").

Thanks for reading.

Yuesong

etorreborre

unread,
Apr 25, 2013, 8:03:25 PM4/25/13
to specs2...@googlegroups.com
Thanks Yuesong for reporting this issue, it is fixed now in 1.15-SNAPSHOT.

E.

Yuesong Wang

unread,
Apr 25, 2013, 9:14:58 PM4/25/13
to specs2...@googlegroups.com
Thanks for the quick turn around!

--
You received this message because you are subscribed to a topic in the Google Groups "specs2-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/specs2-users/8KF2kV7NFY8/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to specs2-users...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages