我有以下功能,我想测试:
def people(id: Int): RIO[R, People]
如果有一个人,则此函数返回 People id
,resp。如果没有,则失败,例如:
IO.fail(ServiceException(s"No People with id $id"))
快乐的案例有效,例如:
suite("Get a Person for an ID") (
testM("get Luke Skywalker") {
for {
peopleRef <- Ref.make(Vector(People()))
luke <- Swapi.>.people(1).provide(Test(peopleRef))
} yield assert(luke, equalTo(People()))
},
但是我怎样才能测试失败案例呢?我尝试了不同的东西,主要是类型不匹配。这是一个尝试:
testM("get not existing People") {
(for {
peopleRef <- Ref.make(Vector(People()))
failure = Swapi.>.people(2).provide(Test(peopleRef))
} yield assertM(failure, fail(Cause.die(ServiceException(s"No People with id 2")))
}
)