Permalink
Browse files

minitest for running tests

  • Loading branch information...
1 parent 2741b44 commit 2c735a9ea33de3c952447565c48f158b5803edeb François de Metz committed Oct 15, 2010
Showing with 85 additions and 39 deletions.
  1. +3 −0 .gitmodules
  2. +5 −0 README.md
  3. +17 −0 tests/fixtures/test.json
  4. +1 −0 tests/minitest
  5. +59 −39 tests/test_client.js
View
@@ -0,0 +1,3 @@
+[submodule "tests/minitest"]
+ path = tests/minitest
+ url = http://github.com/botanicus/minitest.js.git
View
@@ -33,6 +33,11 @@ If a required parameter is not defined, callback is immediatly called with err !
TODO
+## Tests ##
+
+$> git submodule update --init
+$> make test
+
## Examples ##
NONE
View
@@ -0,0 +1,17 @@
+{
+ "api_base_url" : "http://api.twitter.com/1",
+ "version" : "0.1",
+ "methods" : {
+ "public_timeline" : {
+ "params" : [
+ "trim_user",
+ "include_entities"
+ ],
+ "required" : [
+ "format"
+ ],
+ "path" : "/statuses/public_timeline.:format",
+ "method" : "GET"
+ }
+ }
+ }
Submodule minitest added at 58ec8a
View
@@ -1,49 +1,69 @@
// :(
+require.paths.unshift(__dirname +"/minitest");
require.paths.unshift(__dirname +"/../lib");
-var assert = require('assert');
-
// we test that
var Client = require('spore').Client;
-// contruct with a filename
-var clientWithFile = new Client(__dirname +'/fixtures/test.json');
-assert.ok(clientWithFile.public_timeline, "clientWithFile should have a public_timeline method");
-
-// contruct with json
-var twitterClient = new Client({
- "api_base_url" : "http://api.twitter.com/1",
- "version" : "0.1",
- "methods" : {
- "public_timeline" : {
- "params" : [
- "trim_user",
- "include_entities"
- ],
- "required" : [
- "format"
- ],
- "path" : "/statuses/public_timeline.:format",
- "method" : "GET"
- },
- }
+var minitest = require("minitest");
+var assert = require("assert");
+
+minitest.setupListeners();
+
+minitest.context("Create client with filename", function () {
+ this.setup(function () {
+ this.client = new Client(__dirname +'/fixtures/test.json');
});
-assert.ok(twitterClient.public_timeline, "twitterClient should have a public_timeline method");
-// required param missing
-var called = 0;
-twitterClient.public_timeline({}, function(err, result) {
- called++;
- assert.equal(null, result, 'result should be null');
- assert.equal(err, 'format param is required');
+ this.assertion("client should have a public_timeline method", function (test) {
+ assert.ok(this.client.public_timeline,
+ "clientWithFile should have a public_timeline method");
+ test.finished();
+ });
});
-assert.equal(called, 1, "callback should be called");
-// unknow params
-called = 0;
-twitterClient.public_timeline({format: 'json',
- unknowparam: 'foo'}, function(err, result) {
- called++;
- assert.equal(null, result, 'result should be null');
- assert.equal(err, 'unknowparam param is unknow'); // very funny
+
+minitest.context('Create client with json object', function() {
+ this.setup(function() {
+ this.client = new Client({
+ "api_base_url" : "http://api.twitter.com/1",
+ "version" : "0.1",
+ "methods" : {
+ "public_timeline" : {
+ "params" : [
+ "trim_user",
+ "include_entities"
+ ],
+ "required" : [
+ "format"
+ ],
+ "path" : "/statuses/public_timeline.:format",
+ "method" : "GET"
+ },
+ }
+ });
+ });
+
+ this.assertion("client should have a public_timeline method", function(test) {
+
+ assert.ok(this.client.public_timeline,
+ "client should have a public_timeline method");
+ test.finished();
+ });
+
+ this.assertion("err if a required parameter is missing", function(test) {
+ this.client.public_timeline({}, function(err, result) {
+ assert.equal(null, result, 'result should be null');
+ assert.equal(err, 'format param is required');
+ test.finished();
+ });
+ });
+
+ this.assertion("err if unknow param ", function(test) {
+ this.client.public_timeline({format: 'json',
+ unknowparam: 'foo'}, function(err, result) {
+ assert.equal(result, result, 'result should be null');
+ assert.equal(err, 'unknowparam param is unknow'); // very funny
+ test.finished();
+ });
+ });
});
-assert.equal(called, 1, "callback should be called");

0 comments on commit 2c735a9

Please sign in to comment.