52
votes

I started working my way through the Scala Koans, which is organized around a suite of unit tests with blanks that one needs to fill in. (This idea was modeled after a similar Ruby Koans project.) You start the sbt tool running a test, and it admonishes:

[info]   + ***************************************** 
[info]   +  
[info]   +  
[info]   +  
[info]   + Please meditate on koan "None equals None" of suite "AboutEmptyValues" 
[info]   +  
[info]   +  
[info]   +  
[info]   + ***************************************** 

...and so you go look at this unit test and it says:

test("None equals None") {
  assert(None === __)
}

...and, after meditation, you realize that you should fill in the blank like this:

test("None equals None") {
  assert(None === None)
}

...and then it moves on to the next unit test.

My question, though, is what is this === operator? I can't seem to find it anywhere. Is this a DSL operator defined in the Scala Koans project itself? Or is it part of the ScalaTest framework? Or in Scala proper?

1

1 Answers

89
votes

This is the triple-equals operator from ScalaTest. Have a look at this page: Getting Started with FunSuite. It says:

ScalaTest lets you use Scala's assertion syntax, but defines a triple equals operator (===) to give you better error messages. The following code would give you an error indicating only that an assertion failed:

assert(1 == 2)

Using triple equals instead would give you the more informative error message, "1 did not equal 2":

assert(1 === 2)