Soufiaane
Soufiaane

Reputation: 2087

ScalaTest: Checking that list does not contain element

so i am new to scala and i need to check that a List does not contain an element.

here is the code i'm trying to write but abviously my syntax is wrong and i don't know how to do it:

  it should "return unique slugs for all category" in {
    val allCategories = categoryService.getAllCategories("rocket")
    val checkedCategories = List()
    allCategories.foreach(
      category => checkedCategories should notContains category.slug
    )
  } 

Upvotes: 0

Views: 2859

Answers (2)

Shane Perry
Shane Perry

Reputation: 990

Alternatively you could just map the slugs first and then check the sequence against its distinct self

val slugs = categoryService.getAllCategories("rocket").map(_.slug)
slugs.distinct.size shouldBe slugs.size

Upvotes: 0

chengpohi
chengpohi

Reputation: 14217

  checkedCategories should not contain category.slug

You can use not contain for collection contains checking.

http://www.scalatest.org/user_guide/using_matchers

Upvotes: 2

Related Questions