Mocking Screw-Unit Part Deux
I wrote earlier about how Topper mocked out the dom for screw-unit testing. Taking his lead, I started playing with screw-unit and adding some mocking and stubbing in the rspec way. It’s not quite release worthy, but it’s on github now and I think it’s nearly usable. Basically, it lets you do things like this:
user = {login: 'bob'};
Screw.Stub.stub(user, 'login').andReturn('nancy');
user.login; // => 'nancy'
Screw.Stub.reset(); // Called automatically after each spec
user.login; // => 'bob'
// Will throw a spec failure if user.email() is never called.
Screw.stub.shouldReceive(user, 'email');
Obviously shouldReceive is not quite complete. It’s missing with(), numberOfTimes(), and other things. Still, it’s good enough that others can start iterating on the model I’ve laid down. As I said earlier, my fork of screw-unit is available on github now, so have a look and feel free to leave questions in the comments.
Comments
-
I think if you followed this convention: Screw.Stub = function (actual, args) { //do stuff }; Object.extend(Screw.Stub, { //your release() and other methods }); You could get a little better syntax: Screw.Stub(user, 'email'); Screw.Stub.release();