Permalink
Browse files

add mocha and expect.js

add mocha and expect.js,
override $uid so it will work either with 1.3 and 1.4
starting testing
  • Loading branch information...
1 parent 7a386f5 commit 421c89f6c7fc2c7f79e3140532941924064a0073 Cristian Carlesso committed Jun 25, 2012
Showing with 5,934 additions and 1 deletion.
  1. +3 −0 Source/kenta.Private.js
  2. +24 −0 Spec/Private.html
  3. +45 −0 Spec/Private.js
  4. +1,202 −0 Spec/expect.js
  5. +182 −0 Spec/mocha.css
  6. +4,477 −0 Spec/mocha.js
  7. +1 −1 package.yml
View
@@ -11,6 +11,9 @@ provides: [Private]
*/
(function(){
+ var $uid = function(x){
+ return x._privateUID || (x._privateUID = String.uniqueID());
+ };
var Private={};
Class.defineMutator(/^private\s(.*)/,function(fn, name){
View
@@ -0,0 +1,24 @@
+<html>
+<head>
+ <title>Private spec</title>
+ <link href="mocha.css" type="text/css" rel="stylesheet" />
+ <script type="text/javascript" src="mocha.js"></script>
+ <script type="text/javascript" src="expect.js"></script>
+ <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/mootools/1.4.5/mootools-yui-compressed.js"></script>
+ <script type="text/javascript" src="../Source/keeto.PatternMutator.js"></script>
+ <script type="text/javascript" src="../Source/kenta.Private.js"></script>
+ <script>
+ mocha.setup('bdd')
+ window.onload = function(){
+ mocha.run(function(){
+ // required so phantomjs can check if mocha is ready
+ document.body.setAttribute('data-ready', '1')
+ })
+ }
+ </script>
+ <script type="text/javascript" src="Private.js"></script>
+</head>
+<body>
+<div id="mocha"></div>
+</body>
+</html>
View
@@ -0,0 +1,45 @@
+describe("Private.js", function(){
+ var Test = new Class({
+ Implements: [Options, Events],
+ options: {
+ name : 'Test'
+ },
+ 'private initialize': function(options, privs){
+ this.setOptions(options);
+ privs.uniqueID = String.uniqueID();
+ privs.name = privs.uniqueID + '.' + this.options.name;
+ },
+ 'private method': function(params, privs){
+ return privs.name;
+ },
+ 'private getUnique': function(privs){
+ return privs.uniqueID;
+ },
+ 'private setup': function(methods, privs){
+ var self = this;
+ Object.each(methods, function(value, name){
+ privs[name] = value.bind(self);
+ })
+ },
+ 'private issue': function(name, privs){
+ return privs[name]();
+ }
+ })
+
+ it("can be used to pass private properties around", function(){
+ var test = new Test({name:'Toio'});
+ var uniqueID = test.getUnique();
+ expect(test.method({})).to.be(uniqueID + '.' + 'Toio');
+ })
+
+ it("can be used to pass private methods around", function(){
+ var myPrivateMethods = {
+ doStuff: function(){
+ return this.options.name.replace(/T/g, 's');
+ }
+ };
+ var test = new Test({name:'Toronto'});
+ test.setup(myPrivateMethods);
+ expect(test.issue('doStuff')).to.be('soronto');
+ })
+})
Oops, something went wrong.

0 comments on commit 421c89f

Please sign in to comment.