These are chat archives for etorreborre/specs2

Jan 2017
Jan 23 2017 14:05 UTC
How do I check if a list contains some element using a custom function for equality?
val people = List(Person(1, "Bjarne"), Person(2, "Max"))
I need a matcher like this:
people must contain(person => == 2)
(ie. I don't want to bother equality checking a bunch of fields that isn't relevant in the particular case)
Zacharias J. Beckman
Jan 23 2017 19:31 UTC

@holograph have you any experience running AkkaTestKit in specs2? One of our engineers ran into this problem:

def verifyMatch = {
  new AkkaTestkitSpecs2Support {
    true must beFalse           // pass
    true must beEqualTo(false)  // pass
    true === false              // pass
    true must be_==(false)      // pass
    "abc" must beEqualTo("def") // pass

    assert(true must beFalse)           // fails
    assert("abc" must beEqualTo("def")) // fails

In other words, all specs2 matchers pass in all situations. He is resorting to using assert(). Wondering if you have thoughts on this.

Zacharias J. Beckman
Jan 23 2017 20:03 UTC
@etorreborre ^ above was meant for you :)
Eric Torreborre
Jan 23 2017 20:04 UTC
I'll check that in a moment
Eric Torreborre
Jan 23 2017 20:26 UTC
@drhumlen you can write people must contain((person: Person) => === 2).forall but also people must contain(idIs2).forall if idIs2: Matcher[Person]
@zbeckman if you are using org.specs2.Specification as your base specification trait you should mix-in org.specs2.matcher.ThrownExpectations. Otherwise each statement like true must beEqualTo(false) is just a pure expression that has no impact whatsoever on the creation of the new AkkaTestkitSpecs2Support object
Zacharias J. Beckman
Jan 23 2017 21:33 UTC
@drhumlen thanks for the feedback :) much appreciated
@etorreborre oops I mean Eric :)