Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

Adding catchSome breaks the test. #67

Open
jaroslawZawila opened this issue Oct 11, 2024 · 0 comments
Open

Adding catchSome breaks the test. #67

jaroslawZawila opened this issue Oct 11, 2024 · 0 comments

Comments

@jaroslawZawila
Copy link

jaroslawZawila commented Oct 11, 2024

I have a code which I am trying to test which is like above:

private case class ProducerImpl(client: Client) extends Producer {
    def produce(): ZIO[Any, Throwable, Unit] = (for {
      _ <- client.send("Hello")
    } yield ()
    )
    .catchSome {
      case e if e.getMessage().startsWith("Hey") => ZIO.unit
    }
  }

I mock the client:

object MockClient extends Mock[Client] {
  object SendEffect extends Effect[String, Throwable, Unit]

  override val compose: URLayer[mock.Proxy, Client] = ZLayer {
    ZIO.serviceWithZIO[mock.Proxy] { proxy =>
      ZIO.succeed {
        new Client {
          override def send(s: String): ZIO[Any, Throwable, Unit] =
            proxy(SendEffect, s)
        }
      }
    }
  }
}

And then test:

object ProducerSpec extends ZIOSpecDefault {
  def spec = suite("Test")(
    test("1") {
      val program = for {
        producer <- ZIO.service[Producer]
        result <- producer.produce()
      } yield result

      val exp = MockClient.SendEffect(Assertion.anything, Expectation.unit)

      val layer = exp.toLayer >>> ProducerF.live
      val effect = program.provideLayer(layer)

      assertZIO(effect.either)(isRight(equalTo(())))
    }
  )
}

if I remove from the code

 .catchSome {
      case e if e.getMessage().startsWith("Hey") => ZIO.unit
    }

Everything works fine with the catchSome it does not.

Please find working example here: https://scastie.scala-lang.org/UcqqRAYyQVqjbWsggdVXYA

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant