ScalaMock mockFunction not working for me

45 views
Skip to first unread message

Evan Chan

unread,
Apr 12, 2012, 4:55:18 PM4/12/12
to scalate...@googlegroups.com
I have code like the following:

import org.scalamock._
import scalatest.MockFactory

class SomeScalaTest extends FunSpec with MockFactory {
  val mockGetXml = mockFunction[String, String, xml.NodeSeq]

  val classUnderTest = new SomeClass(..) { override def getXml(host: String, route: String) = mockGetXml(host, route) }

  describe("checkConnection") {
    it("should return true if schema route returns data, false for bad hosts") {
      mockGetXml.expects(BadHost, client.BaseUrl + "schema").throws(
          new java.net.UnknownHostException(""))
      mockGetXml.expects("host2", client.BaseUrl + 'schema).returns(<node></node>)
                ...
                // Some code that exercises classUnderTest.getXml()
              }
           }
 
When I run the test above, I get errors like these:

[info] - should return true if schema route returns data, false for bad hosts *** FAILED ***
[info]   org.scalamock.ExpectationException: Unexpected: unnamed MockFunction2 with arguments: (host2, gds/v1/ipinfo/schema)
[info]   at org.scalamock.MockFactoryBase$class.handleUnexpectedCall(MockFactoryBase.scala:129)
[

Any ideas?

thanks,
Evan

 
Reply all
Reply to author
Forward
0 new messages