Unexpected behavior of FuturesConcept.futureValue() in combination with thrownBy-matcher [2.2.5]

52 views
Skip to first unread message

Niklas Lochschmidt

unread,
Sep 25, 2015, 12:44:36 PM9/25/15
to scalatest-users
Hi

Starting from the documentation of FutureConcept.futureValue():

def futureValue(implicit config: Futures.PatienceConfig): T 
Returns the result of this FutureConcept, once it is ready, or throws either the exception returned by the future (i.e., futureValue returned a Left) or TestFailedException.

I wrote some test code along the lines of this

class TestException() extends RuntimeException("Expected in test")

object ExampleCode {
 
def execute()(implicit ec: ExecutionContext): Future[String] = {
   
Future { throw new TestException() }
 
}
}

when I assert against the TestException I got a TestFailedException instead
a[TestException] should be thrownBy(ExampleCode.execute().futureValue)
-> Expected exception TestException to be thrown, but org.scalatest.exceptions.TestFailedException was thrown. (ExampleTest.scala:10)

and actually when I check the result of ExampleCode.execute().futureValue I get
The future returned an exception of type: TestException, with message: Expected in test. (ExampleTest.scala:13)

My expectation is that I can match on the TestException, am I wrong?
Full code is here https://gist.github.com/04158ab2b087dab7288c

Thanks
Niklas
Reply all
Reply to author
Forward
0 new messages