Problem with ScalaMock mockFunction

188 views
Skip to first unread message

Evan Chan

unread,
Apr 12, 2012, 5:01:20 PM4/12/12
to scalate...@googlegroups.com
[Not sure if my earlier post went through, sorry if this ends up double posting....]

Hi there,

I'm trying to use ScalaMock mockFunction, but it's not quite working.  I have code like the following:

import org.scalamock._
import scalatest.MockFactory

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

  val client = new Client(List(BadHost, "host2")) {
    override protected def getXmlFromRoute(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 test code that exercises getXmlFromRoute() above...
    }
  }
 
 
 
When I run this test, I get the following error:

[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) 
 
..

help?

thanks.

Paul Butcher

unread,
Apr 28, 2012, 11:20:00 AM4/28/12
to scalate...@googlegroups.com
Evan,

Many apologies for the delayed reply - I don't check this group as often as I should :-(

I'm not sure that I can tell why your test isn't working from the code you've pasted. You might try mixing in the CallLogging and/or VerboseErrors traits into your tests, which should hopefully print enough information for you to be able to work out what's up. One possibility - you've not specified how many times you expect your mock function to be called, which means that by default it only expects to be called once. Might your test be calling it more than once?

If you're still stuck, if you can create a small example that reproduces the problem, I'd be very happy to take a look. (Although I should warn you that I'm currently in South Africa with very intermittent connectivity, so I may not be as responsive as I'd hope).

--
paul.butcher->msgCount++

Snetterton, Castle Combe, Cadwell Park...
Who says I have a one track mind?

http://www.paulbutcher.com/
LinkedIn: http://www.linkedin.com/in/paulbutcher
MSN: pa...@paulbutcher.com
AIM: paulrabutcher
Skype: paulrabutcher

--
You received this message because you are subscribed to the Google
Groups "scalatest-users" group.
To post to this group, send email to scalate...@googlegroups.com
To unsubscribe from this group, send email to
scalatest-use...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/scalatest-users?hl=en
ScalaTest itself, and documentation, is available here:
http://www.artima.com/scalatest

Reply all
Reply to author
Forward
0 new messages