Hi Cay,
Sorry I've been at the JVM Languages Summit the past three days and
therefore slower to respond. The documentation for Assertions is here:
http://www.artima.com/scalatest/doc-1.0-SNAPSHOT/org/scalatest/Assertions.html
That's for 1.0, but it is the same for 0.9.5 (except I removed two
methods that had been deprecated for two releases already). For the
1.0 release I'll finally get a real user guide up on the web.
ScalaTest has always had very thorough documentation, but so far it
has pretty much been just in the scaladoc form.
Other than the form I mentioned in my previous email:
assert(a === b)
You can also say:
expect(a) { b }
The assert(a === b) form fails with "1 did not equal 2":
scala> import org.scalatest.Assertions._
import org.scalatest.Assertions._
scala> val a = 1
a: Int = 1
scala> val b = 2
b: Int = 2
scala> assert(a === b)
org.scalatest.TestFailedException: 1 did not equal 2
at org.scalatest.Assertions$class.newAssertionFailedException(Assertions.scala:278)
at org.scalatest.matchers.ShouldMatchers$.newAssertionFailedException(ShouldMatchers.scala:2318)
at org.scalatest.Assertions$class.assert(Assertions.scala:363)
at org.scalatest.matchers.ShouldMatchers$.assert(ShouldMatchers.scala:2318)
at .<init...
The === does not indicate that one value was expected and the other
actual, because it can be hard to remember which goes on which side of
the equals sign. If you want to differentiate between actual and
expected, you can use the expect form:
scala> expect(a) { b }
org.scalatest.TestFailedException: Expected 1, but got 2
at org.scalatest.Assertions$class.newAssertionFailedException(Assertions.scala:278)
at org.scalatest.matchers.ShouldMatchers$.newAssertionFailedException(ShouldMatchers.scala:2318)
at org.scalatest.Assertions$class.expect(Assertions.scala:577)
at org.scalatest.matchers.ShouldMatchers$.expect(ShouldMatchers.scala:2318)
at .<...
scala> expect(b) { a }
org.scalatest.TestFailedException: Expected 2, but got 1
at org.scalatest.Assertions$class.newAssertionFailedException(Assertions.scala:278)
at org.scalatest.matchers.ShouldMatchers$.newAssertionFailedException(ShouldMatchers.scala:2318)
at org.scalatest.Assertions$class.expect(Assertions.scala:577)
at org.scalatest.matchers.ShouldMatchers$.expect(ShouldMatchers.scala:2318)
at .<...
The value you are expecting goes in the parens after expect, and the
code that evaluates to the actual value goes in the curly braces. I
tend to use the expect form when the code that produces the actual
value is a bit longer:
expect(3) {
some.longer.expression.that.i.hope.results.in.three()
}
Can you elaborate on why the a should equal (b) didn't give you a good
output? It should print the toString of both a and b:
scala> import org.scalatest.matchers.ShouldMatchers._
import org.scalatest.matchers.ShouldMatchers._
scala> val a = 1
a: Int = 1
scala> val b = 2
b: Int = 2
scala> a should equal (b)
org.scalatest.TestFailedException: 1 did not equal 2
at org.scalatest.matchers.Matchers$class.newTestFailedException(Matchers.scala:148)
at org.scalatest.matchers.ShouldMatchers$.newTestFailedException(ShouldMatchers.scala:2318)
at org.scalatest.matchers.ShouldMatchers$ShouldMethodHelper$.shouldMatcher(ShouldMatchers.scala:871)
at org.scalatest.matchers.ShouldMatchers$IntShouldWra...
For example here is said "1 did not equal 2".
Bill