Search code examples
scalascalatestinfix-notation

Scalatest call be without parenthesis


Why does the following code fails:

session.getGameId should be 10 

with this error

';' expected but integer literal found.

However this one doesn't fail

session.getGameId should be(10)

Does it have to do with the way that the apply method is called


Solution

  • session.getGameId should be 10
    

    means

    (session.getGameId).should(be).(10)
    

    whereas

    session.getGameId should be(10)
    

    means

    (session.getGameId).should(be(10))
    

    Obviously, the first one can't compile since it is not valid to call an integer literal in this position. See this question for further explanation when you can leave out parentheses and dots in Scala.