0

Is this the most idiomatic way to test a failing effect?

  def spec = suite("LookupPositionProviderSpec")(
    suite("determinePosition")(
      test("Unknown hints lead to 'NoPositionDetermined'") {
        for exit <- LookupPositionProvider.determinePosition(Seq(GsmFixtures.cellHintTowerGsm1.copy(cid = 4711))).exit
        yield assert(exit)(
          fails(
            equalTo(
              ProviderError(
                Lookup,
                NoPositionDetermined,
                Some("No position could be determined from List(CellHint(GSM,4711,Some(5891),Some(-70),None,None,None))")
              )
            )
          )
        )
      }.provide(TestLayers.findsNothingLookupPositionProvider)
    )
  ) 

I saw this old question (How to test an exception case with zio-test), but I am unsure if and what has changed since then with ZIO 2.

Chris W.
  • 2,266
  • 20
  • 40

1 Answers1

0

Adam answered this on Discord (https://discord.com/channels/629491597070827530/630498701860929559?fingerprint=1007186113041006615&attemptId=31b120fc-90de-4937-af0b-46db03424f24):

"Yes the exit and then assert(exit)(fails(???)) definitely is. If you want to assert that it has that exact failure that looks great. If you just want to assert that it fails and don't care more about the failure you could do fails(anything) or you could use any other assertion there."

Chris W.
  • 2,266
  • 20
  • 40