From a2802923e297ed863717cfd495c55db1ce76c896 Mon Sep 17 00:00:00 2001 From: "Davis W. Frank" Date: Thu, 27 Nov 2008 14:30:46 -0800 Subject: [PATCH] dwf: refactor to move expects & spec to the global name space so they're accessible. --- jasmine.iml | 17 ++ jasmine.ipr | 250 +++++++++++++++++ jasmine.iws | 526 +++++++++++++++++++++++++++++++++++ jspec | 1 + lib/jasmine.js | 81 ++++++ nbproject/project.properties | 3 + nbproject/project.xml | 11 + test/spinner.gif | Bin 0 -> 1737 bytes test/test.html | 22 ++ test/test.js | 101 +++++++ 10 files changed, 1012 insertions(+) create mode 100644 jasmine.iml create mode 100644 jasmine.ipr create mode 100644 jasmine.iws create mode 160000 jspec create mode 100644 lib/jasmine.js create mode 100644 nbproject/project.properties create mode 100644 nbproject/project.xml create mode 100644 test/spinner.gif create mode 100644 test/test.html create mode 100644 test/test.js diff --git a/jasmine.iml b/jasmine.iml new file mode 100644 index 0000000..bf91408 --- /dev/null +++ b/jasmine.iml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + diff --git a/jasmine.ipr b/jasmine.ipr new file mode 100644 index 0000000..ce1553f --- /dev/null +++ b/jasmine.ipr @@ -0,0 +1,250 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/jasmine.iws b/jasmine.iws new file mode 100644 index 0000000..a3c3c38 --- /dev/null +++ b/jasmine.iws @@ -0,0 +1,526 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + localhost + 5050 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/jspec b/jspec new file mode 160000 index 0000000..d1c67d1 --- /dev/null +++ b/jspec @@ -0,0 +1 @@ +Subproject commit d1c67d1f23fc186b86d1a4472039e13a389c903b diff --git a/lib/jasmine.js b/lib/jasmine.js new file mode 100644 index 0000000..8e2e246 --- /dev/null +++ b/lib/jasmine.js @@ -0,0 +1,81 @@ +// Crockford's helpers + +// Object.create instead of new Object +if (typeof Object.create !== 'function') { + Object.create = function (o) { + var F = function () {}; + F.prototype = o; + return new F(); + }; +} + +// Klass.method instead of Klass.prototype.name = function +Function.prototype.method = function (name, func) { + this.prototype[name] = func; + return this; +} + +/****************************************************************************** + * Jasmine + ******************************************************************************/ + +/* + * Jasmine expectation constructor + */ +var expects = function (actual) { + var that = {}; + that.actual = actual; + + that.should_equal = function(expected) { + var message = 'Passed.'; + result = (that.actual === expected); + + if (!result) { + message = 'Expected ' + expected + ' but got ' + that.actual + '.'; + } + + Jasmine.results.push({ + passed: result, + message: message + }); + + return result; + } + + return that; +} + +var spec = function (description, func) { + return { + description: description, + execute: func + } +} + +var jasmine_init = function () { + return { + results: [] + } +} + +var Jasmine = jasmine_init(); + +// spec: { +// description: description, +// func: func, +// execute: function() {with(jasmine) {func();}} +// }, +// +// expects_that: function(actual) { +// +// this.actual = actual; +// return this; +// }, +// +// } +//} +// +//var JasmineSpec = function(description, func) { +// +//} + diff --git a/nbproject/project.properties b/nbproject/project.properties new file mode 100644 index 0000000..caab57d --- /dev/null +++ b/nbproject/project.properties @@ -0,0 +1,3 @@ +main.file= +platform.active=Ruby +source.encoding=UTF-8 diff --git a/nbproject/project.xml b/nbproject/project.xml new file mode 100644 index 0000000..5b7dc0a --- /dev/null +++ b/nbproject/project.xml @@ -0,0 +1,11 @@ + + + org.netbeans.modules.ruby.rubyproject + + + jasmine + + + + + diff --git a/test/spinner.gif b/test/spinner.gif new file mode 100644 index 0000000000000000000000000000000000000000..148005da279b97c0acc697d48a815645977dc723 GIT binary patch literal 1737 zcmYk+ZA?>H8o=>msePlC7H(UlOeuva6-udX=eG2X-nQJ9g5||K3}WrHKr7Zx(JnHq zYm9Sl?~UuSa${USIL0u>7~?RkfNPD*`ob8-IL0xKV;t8tt}(_n#yG|p*O+y6r*3#Y zo}4H7<@}T5Z^5mNF)7XZ9@^9BHL{rdI2d-q18QMcRe^ZC;0^r1tCZr{Fr`0(NC z>T0c4YcLp46m_{=$z<~M>C@%q<(W+8@#Du&o;;bKpWn4>S4T%jBoaAu=FHWrS8X<% zOePx}8#{LFSU4Qswr$(Jd-rIX7KucIgM$YS97rS*Cr_Tlaah-n{wj*|S@>Zf)JV^~8x2Gcz-7ZEam$UA?`%eSLi% zkH_I~T)1#yWMsr>G(LLtsJ6Ct_wL<2Jv};|PN`H*OiYAAq2l7=ojZ393=Ejf=8G3E zUcP+!!Gi~U=R0Kh!QmGv~cD#M_U#IdvW!_9YHXI*NeZFCMP!&tY zMpHwv0sV$_VhB|Jn+*hSFIK)O3^fz0y;w)HQEw<%^7csgZvS0G!2RP60Ld&xDXLb~ z(-g0~x>gTSn}re-e(+&k1GE^ND9Pd!D`^x#_JM-Jk}=?HazeIHGHr4Z{<1uku9sN;jT0*bq@ZR zy5l(W&#&;^(fMKyE012XSU8p!+6zAE5w2aQpn;?GDKjD1idkWAsSnflj1#qo+1HjNgl{r4E%i_$QP7s;6!vR z8hE*_oFdUOVKPNoBkKn{rBZL#Mj?+>4}=`_V10)I_KOn?5P!A~>PlR>U^)qn0Yi?^ z*F&Y*l%qb9`>$rBac>T_kw``2EM;^4K>9zbzzB=QfHX)^%I(#9J(%6yaGS>Yip)z@ z@t=GD;?C;|7VF0Ix+bks9I8zDY0xO=)+}GYHW><1SXCgUz@46TMePof&={?B;?p)e zZ0y!DARsJ&K^;FQ+4u=eC2TpQ_+vPf`i>z!$UvE+FBkl*75cTVT&T7R;!&%b*|ZEJ z8={SB1GGE`n<=E3#a9zf6Po_lgbEifEnPCSq8#DnjqJt7_lc3%P+X~zG|_-xw>d61 z2TF`G%I6Ts+$IxC@S(Vj#H|iH9aNRLp}SwffcV-JbXkdlVSeGHzfRj z;-!m$?-Lu`joLa1hR}e(to^|X-e!S|k}9Hp0=22jy1OwFb-Nm9k2&54o&0Z@p)Ls| zd?p6CxPyP4Ig3ZQP&&S_ss^g$zU%9$HNRND; z4%e^AlsXu!YD1y$%HE%U`TFj}`^22Zx}EvN7H5;)Wmg+$U?Y5d7Ur>bswq_3ATPx0w-9QSx`*AL7f4I3iUbdbvlHZ_8bb`@^p|+G4|{ zQXHj8)Py5_KA)4)&^Dymj*!?g{WyWSOt7jpG!FPOA8f6zn?k&eurN$ap}~GAtUohu zt2hbPuhCBVdL=MkxMfPB!yv1*XEQC6^A^BR$FQ-}iDRisxq_-wwI|zFMYzh?xSzLj Wc_{4u<=a1<$G!l-{_f-Z-~1P&zb^m) literal 0 HcmV?d00001 diff --git a/test/test.html b/test/test.html new file mode 100644 index 0000000..3842f17 --- /dev/null +++ b/test/test.html @@ -0,0 +1,22 @@ + + + + Jasmine Tests + + + + + + + +

+ Running all Jasmine Test Suites +

+
+ +
+ + + + diff --git a/test/test.js b/test/test.js new file mode 100644 index 0000000..2e7f951 --- /dev/null +++ b/test/test.js @@ -0,0 +1,101 @@ +// NOTE: we're using JSpec to test-drive Jasmine. Any syntax +// similarities should be ignored. THIS FILE uses JSpec + +with(JSpec('Jasmine expectation results')) { + + it('should compare actual and expected values that are equal', function(){ + var jasmine_result = expects(true).should_equal(true); + + expects_that(jasmine_result).should_equal(true).and_finish(); + }); + + it('should compare actual and expected values that are NOT equal', function(){ + var jasmine_result = expects(false).should_equal(true); + + expects_that(jasmine_result).should_equal(false).and_finish(); + }); + + it('should be able to store the results of assertions', function(){ + Jasmine = jasmine_init(); // re-clears out Jasmine + + expects(true).should_equal(true); + expects(false).should_equal(true); + + expects_that(Jasmine.results.length).should_equal(2); + expects_that(Jasmine.results[0].passed).should_equal(true); + expects_that(Jasmine.results[1].passed).should_equal(false).and_finish(); + }); + + it('should store a message with a failed expectation', function(){ + Jasmine = jasmine_init(); // re-clears out Jasmine + + expects(false).should_equal(true); + + var expected_message = 'Expected true but got false.'; + expects_that(Jasmine.results[0].message).should_equal(expected_message).and_finish(); + }); + + it('should store a default message with a passed expectation', function(){ + Jasmine = jasmine_init(); + + expects(true).should_equal(true); + + var expected_message = 'Passed.'; + expects_that(Jasmine.results[0].message).should_equal(expected_message).and_finish(); + }); + +} + +with(JSpec('Jasmine specs')){ + + it('can have a description', function(){ + Jasmine = jasmine_init(); + + var a_spec = spec('new spec'); + expects_that(a_spec.description).should_equal('new spec').and_finish(); + }); + + it('can execute some statements & expectations', function(){ + Jasmine = jasmine_init(); + + var a_spec = spec('new spec', function() { + var foo = 'bar'; + expects(foo).should_equal('bar'); + }); + + a_spec.execute(); + + expects_that(Jasmine.results.length).should_equal(1) + expects_that(Jasmine.results[0].passed).should_equal(true).and_finish(); + }); +} +// it('should return true if all of its results are true', function(){ +// }); + +// it('can have multiple assertions', function(){ +// +// var jasmine = Jasmine(); +// jasmine.expects_that(true).should_equal(true); +// +// var expected_message = 'Passed.'; +// expects_that(jasmine.results[0].message).should_equal(expected_message).and_finish(); +// +// }); + +//} + + +//with(JSpec('Test runner')) { +// +// it('should run a test and collect a result', function(){ +// +// +// +// +// }); +// +// expects_that(actual).should_equal(expected)u; +// +// +// +//} \ No newline at end of file