Skip to content

Instantly share code, notes, and snippets.

@tobie
Forked from DavidBruant/original.js
Last active December 12, 2015 04:19
Show Gist options
  • Save tobie/4713821 to your computer and use it in GitHub Desktop.
Save tobie/4713821 to your computer and use it in GitHub Desktop.

Revisions

  1. tobie revised this gist Feb 5, 2013. 1 changed file with 1 addition and 3 deletions.
    4 changes: 1 addition & 3 deletions withPromise.js
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,5 @@
    function load(fixtures) {
    return Q.all(fixtures.map(function(fixture) {
    return store(fixture); // assumes the store function returns a promise for success
    });
    return Q.all(fixtures.map(store));
    }

    describe("moods tests", function() {
  2. @DavidBruant DavidBruant revised this gist Feb 5, 2013. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions withPromise.js
    Original file line number Diff line number Diff line change
    @@ -12,8 +12,8 @@ describe("moods tests", function() {
    , "2013-02-04:n1k0:rainy"
    // … we could add many more
    ];

    it ("should do something useful with moods", function(done) {
    load(moods).done(done);
    // a promise-freindly test framework would expect promises to be returned
    it ("should do something useful with moods", function() {
    return load(moods);
    });
    });
  3. @DavidBruant DavidBruant revised this gist Feb 5, 2013. 2 changed files with 2 additions and 5 deletions.
    4 changes: 1 addition & 3 deletions original.js
    Original file line number Diff line number Diff line change
    @@ -19,9 +19,7 @@ describe("moods tests", function() {

    it ("should do something useful with moods", function(done) {
    load(moods, function(err, storedMoods) {
    assert.ifError(err);
    // now let's test stuff with stored moods
    done();
    done(err || undefined); // to make a fair comparison
    });
    });
    });
    3 changes: 1 addition & 2 deletions withPromise.js
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,6 @@
    function load(fixtures) {
    return Q.all(fixtures.map(function(fixture) {
    // assumes the store function returns a promise for success
    return store(fixture)
    return store(fixture); // assumes the store function returns a promise for success
    });
    }

  4. @DavidBruant DavidBruant revised this gist Feb 5, 2013. No changes.
  5. @DavidBruant DavidBruant revised this gist Feb 5, 2013. 2 changed files with 27 additions and 0 deletions.
    27 changes: 27 additions & 0 deletions original.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    function load(fixtures, onComplete) {
    async.parallel(fixtures.map(function(fixture) {
    return function(cb) {
    store(fixture, function(err, result) {
    cb(err, result);
    });
    };
    }), onComplete);
    }

    describe("moods tests", function() {
    var moods = [
    "2013-02-01:n1k0:sunny"
    , "2013-02-02:n1k0:cloudy"
    , "2013-02-03:n1k0:stormy"
    , "2013-02-04:n1k0:rainy"
    // … we could add many more
    ];

    it ("should do something useful with moods", function(done) {
    load(moods, function(err, storedMoods) {
    assert.ifError(err);
    // now let's test stuff with stored moods
    done();
    });
    });
    });
    File renamed without changes.
  6. @DavidBruant DavidBruant created this gist Feb 5, 2013.
    20 changes: 20 additions & 0 deletions gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    function load(fixtures) {
    return Q.all(fixtures.map(function(fixture) {
    // assumes the store function returns a promise for success
    return store(fixture)
    });
    }

    describe("moods tests", function() {
    var moods = [
    "2013-02-01:n1k0:sunny"
    , "2013-02-02:n1k0:cloudy"
    , "2013-02-03:n1k0:stormy"
    , "2013-02-04:n1k0:rainy"
    // … we could add many more
    ];

    it ("should do something useful with moods", function(done) {
    load(moods).done(done);
    });
    });