jackfranklin/pulldown — pull request #48 by jackfranklin (2013-08-09 23:10:41+00:00)
Title: Fixing the tests

This is how I think we test it

- mock API requests with [nock](https://github.com/flatiron/nock):

```
var api = nock("http://pulldown-api.herokuapp.com/")
.get("/set/jquery")
.reply(200, [ "//cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.min.js" ]);
```

- mock `getFile` so it first calls the spy with the args, and then immediately returns the callback (when we come to write tests for zips, we might have to do something differently, but else this should be fine)

```js
Pulldown.prototype.getFile = function(url, out, doneGetFile) {
spy.apply(this, Array.prototype.slice.call(arguments));
return doneGetFile(null, { url: url, fileDestination: out });
};
```

- assert that nock's mock URL was called:

```js
assert(api.isDone(), "the API was hit with /set/jquery");
```

- assert the spy was called with the right args:

```js
assert(spy.calledWith("https://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.min.js", undefined), "getFile was called with the expected arguments");
```

I also think we should always add a descriptor to `assert`, so if one fails it's easy to see.

These changes mean our tests are no longer network dependent, which is the source of 99.999% of our current problems.

@phuu what do you think? If you're happy with it I'll continue writing new ones.