Skip to content

Instantly share code, notes, and snippets.

@poetix
Last active December 16, 2015 13:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save poetix/5443366 to your computer and use it in GitHub Desktop.
Save poetix/5443366 to your computer and use it in GitHub Desktop.
Demonstrating a Map matcher with improved failure reporting
package com.youdevise.matchless
import org.specs2.matcher.MustMatchers._
import com.youdevise.matchless.Collections._
object HasThePairsWorksheet {
val testMap = Map(
"a" -> "Apple",
"b" -> "Banana",
"c" -> "Carrot"
) //> testMap : scala.collection.immutable.Map[java.lang.String,java.lang.String]
//| = Map(a -> Apple, b -> Banana, c -> Carrot)
(testMap must haveThePairs(
"a" -> "Apple",
"b" -> "Banana",
"c" -> "Cactus",
"d" -> "Dragonfruit"
)).message //> res0: String = some of the expected key/value pairs were not present in the
//| collection:
//|
//| a: Apple
//| b: Banana
//| * c: 'Carrot' is not equal to 'Cactus'
//| * d: <missing value>
(testMap must havePairsLike(
"a" -> contain("pp"),
"b" -> contain("anana"),
"c" -> contain("actus")
)).message //> res1: String = some of the expected key/value pairs were not present in the
//| collection:
//|
//| a: Apple
//| b: Banana
//| * c: 'Carrot' doesn't contain 'actus'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment