Hi Benjamin,

> var mockEnv = 
> this.mock(qx.core.Environment).expects("get").withArgs("username").returns("usernmae");
> 
> Do i use sinon correctly??

You correctly tell Sinon to mock qx.core.Environment. But it is questionable if 
a mock is really what you want here.

To quote from the documentation:

„Mocks (and mock expectations) are fake methods (like spies) with 
pre-programmed behavior (like stubs) as well as pre-programmed expectations. A 
mock will fail your test if it is not used as expected.“

In the case of qx.core.Environment, you mock an object  which is used 
extensively throughout frameworks code base and probably your application too. 
You express the expectation that every call of get() receives "username" as 
first argument. However, get() is used in contexts outside the scope of your 
test, with differing arguments. Every call not meeting the expectation you 
specified will fail. 

To illustrate, here is a sample test.

"test: mock unexpected use throws": function() {
  var obj = {method: function() {}};
  var mock = this.sinon.mock(obj);
  mock.expects("method").never();

  this.assertException(function() {
    obj.method();
  }, Error, /ExpectationError/);
}

Note that obj.method() throws an expectation error, because the pre-programmed 
expectation of the mock is that method should never be called.

I suppose the expectation error thrown on "other calls" is causing the test 
runner to hang. The test runners tear down for instance reads 
"qx.debug.dispose" from the environment.

In short, using a stub seems the way to go. Also, make sure to limit the 
behavioral change to calls with expected arguments, like this:

this.stub(qx.core.Environment, "get").withArgs("username").returns("username")

Regards
Tristan




------------------------------------------------------------------------------
RSA(R) Conference 2012
Save $700 by Nov 18
Register now
http://p.sf.net/sfu/rsa-sfdev2dev1
_______________________________________________
qooxdoo-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel

Reply via email to