Permalink
Browse files

refactoring

  • Loading branch information...
1 parent e100c6f commit cc208a9897f3b0716bb80fc21398797d251f6c3c @cmilfont cmilfont committed Dec 16, 2011
Showing with 43 additions and 64 deletions.
  1. +2 −13 runspec.js
  2. +0 −11 runspecs.js
  3. +32 −37 specs/getjson.spec.js
  4. +9 −3 specs/populate.spec.js
View
@@ -3,24 +3,13 @@ var fs = require('fs');
var sys = require('sys');
var path = require('path');
-global.window = require("jsdom")
- .jsdom()
- .createWindow();
+global.window = require("jsdom").jsdom().createWindow();
global.jQuery = require("jquery").create(window);
//Test framework
var jasmine=require('jasmine-node');
-require(__dirname + "/lib/jsonform.js")
-
-var templatePath = __dirname + '/specs/template.html';
-var templateWithNamePath = __dirname + '/specs/template.with.name.html';
-
-var template = fs.readFileSync(templatePath).toString();
-var templateWithName = fs.readFileSync(templateWithNamePath).toString();
-
-global["template"] = template;
-global["templateWithName"] = templateWithName;
+require(__dirname + "/lib/jsonform.js");
var isVerbose = true;
var showColors = true;
View
@@ -15,17 +15,6 @@ var jasmine=require('jasmine-node');
//require(__dirname + "/lib/jsonform.js")
require(__dirname + "/minified/jsonform.min.js")
-// Templates
-var fs = require('fs');
-var templatePath = __dirname + '/specs/template.html';
-var templateWithNamePath = __dirname + '/specs/template.with.name.html';
-
-var template = fs.readFileSync(templatePath).toString();
-var templateWithName = fs.readFileSync(templateWithNamePath).toString();
-
-global["template"] = template;
-global["templateWithName"] = templateWithName;
-
var isVerbose = true;
var showColors = true;
jasmine.executeSpecsInFolder(__dirname + '/specs', function(runner, log){
View
@@ -1,93 +1,88 @@
-describe("Get JSON with jsonform ", function(){
- var lancamento;
-
- beforeEach( function () {
+describe("Get JSON with jsonform ", function() {
+ var lancamento, template, templateWithName;
+
+ beforeEach( function () {
+
jQuery("body").html("");
+
lancamento = {
empresa: {id: 2, name: "Teste"},
partidas: [
- {conta: {codigo:"1.02.0002", nome: "Compras"}, natureza: "1"},
- {conta: {codigo:"1.01.0001", nome: "Banco"}, natureza: "-1"}
+ {conta: {codigo:"1.02.0002", nome: "Compras"}, natureza: "1"},
+ {conta: {codigo:"1.01.0001", nome: "Banco"}, natureza: "-1"}
],
description: "Teste",
value: "125,67",
date: "12/03/1999"
};
+
+ var fs = require('fs'),
+ templatePath = __dirname + '/template.html',
+ templateWithNamePath = __dirname + '/template.with.name.html';
+
+ template = fs.readFileSync(templatePath).toString();
+ templateWithName = fs.readFileSync(templateWithNamePath).toString();
+
});
describe('when have id property', function() {
-
+
beforeEach( function () {
- jQuery(global["template"]).appendTo("body");
- });
-
+ jQuery(template).appendTo("body");
+ });
it('should have nested object using "getJSON method"', function () {
var byId = true;
var codigo = jQuery('#jsonform').populate(lancamento, byId)
- .getJSON(byId).partidas[0].conta.codigo;
+ .getJSON(byId).partidas[0].conta.codigo;
expect(codigo).toEqual("1.02.0002");
});
-
it('should have nested objects with suffix', function () {
var byId = true;
var json = jQuery("#jsonform").populate(lancamento, byId)
- .getJSON({suffix:"_attributes", byId: byId});
+ .getJSON({suffix:"_attributes", byId: byId});
expect(json.partidas_attributes).toBeTruthy();
});
-
});
-
-
describe('when have name property', function() {
-
+
beforeEach( function () {
- jQuery(global["templateWithName"]).appendTo("body");
+ jQuery(templateWithName).appendTo("body");
});
-
it('should have nested objects', function () {
var codigo = jQuery("form[name='jsonform']").populate(lancamento)
- .getJSON().partidas[0].conta.codigo;
+ .getJSON().partidas[0].conta.codigo;
expect(codigo).toEqual("1.02.0002");
});
-
});
-
describe('when need prefix in nested property', function() {
-
+
beforeEach( function () {
- jQuery(global["templateWithName"]).appendTo("body");
+ jQuery(templateWithName).appendTo("body");
});
-
it('should have nested objects with suffix', function () {
var json = jQuery("form[name='jsonform']").populate(lancamento)
- .getJSON({suffix:"_attributes"});
+ .getJSON({suffix:"_attributes"});
expect(json.partidas_attributes).toBeTruthy();
});
-
it('should have nested objects with prefix', function () {
var json = jQuery("form[name='jsonform']").populate(lancamento)
- .getJSON({prefix:"attributes_"});
+ .getJSON({prefix:"attributes_"});
expect(json.attributes_partidas).toBeTruthy();
});
-
});
-
-
describe('when have an input without name property', function() {
-
+
beforeEach( function () {
- jQuery(global["templateWithName"]).appendTo("body");
+ jQuery(templateWithName).appendTo("body");
});
-
it('should not have property with empty name', function () {
var json = jQuery("form[name='jsonform']").populate(lancamento).getJSON();
var emptyName = false;
for(var name in json) {
- if(name === '') emptyName = true;
+ if(name === '')
+ emptyName = true;
}
expect(emptyName).toBeFalsy();
});
-
});
-
});
@@ -1,11 +1,17 @@
-var lancamento;
+var lancamento, template, templateWithName;
+var fs = require('fs'),
+ templatePath = __dirname + '/template.html',
+ templateWithNamePath = __dirname + '/template.with.name.html';
+
+template = fs.readFileSync(templatePath).toString();
+templateWithName = fs.readFileSync(templateWithNamePath).toString();
describe('Populate with jsonform when have id property', function() {
beforeEach( function () {
jQuery("body").html("");
- jQuery(global["template"]).appendTo("body");
+ jQuery(template).appendTo("body");
lancamento = {
empresa: {id: 2, name: "Teste"},
partidas: [
@@ -31,7 +37,7 @@ describe('Populate with jsonform when have name property', function() {
beforeEach( function () {
jQuery("body").html("");
- jQuery(global["templateWithName"]).appendTo("body");
+ jQuery(templateWithName).appendTo("body");
lancamento = {
empresa: {id: 2, name: "Teste"},
partidas: [

0 comments on commit cc208a9

Please sign in to comment.