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

Make Implementing custom matchers and verbs easier #2

Open
mysticfall opened this issue Feb 2, 2015 · 1 comment
Open

Make Implementing custom matchers and verbs easier #2

mysticfall opened this issue Feb 2, 2015 · 1 comment

Comments

@mysticfall
Copy link
Member

For now, implementations of Verb trait don't share much in common, so complicating implementing custom matchers and verbs.

Ideally, there should be a convenient super structure to delegate common tasks to, and an easy way to register them without having to extend FollowedByNegation by an implicit conversion.

@mysticfall
Copy link
Member Author

Currently supported method to implement a custom matcher:

trait SvgTest extends HaveClass {
  this: TestSuite =>
}

trait HaveClass extends Words with Matchers with Conversions

object HaveClass {

  object HaveClassMatcher extends Matcher[SVGElement, HaveClass, String] {

    override def matches(actual: SVGElement, expected: String): Unit = if (!actual.hasClass(expected))
      throw TestFailureException(s"Expected the elment to have class '$expected' but it didn't.")

    override def notMatches(actual: SVGElement, expected: String): Unit = if (actual.hasClass(expected))
      throw TestFailureException(s"Expected the elment not to have class '$expected' but it did.")
  }

  class HaveClass extends AbstractVerb("have class") {

    def apply[A, E](expectation: Expectation[E])(implicit matcher: Matcher[A, HaveClass, E]) =
      WhatIsExpected(this, expectation)
  }

  trait Words {

    val have_class = new HaveClass
  }

  object Words extends Words

  trait Matchers extends MediumPriorityMatchers {

    implicit val haveClassMatcher = HaveClassMatcher
  }

  trait Conversions {

    implicit class FollowedByNegationEx[A](fbn: FollowedByNegation[A]) {

      def have_class[E](expectation: Expectation[E])(implicit matcher: Matcher[A, HaveClass, E]): Assertation[A, HaveClass, E] =
        fbn.builder.assert(WhatIsExpected(Words.have_class, !expectation))
    }
  }
}

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

No branches or pull requests

1 participant