-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added new rapid-test project to provide ScalaTest support for async s…
…pecs
- Loading branch information
1 parent
84ce4fa
commit b579984
Showing
4 changed files
with
82 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package rapid | ||
|
||
import scala.concurrent.Future | ||
|
||
import scala.language.implicitConversions | ||
|
||
trait AsyncTaskSpec { | ||
implicit def task2Future[Return](task: Task[Return]) | ||
(implicit ec: scala.concurrent.ExecutionContext): Future[Return] = task.toFuture | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package spec | ||
|
||
import org.scalatest.matchers.should.Matchers | ||
import org.scalatest.wordspec.{AnyWordSpec, AsyncWordSpec} | ||
import rapid._ | ||
|
||
class BasicsAsyncSpec extends AsyncWordSpec with AsyncTaskSpec with Matchers { | ||
"Basics sync" should { | ||
"handle a simple task" in { | ||
val i = Task { | ||
5 * 5 | ||
} | ||
i.map { n => | ||
n should be(25) | ||
} | ||
} | ||
"handle a simple task mapping" in { | ||
val i = Task { | ||
5 * 5 | ||
} | ||
val s = i.map { v => | ||
s"Value: $v" | ||
} | ||
s.map { s => | ||
s should be("Value: 25") | ||
} | ||
} | ||
"handle flat mapping" in { | ||
val task = (1 to 10).foldLeft(Task(0))((t, i) => t.flatMap { total => | ||
Task(total + i) | ||
}) | ||
task.map { result => | ||
result should be(55) | ||
} | ||
} | ||
"throw an error and recover" in { | ||
val result = Task[String](throw new RuntimeException("Die Die Die")) | ||
.handleError { _ => | ||
Task.pure("Recovered") | ||
} | ||
result map { s => | ||
s should be("Recovered") | ||
} | ||
} | ||
"process a list of tasks to a task with a list" in { | ||
val list = List( | ||
Task("One"), Task("Two"), Task("Three") | ||
) | ||
list.tasks.map { list => | ||
list should be(List("One", "Two", "Three")) | ||
} | ||
} | ||
} | ||
} |