Skip to content
This repository has been archived by the owner on Mar 28, 2018. It is now read-only.

Custom matchers #4

Open
EECOLOR opened this issue Mar 3, 2015 · 1 comment
Open

Custom matchers #4

EECOLOR opened this issue Mar 3, 2015 · 1 comment

Comments

@EECOLOR
Copy link
Owner

EECOLOR commented Mar 3, 2015

Should we collect them in a separate library?

  def endWith(expected: String) =
    new Assertion[String] {
      def assert(s: => String) =
        if (s.endsWith(expected)) Right(success)
        else Left("The given string did not end with " + expected)
    }
@Hayena
Copy link

Hayena commented Mar 6, 2015

  private val beRight =
    new Assertion[Either[_, _]] {
      def assert(s: => Either[_, _]) =
        if (s.isRight) Success(success)
        else Failure("Expected Right")
    }

  private val beLeft: Assertion[Either[Any, _]] = beLeft(None)
  private def beLeft[T](expected: => T): Assertion[Either[T, _]] = beLeft(Some(expected))

  private def beLeft[T](expected: => Option[T]) =
    new Assertion[Either[T, _]] {
      def assert(s: => Either[T, _]) =
        s match {
          case Left(value) => Success(expected map (value is _) getOrElse success)
          case _ => Failure("Expected Left")
        }
    }

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants