Permalink
Browse files

updating tests with more logging and consistent, cleaner works

  • Loading branch information...
mckelvey committed Apr 30, 2011
1 parent c68460f commit 29316b9b7cdce3d9a6665be5c75bd497df31104c
View
@@ -1,16 +1,25 @@
-module.exports = (title = '', Instagram, type, method, params = {}, assertions) ->
- indent = " "
- params['complete'] = (data, pagination) ->
- console.log "\n#{title}\n#{indent}connection/parsing succeeded"
- try
- assertions data, pagination
- console.log "#{indent}data met assertions"
- catch e
- console.log "#{indent}data failed to meet the assertion(s): #{e}"
+indent = " "
+
+module.exports =
+ indent: indent
+ helper: (title = '', Instagram, type, method, params = {}, assertions) ->
+ params['complete'] = (data, pagination) ->
+ console.log "\n#{title}\n#{indent}connection/parsing succeeded"
+ try
+ assertions data, pagination
+ console.log "#{indent}data met assertions"
+ catch e
+ console.log "#{indent}data failed to meet the assertion(s): #{e}"
+ throw e
+ params['error'] = (e, data, caller) ->
+ console.log "#{indent}error: #{e}\n#{indent}data: #{data}\n#{indent}caller: #{caller}"
throw e
- params['error'] = (e, data, caller) ->
- console.log "\n#{title}\n#{indent}connection/parsing failed"
- console.log "#{indent}error: #{e}\n#{indent}data: #{data}\n#{indent}caller: #{caller}"
- throw e
- Instagram[type][method] params
+ Instagram[type][method] params
+ output: (message, value = null) ->
+ console.log "#{indent}#{message}"
+ if value?
+ if typeof value is 'object'
+ console.log "#{indent}#{indent}it was: " + JSON.stringify(value)
+ else
+ console.log "#{indent}#{indent}it was: #{value}"
View
@@ -1,28 +1,43 @@
(function() {
- module.exports = function(title, Instagram, type, method, params, assertions) {
- var indent;
- if (title == null) {
- title = '';
- }
- if (params == null) {
- params = {};
- }
- indent = " ";
- params['complete'] = function(data, pagination) {
- console.log("\n" + title + "\n" + indent + "connection/parsing succeeded");
- try {
- assertions(data, pagination);
- return console.log("" + indent + "data met assertions");
- } catch (e) {
- console.log("" + indent + "data failed to meet the assertion(s): " + e);
+ var indent;
+ indent = " ";
+ module.exports = {
+ indent: indent,
+ helper: function(title, Instagram, type, method, params, assertions) {
+ if (title == null) {
+ title = '';
+ }
+ if (params == null) {
+ params = {};
+ }
+ params['complete'] = function(data, pagination) {
+ console.log("\n" + title + "\n" + indent + "connection/parsing succeeded");
+ try {
+ assertions(data, pagination);
+ return console.log("" + indent + "data met assertions");
+ } catch (e) {
+ console.log("" + indent + "data failed to meet the assertion(s): " + e);
+ throw e;
+ }
+ };
+ params['error'] = function(e, data, caller) {
+ console.log("" + indent + "error: " + e + "\n" + indent + "data: " + data + "\n" + indent + "caller: " + caller);
throw e;
+ };
+ return Instagram[type][method](params);
+ },
+ output: function(message, value) {
+ if (value == null) {
+ value = null;
+ }
+ console.log("" + indent + message);
+ if (value != null) {
+ if (typeof value === 'object') {
+ return console.log(("" + indent + indent + "it was: ") + JSON.stringify(value));
+ } else {
+ return console.log("" + indent + indent + "it was: " + value);
+ }
}
- };
- params['error'] = function(e, data, caller) {
- console.log("\n" + title + "\n" + indent + "connection/parsing failed");
- console.log("" + indent + "error: " + e + "\n" + indent + "data: " + data + "\n" + indent + "caller: " + caller);
- throw e;
- };
- return Instagram[type][method](params);
+ }
};
}).call(this);
@@ -8,22 +8,32 @@ console.log "\nInstagram API Node.js Lib Tests :: Locations"
Instagram = require '../lib/class.instagram'
assert = require 'assert'
should = require 'should'
-test_helper = require './helpers.js'
+test = require './helpers.js'
module.exports =
'locations#info for id#1': ->
- test_helper 'locations#info for id#1', Instagram, 'locations', 'info', { location_id: 1 }, (data) ->
+ test.helper 'locations#info for id#1', Instagram, 'locations', 'info', { location_id: 1 }, (data) ->
data.should.have.property 'name', 'Dogpatch Labs'
+ test.output "data had the property 'name' equal to 'Dogpatch Labs'"
data.latitude.should.be.above 0
+ test.output "data had the property 'latitude' greater than zero", data.latitude
data.longitude.should.be.below 0
+ test.output "data had the property 'longitude' less than zero", data.longitude
'locations#recent for id#1': ->
- test_helper 'locations#recent for id#1', Instagram, 'locations', 'recent', { location_id: 1 }, (data, pagination) ->
+ test.helper 'locations#recent for id#1', Instagram, 'locations', 'recent', { location_id: 1 }, (data, pagination) ->
data.length.should.be.above 0
+ test.output "data had length greater than 0", data.length
data[0].should.have.property 'id'
+ test.output "data[0] had the property 'id'", data[0].id
pagination.should.have.property 'next_url'
+ test.output "pagination had the property 'next_url'", pagination.next_url
pagination.should.have.property 'next_max_id' or pagination.should.have.property 'next_min_id'
+ test.output "pagination had the property 'next_max_id' or 'next_min_id'", pagination
'locations#search for 48.858844300000001/2.2943506': ->
- test_helper 'locations#search for 48.858844300000001/2.2943506', Instagram, 'locations', 'search', { lat: 48.858844300000001, lng: 2.2943506 }, (data) ->
+ test.helper 'locations#search for 48.858844300000001/2.2943506', Instagram, 'locations', 'search', { lat: 48.858844300000001, lng: 2.2943506 }, (data) ->
data.length.should.be.above 0
+ test.output "data had length greater than 0", data.length
data[0].should.have.property 'id'
+ test.output "data[0] had the property 'id'", data[0].id
data[0].should.have.property 'name'
+ test.output "data[0] had the property 'name'", data[0].name
@@ -1,40 +1,50 @@
(function() {
/*
Testing Location Methods
- */ var Instagram, assert, should, test_helper;
+ */ var Instagram, assert, should, test;
console.log("\nInstagram API Node.js Lib Tests :: Locations");
Instagram = require('../lib/class.instagram');
assert = require('assert');
should = require('should');
- test_helper = require('./helpers.js');
+ test = require('./helpers.js');
module.exports = {
'locations#info for id#1': function() {
- return test_helper('locations#info for id#1', Instagram, 'locations', 'info', {
+ return test.helper('locations#info for id#1', Instagram, 'locations', 'info', {
location_id: 1
}, function(data) {
data.should.have.property('name', 'Dogpatch Labs');
+ test.output("data had the property 'name' equal to 'Dogpatch Labs'");
data.latitude.should.be.above(0);
- return data.longitude.should.be.below(0);
+ test.output("data had the property 'latitude' greater than zero", data.latitude);
+ data.longitude.should.be.below(0);
+ return test.output("data had the property 'longitude' less than zero", data.longitude);
});
},
'locations#recent for id#1': function() {
- return test_helper('locations#recent for id#1', Instagram, 'locations', 'recent', {
+ return test.helper('locations#recent for id#1', Instagram, 'locations', 'recent', {
location_id: 1
}, function(data, pagination) {
data.length.should.be.above(0);
+ test.output("data had length greater than 0", data.length);
data[0].should.have.property('id');
+ test.output("data[0] had the property 'id'", data[0].id);
pagination.should.have.property('next_url');
- return pagination.should.have.property('next_max_id' || pagination.should.have.property('next_min_id'));
+ test.output("pagination had the property 'next_url'", pagination.next_url);
+ pagination.should.have.property('next_max_id' || pagination.should.have.property('next_min_id'));
+ return test.output("pagination had the property 'next_max_id' or 'next_min_id'", pagination);
});
},
'locations#search for 48.858844300000001/2.2943506': function() {
- return test_helper('locations#search for 48.858844300000001/2.2943506', Instagram, 'locations', 'search', {
+ return test.helper('locations#search for 48.858844300000001/2.2943506', Instagram, 'locations', 'search', {
lat: 48.858844300000001,
lng: 2.2943506
}, function(data) {
data.length.should.be.above(0);
+ test.output("data had length greater than 0", data.length);
data[0].should.have.property('id');
- return data[0].should.have.property('name');
+ test.output("data[0] had the property 'id'", data[0].id);
+ data[0].should.have.property('name');
+ return test.output("data[0] had the property 'name'", data[0].name);
});
}
};
@@ -8,40 +8,52 @@ console.log "\nInstagram API Node.js Lib Tests :: Media"
Instagram = require '../lib/class.instagram'
assert = require 'assert'
should = require 'should'
-test_helper = require './helpers.js'
+test = require './helpers.js'
module.exports =
'media#popular': ->
- test_helper 'media#popular', Instagram, 'media', 'popular', {}, (data) ->
+ test.helper 'media#popular', Instagram, 'media', 'popular', {}, (data) ->
data.length.should.equal 32
+ test.output "data had length equal to 32"
data[0].should.have.property 'id'
+ test.output "data[0] had the property 'id'", data[0].id
'media#info for id#3': ->
- test_helper 'media#info for id#3', Instagram, 'media', 'info', { media_id: 3 }, (data) ->
+ test.helper 'media#info for id#3', Instagram, 'media', 'info', { media_id: 3 }, (data) ->
data.should.have.property 'id', '3'
+ test.output "data had the property 'id' equal to 3"
data.should.have.property 'created_time', '1279315783'
+ test.output "data had the property 'created_time' equal to 1279315783"
'media#search for 48.858844300000001/2.2943506': ->
- test_helper 'media#search for 48.858844300000001/2.2943506', Instagram, 'media', 'search', { lat: 48.858844300000001, lng: 2.2943506 }, (data) ->
+ test.helper 'media#search for 48.858844300000001/2.2943506', Instagram, 'media', 'search', { lat: 48.858844300000001, lng: 2.2943506 }, (data) ->
data.length.should.be.above 0
+ test.output "data had length greater than 0", data.length
data[0].should.have.property 'id'
+ test.output "data[0] had the property 'id'", data[0].id
'media#like id#3': ->
- test_helper 'media#like id#3', Instagram, 'media', 'like', { media_id: 3 }, (data) ->
+ test.helper 'media#like id#3', Instagram, 'media', 'like', { media_id: 3 }, (data) ->
throw "like failed" if data isnt null
- console.log " liked media #3"
- test_helper 'media#likes for id#3', Instagram, 'media', 'likes', { media_id: 3 }, (data) ->
+ test.output "data was null; we liked media #3"
+ test.helper 'media#likes for id#3', Instagram, 'media', 'likes', { media_id: 3 }, (data) ->
data.length.should.be.above 0
- test_helper 'media#unlike id#3', Instagram, 'media', 'unlike', { media_id: 3 }, (data) ->
+ test.output "data had length greater than 0", data.length
+ test.helper 'media#unlike id#3', Instagram, 'media', 'unlike', { media_id: 3 }, (data) ->
throw "unlike failed" if data isnt null
- console.log " unliked media #3"
+ test.output "data was null; we unliked media #3"
'media#comment id#53355234': ->
- test_helper 'media#comment id#53355234', Instagram, 'media', 'comment', { media_id: 53355234, text: 'Instagame was here.' }, (data) ->
+ test.helper 'media#comment id#53355234', Instagram, 'media', 'comment', { media_id: 53355234, text: 'Instagame was here.' }, (data) ->
data.should.have.property 'id'
+ test.output "data had the property 'id'", data.id
data.should.have.property 'from'
+ test.output "data had the property 'from'", data.from
data.should.have.property 'created_time'
+ test.output "data had the property 'created_time'", data.created_time
data.should.have.property 'text'
+ test.output "data had the property 'text'", data.text
comment_id = data['id']
- console.log " created comment #{comment_id}"
- test_helper 'media#comments for id#53355234', Instagram, 'media', 'comments', { media_id: 53355234 }, (data) ->
+ test.output "created comment #{comment_id}"
+ test.helper 'media#comments for id#53355234', Instagram, 'media', 'comments', { media_id: 53355234 }, (data) ->
data.length.should.be.above 0
- test_helper 'media#uncomment id#53355234', Instagram, 'media', 'uncomment', { media_id: 53355234, comment_id: comment_id }, (data) ->
- throw "unlike failed" if data isnt null
- console.log " deleted comment #{comment_id}"
+ test.output "data had length greater than 0", data.length
+ test.helper 'media#uncomment id#53355234', Instagram, 'media', 'uncomment', { media_id: 53355234, comment_id: comment_id }, (data) ->
+ throw "uncomment failed" if data isnt null
+ test.output "data was null; we deleted comment #{comment_id}"
View
@@ -1,83 +1,95 @@
(function() {
/*
Testing Media Methods
- */ var Instagram, assert, should, test_helper;
+ */ var Instagram, assert, should, test;
console.log("\nInstagram API Node.js Lib Tests :: Media");
Instagram = require('../lib/class.instagram');
assert = require('assert');
should = require('should');
- test_helper = require('./helpers.js');
+ test = require('./helpers.js');
module.exports = {
'media#popular': function() {
- return test_helper('media#popular', Instagram, 'media', 'popular', {}, function(data) {
+ return test.helper('media#popular', Instagram, 'media', 'popular', {}, function(data) {
data.length.should.equal(32);
- return data[0].should.have.property('id');
+ test.output("data had length equal to 32");
+ data[0].should.have.property('id');
+ return test.output("data[0] had the property 'id'", data[0].id);
});
},
'media#info for id#3': function() {
- return test_helper('media#info for id#3', Instagram, 'media', 'info', {
+ return test.helper('media#info for id#3', Instagram, 'media', 'info', {
media_id: 3
}, function(data) {
data.should.have.property('id', '3');
- return data.should.have.property('created_time', '1279315783');
+ test.output("data had the property 'id' equal to 3");
+ data.should.have.property('created_time', '1279315783');
+ return test.output("data had the property 'created_time' equal to 1279315783");
});
},
'media#search for 48.858844300000001/2.2943506': function() {
- return test_helper('media#search for 48.858844300000001/2.2943506', Instagram, 'media', 'search', {
+ return test.helper('media#search for 48.858844300000001/2.2943506', Instagram, 'media', 'search', {
lat: 48.858844300000001,
lng: 2.2943506
}, function(data) {
data.length.should.be.above(0);
- return data[0].should.have.property('id');
+ test.output("data had length greater than 0", data.length);
+ data[0].should.have.property('id');
+ return test.output("data[0] had the property 'id'", data[0].id);
});
},
'media#like id#3': function() {
- return test_helper('media#like id#3', Instagram, 'media', 'like', {
+ return test.helper('media#like id#3', Instagram, 'media', 'like', {
media_id: 3
}, function(data) {
if (data !== null) {
throw "like failed";
}
- console.log(" liked media #3");
- return test_helper('media#likes for id#3', Instagram, 'media', 'likes', {
+ test.output("data was null; we liked media #3");
+ return test.helper('media#likes for id#3', Instagram, 'media', 'likes', {
media_id: 3
}, function(data) {
data.length.should.be.above(0);
- return test_helper('media#unlike id#3', Instagram, 'media', 'unlike', {
+ test.output("data had length greater than 0", data.length);
+ return test.helper('media#unlike id#3', Instagram, 'media', 'unlike', {
media_id: 3
}, function(data) {
if (data !== null) {
throw "unlike failed";
}
- return console.log(" unliked media #3");
+ return test.output("data was null; we unliked media #3");
});
});
});
},
'media#comment id#53355234': function() {
- return test_helper('media#comment id#53355234', Instagram, 'media', 'comment', {
+ return test.helper('media#comment id#53355234', Instagram, 'media', 'comment', {
media_id: 53355234,
text: 'Instagame was here.'
}, function(data) {
var comment_id;
data.should.have.property('id');
+ test.output("data had the property 'id'", data.id);
data.should.have.property('from');
+ test.output("data had the property 'from'", data.from);
data.should.have.property('created_time');
+ test.output("data had the property 'created_time'", data.created_time);
data.should.have.property('text');
+ test.output("data had the property 'text'", data.text);
comment_id = data['id'];
- console.log(" created comment " + comment_id);
- return test_helper('media#comments for id#53355234', Instagram, 'media', 'comments', {
+ test.output("created comment " + comment_id);
+ return test.helper('media#comments for id#53355234', Instagram, 'media', 'comments', {
media_id: 53355234
}, function(data) {
data.length.should.be.above(0);
- return test_helper('media#uncomment id#53355234', Instagram, 'media', 'uncomment', {
+ test.output("data had length greater than 0", data.length);
+ return test.helper('media#uncomment id#53355234', Instagram, 'media', 'uncomment', {
media_id: 53355234,
comment_id: comment_id
}, function(data) {
if (data !== null) {
- throw "unlike failed";
+ throw "uncomment failed";
}
- return console.log(" deleted comment " + comment_id);
+ return test.output("data was null; we deleted comment " + comment_id);
});
});
});
Oops, something went wrong.

0 comments on commit 29316b9

Please sign in to comment.