Reputation: 2087
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
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
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