Skip to content

Instantly share code, notes, and snippets.

@mkmik
Created December 13, 2010 23:09
Show Gist options
  • Save mkmik/739767 to your computer and use it in GitHub Desktop.
Save mkmik/739767 to your computer and use it in GitHub Desktop.
package eu.rinfrastructures
import org.specs._
trait FunctionalMatchers {
import org.specs.matcher.Matcher
type byNameMatcherFunction [A] = (=> A) => (Boolean, String, String)
type byValueMatcherFunction[A] = A => (Boolean, String, String)
implicit def byNameFunction2matcher[A] (f : byNameMatcherFunction[A]) = new Matcher[A] {
def apply(v: => A) = f(v)
}
implicit def byValueFunction2matcher[A] (f : byValueMatcherFunction[A]) = new Matcher[A] {
def apply(v: => A) = f(v)
}
}
trait ShortMatcher {
// cannot use by-name functional literals
def fBeLazyEven(number: => Int) = {
val b = number; (b % 2 == 0, b + " is even", b + " is odd")
}
val beLazyEven = fBeLazyEven _
}
trait VeryShortMatcher {
def beEven = (b: Int) => (true, "great", "failure")
}
object newSpecification extends Specification with FunctionalMatchers
with ShortMatcher with VeryShortMatcher {
"short matchers" should {
"allow us to do" in {
"it's terse".size must beEven
"it's terse".size must beLazyEven
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment