StubbedIOMethod

org.scalamock.stubs.StubbedIOMethod
class StubbedIOMethod[A, R](delegate: StubbedMethod[A, R]) extends StubbedMethod[A, R]

Representation of stubbed method

CatsEffectStubs interface provides implicit conversion from selected method to StubbedMethodIO.

 trait Foo:
   def foo0: IO[String]
   def foo(x: Int): IO[String]
   def bar(x: Int, y: String): IO[Int]

 val foo = stub[Foo]

Scala 3

 val foo0Stubbed: StubbedMethod[Unit, IO[String]] = foo.foo0
 val fooStubbed: StubbedMethod[Int, IO[String]] = foo.foo
 val barStubbed: StubbedMethod[(Int, String), IO[Int]] = foo.bar

Scala 2

 val foo0Stubbed: StubbedMethod[Unit, IO[String]] = foo.foo0
 val fooStubbed: StubbedMethod[Int, IO[String]] = foo.foo _
 val barStubbed: StubbedMethod[(Int, String), IO[Int]] = foo.bar _

Attributes

Graph
Supertypes
trait StubbedMethod[A, R]
class Object
trait Matchable
class Any

Members list

Value members

Concrete methods

def asString: String

Returns string representation of method. Representation currently depends on scala version.

Returns string representation of method. Representation currently depends on scala version.

Attributes

def calls: List[A]

Allows to get arguments with which method was executed. Returns multiple arguments as tuple. One list item per call.

Allows to get arguments with which method was executed. Returns multiple arguments as tuple. One list item per call.

Scala 3

 for
   _ <- foo.foo.returnsIO(x => IO(5))
   _ <- foo.foo(1)
   _ <- foo.foo(100)
 yield foo.foo.calls == List(1, 100) // true

Scala 2

 for {
   _ <- (foo.foo _).returnsIO(x => IO(5))
   _ <- foo.foo(1)
   _ <- foo.foo(100)
 } yield (foo.foo _).calls == List(1, 100) // true

Attributes

def callsIO: IO[List[A]]

Allows to get arguments with which method was executed. Returns IO

Allows to get arguments with which method was executed. Returns IO

Returns multiple arguments as tuple. One list item per call.

Scala 3

 for {
   _ <- foo.bar.returnsIO(_ => IO(5))
   _ <- foo.bar(1, "foo")
   _ <- foo.bar(2, "bar")
   calls <- foo.bar.callsIO
 } yield calls == List((1, "foo"), (2, "bar")) // true

Scala 2

 for {
   _ <- (foo.bar _).returnsIO(_ => IO(5))
   _ <- foo.bar(1, "foo")
   _ <- foo.bar(2, "bar")
   calls <- (foo.bar _).callsIO
 } yield calls == List((1, "foo"), (2, "bar")) // true

Attributes

def isAfter(other: StubbedMethod[_, _])(implicit callLog: CallLog): Boolean

Returns true if this method was called after other method.

Returns true if this method was called after other method.

Attributes

def isBefore(other: StubbedMethod[_, _])(implicit callLog: CallLog): Boolean

Returns true if this method was called before other method.

Returns true if this method was called before other method.

Attributes

def raisesErrorWith(ex: => Throwable)(implicit ev: IO[Nothing] <:< R): IO[Unit]

Allows raise error for method without arguments. Returns IO.

Allows raise error for method without arguments. Returns IO.

  for {
    _ <- foo.fooIO.failsWith(1)
  } yield ()

Attributes

def returns(f: A => R): Unit

Allows to set result for method with arguments.

Allows to set result for method with arguments.

Scala 3

 foo.bar.returns((x, y) => IO(1))

Scala 2

 (foo.bar _).returns((x, y) => IO(1))

Attributes

def returnsIO(f: A => R): IO[Unit]

Allows to set result for method with arguments. Returns IO

Allows to set result for method with arguments. Returns IO

Scala 3

 for
   _ <- foo.bar.returnsIO((x, y) => IO(1))
 yield ()

Scala 2

 for {
   _ <- (foo.bar _).returnsIO((x, y) => IO(1))
 } yield ()

Attributes

def returnsIOOnCall(f: Int => R): IO[Unit]

Allows to set result depending on call number starting from 1. Returns IO

Allows to set result depending on call number starting from 1. Returns IO

Scala 3

 for
   _ <- foo.bar.returnsIOOnCall:
     case 1 | 2 => IO(0)
     case _ => IO(1)
 yield ()

Scala 2

 for {
   _ <- foo.bar.returnsIOOnCall {
     case 1 | 2 => IO(0)
     case _ => IO(1)
   }
 } yield ()

Attributes

def returnsIOWith(value: => R): IO[Unit]

Allows to set result for method with arguments. Returns IO

Allows to set result for method with arguments. Returns IO

Scala 3

 for
   _ <- foo.bar.returnsIOWith(IO(1))
 yield ()

Scala 2

 for {
   _ <- (foo.bar _).returnsIOWith(IO(1))
 } yield ()

Attributes

def returnsOnCall(f: Int => R): Unit

Allows to set result depending on call number starting from 1

Allows to set result depending on call number starting from 1

Scala 3

 foo.bar.returnsOnCall:
   case 1 | 2 => IO(0)
   case _ => IO(1)
  • Scala 2
 (foo.bar _).returnsOnCall {
   case 1 | 2 => IO(0)
   case _ => IO(1)
 }

Attributes

def returnsWith(f: => R): Unit

Allows to set result for method with arguments.

Allows to set result for method with arguments.

Scala 3

 foo.bar.returnsWith(IO(1))

Scala 2

 (foo.bar _).returnsWith(IO(1))

Attributes

def succeedsWith[RR](value: => RR)(implicit ev: IO[RR] <:< R): IO[Unit]

Allows to set success for method with arguments. Returns IO.

Allows to set success for method with arguments. Returns IO.

Scala 3

 for
   _ <- foo.bar.succeedsWith(1)
 yield ()

Scala 2

 for {
   _ <- (foo.bar _).succeedsWith(1)
 } yield ()

Attributes

def times: Int

Allows to get number of times method was executed.

Allows to get number of times method was executed.

Scala 3

 for
   _ <- foo.foo.returnsIO(x => IO(5))
   _ <- foo.foo(1)
   _ <- foo.foo(100)
 yield foo.foo.times == 2 // true

Scala 2

 for {
   _ <- (foo.foo _).returnsIO(x => IO(5))
   _ <- foo.foo(1)
   _ <- foo.foo(100)
 } yield (foo.foo _).times == 2 // true

Attributes

def timesIO: IO[Int]

Allows to get number of times method was executed with specific arguments. Returns IO

Allows to get number of times method was executed with specific arguments. Returns IO

Scala 3

  for
    _ <- foo.bar.returnsIO(_ => IO(1))
    _ <- foo.bar(1, "foo")
    _ <- foo.bar(2, "bar")
    barTimes <- foo.bar.timesIO
  yield barTimes == 2 // true

Scala 2

  for {
    _ <- (foo.bar _).returnsIO(_ => IO(1))
    _ <- foo.bar(1, "foo")
    _ <- foo.bar(2, "bar")
    barTimes <- (foo.bar _).timesIO
  } yield barTimes == 2 // true

Attributes

def timesIO(args: A): IO[Int]

Allows to get number of times method was executed with specific arguments. Returns IO

Allows to get number of times method was executed with specific arguments. Returns IO

Scala 3

  for
    _ <- foo.bar.returnsIO(_ => IO(1))
    _ <- foo.bar(1, "foo")
    _ <- foo.bar(2, "bar")
    barTimes <- foo.bar.timesIO((1, "foo"))
  yield barTimes == 1 // true

Scala 2

  for {
    _ <- (foo.bar _).returnsIO(_ => IO(1))
    _ <- foo.bar(1, "foo")
    _ <- foo.bar(2, "bar")
    barTimes <- (foo.bar _).timesIO((1, "foo"))
  } yield barTimes == 1 // true

Attributes

override def toString: String

Returns a string representation of the object.

Returns a string representation of the object.

The default representation is platform dependent.

Attributes

Returns

a string representation of the object.

Definition Classes
Any

Inherited methods

final def times(args: A): Int

Allows to get number of times method was executed with specific arguments.

Allows to get number of times method was executed with specific arguments.

Scala 3

 foo.foo.returns(_ => 5)
 foo.foo(1)

 foo.foo.times(1) // 1
 foo.foo.times(100) // 0

Scala 2

  (foo.foo _).returns(_ => 5)
  foo.foo(1)

 (foo.foo _).times(1) // 1
 (foo.foo _).times(100) // 0

Attributes

Inherited from:
StubbedMethod