Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add implicit conversion for org.hamcrest.Matcher[T] to specs2.Matcher[T] #114

Closed
electricmonk opened this Issue · 2 comments

2 participants

@electricmonk

In a StackOverflow question I asked, Eric showed that it's rather trivial to convert from the org.hamcrest.matcher[T] interface to Specs2's Matcher[T] trait:

http://stackoverflow.com/questions/13126705/specs2-use-a-hamcrest-matcher

I would like to see this implicit conversion (note that in the SO thread there's an error, should be Matcher[T] rather than TypeSafeMatcher[T[) added into the Specs2 codebase, either as an optional Trait or directly into the Matchers trait.

IMO backwards compatibility with Java system is a must in mature Scala frameworks. At Wix.com, we have zillions of proprietary Hamcrest matchers for our domain objects, being able to use them from Scala determines if we migrate to Specs2 or not.

Thanks.

@etorreborre etorreborre closed this issue from a commit
@etorreborre fixed #114. Added a Hamcrest trait to enable implicit conversions fro…
…m Hamcrest matchers to specs2 matchers
bddd398
@etorreborre
Owner

Please try the latest 1.12.3-SNAPSHOT. Note that the reuse of some Hamcrest matchers might be problematic though due to the interoperability between Scala and Java.

For example, in the documentation I give:

// a Hamcrest matcher for even numbers
object beEven extends BaseMatcher[Int] {
  def matches(item: Object): Boolean       = item.toString.toInt % 2 == 0
  def describeTo(description: Description) { description.appendText(" is odd") }
}

I tried to make it a TypesafeMatcher but that didn't work because the expected type was int, the primitive type from Java, whereas the number I was passing in my test was a Scala Int.

Anyway, I hope there is now no more obstacle for you to use specs2 at Wix.com :-)!

@electricmonk

Thanks!

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.