js_spec 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGES +2 -0
- data/README +9 -0
- data/Rakefile +72 -0
- data/bin/js_spec_server +9 -0
- data/core/COPYING +459 -0
- data/core/JSSpec.css +216 -0
- data/core/JSSpec.js +1506 -0
- data/core/JSSpecExtensions.js +27 -0
- data/core/demo.html +182 -0
- data/core/diff_match_patch.js +1 -0
- data/lib/js_spec/dir.rb +58 -0
- data/lib/js_spec/file.rb +26 -0
- data/lib/js_spec/server.rb +77 -0
- data/lib/js_spec/spec_dir_runner.rb +13 -0
- data/lib/js_spec/spec_file_runner.rb +13 -0
- data/lib/js_spec/spec_runner.rb +27 -0
- data/lib/js_spec/suite_result.rb +11 -0
- data/lib/js_spec/web_root.rb +18 -0
- data/lib/js_spec.rb +13 -0
- data/spec/functional/functional_spec_helper.rb +18 -0
- data/spec/functional/server_spec.rb +5 -0
- data/spec/functional_spec_suite.rb +10 -0
- data/spec/spec_suite.rb +3 -0
- data/spec/unit/dir_spec.rb +82 -0
- data/spec/unit/file_spec.rb +78 -0
- data/spec/unit/server_spec.rb +156 -0
- data/spec/unit/spec_dir_runner_spec.rb +41 -0
- data/spec/unit/spec_file_runner_spec.rb +18 -0
- data/spec/unit/suite_result_spec.rb +31 -0
- data/spec/unit/unit_spec_helper.rb +84 -0
- data/spec/unit/web_root_spec.rb +39 -0
- data/spec/unit_spec_suite.rb +10 -0
- metadata +82 -0
@@ -0,0 +1,27 @@
|
|
1
|
+
var Require = {
|
2
|
+
require: function(path_from_javascripts) {
|
3
|
+
if(!Require.required_paths[path_from_javascripts]) {
|
4
|
+
var full_path = path_from_javascripts + ".js?" + Require.cache_buster;
|
5
|
+
document.write("<script src='" + full_path + "' type='text/javascript'></script>");
|
6
|
+
Require.required_paths[path_from_javascripts] = true;
|
7
|
+
}
|
8
|
+
},
|
9
|
+
|
10
|
+
required_paths: {},
|
11
|
+
cache_buster: parseInt(new Date().getTime()/(1*1000))
|
12
|
+
}
|
13
|
+
|
14
|
+
var require = Require.require;
|
15
|
+
|
16
|
+
JSSpec.Logger.prototype.onRunnerEndWithoutServerNotification = JSSpec.Logger.prototype.onRunnerEnd;
|
17
|
+
JSSpec.Logger.prototype.onRunnerEndWithServerNotification = function() {
|
18
|
+
this.onRunnerEndWithoutServerNotification();
|
19
|
+
$.ajax({
|
20
|
+
type: 'POST',
|
21
|
+
url: '/results',
|
22
|
+
data: {
|
23
|
+
'text': "---------------------------------------------------------------------------------------\n\n+++++++++++++++++++++++++++++++++++++"
|
24
|
+
}
|
25
|
+
});
|
26
|
+
}
|
27
|
+
JSSpec.Logger.prototype.onRunnerEnd = JSSpec.Logger.prototype.onRunnerEndWithServerNotification;
|
data/core/demo.html
ADDED
@@ -0,0 +1,182 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
|
2
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ko">
|
3
|
+
<head>
|
4
|
+
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
|
5
|
+
<title>JSSpec results</title>
|
6
|
+
<link rel="stylesheet" type="text/css" href="JSSpec.css" />
|
7
|
+
<script type="text/javascript" src="diff_match_patch.js"></script>
|
8
|
+
<script type="text/javascript" src="JSSpec.js"></script>
|
9
|
+
<script type="text/javascript">// <![CDATA[
|
10
|
+
describe('Plus operator (just for example)', {
|
11
|
+
'should concatenate two strings': function() {
|
12
|
+
value_of("Hello " + "World").should_be("Hello World");
|
13
|
+
},
|
14
|
+
'should add two numbers': function() {
|
15
|
+
value_of(1 + 2).should_be(3);
|
16
|
+
}
|
17
|
+
})
|
18
|
+
|
19
|
+
describe('"Should match"s', {
|
20
|
+
'Should match': function() {
|
21
|
+
value_of("Hello").should_match(/ell/);
|
22
|
+
},
|
23
|
+
'Should match 1': function() {
|
24
|
+
value_of("Hello").should_match(/x/);
|
25
|
+
},
|
26
|
+
'Should match 2': function() {
|
27
|
+
value_of([1,2,3]).should_match(/x/);
|
28
|
+
},
|
29
|
+
'Should not match 1': function() {
|
30
|
+
value_of("Hello").should_not_match(/ell/);
|
31
|
+
},
|
32
|
+
'Should not match 2': function() {
|
33
|
+
value_of([1,2,3]).should_not_match(/x/);
|
34
|
+
}
|
35
|
+
})
|
36
|
+
describe('"Should include"s', {
|
37
|
+
'Should include': function() {
|
38
|
+
value_of([1,2,3]).should_include(4);
|
39
|
+
},
|
40
|
+
'Should not include': function() {
|
41
|
+
value_of([1,2,3]).should_not_include(2);
|
42
|
+
},
|
43
|
+
'Should include / Non-array object': function() {
|
44
|
+
value_of(new Date()).should_include(4);
|
45
|
+
},
|
46
|
+
'Should not include / Non-array object': function() {
|
47
|
+
value_of(new Date()).should_not_include(4);
|
48
|
+
}
|
49
|
+
})
|
50
|
+
|
51
|
+
describe('"Should have"s', {
|
52
|
+
'String length': function() {
|
53
|
+
value_of("Hello").should_have(4, "characters");
|
54
|
+
},
|
55
|
+
'Array length': function() {
|
56
|
+
value_of([1,2,3]).should_have(4, "items");
|
57
|
+
},
|
58
|
+
'Object\'s item length': function() {
|
59
|
+
value_of({name:'Alan Kang', email:'jania902@gmail.com', accounts:['A', 'B']}).should_have(3, "accounts");
|
60
|
+
},
|
61
|
+
'No match': function() {
|
62
|
+
value_of("This is a string").should_have(5, "players");
|
63
|
+
},
|
64
|
+
'Exactly': function() {
|
65
|
+
value_of([1,2,3]).should_have_exactly(2, "items");
|
66
|
+
},
|
67
|
+
'At least': function() {
|
68
|
+
value_of([1,2,3]).should_have_at_least(4, "items");
|
69
|
+
},
|
70
|
+
'At most': function() {
|
71
|
+
value_of([1,2,3]).should_have_at_most(2, "items");
|
72
|
+
}
|
73
|
+
})
|
74
|
+
describe('"Should be empty"s', {
|
75
|
+
'String': function() {
|
76
|
+
value_of("Hello").should_be_empty();
|
77
|
+
},
|
78
|
+
'Array': function() {
|
79
|
+
value_of([1,2,3]).should_be_empty();
|
80
|
+
},
|
81
|
+
'Object\'s item': function() {
|
82
|
+
value_of({name:'Alan Kang', email:'jania902@gmail.com', accounts:['A', 'B']}).should_have(0, "accounts");
|
83
|
+
}
|
84
|
+
})
|
85
|
+
|
86
|
+
describe('Failure messages', {
|
87
|
+
'Should be (String)': function() {
|
88
|
+
value_of("Hello World").should_be("Good-bye world");
|
89
|
+
},
|
90
|
+
'Should have (Object\s item)': function() {
|
91
|
+
value_of({name:'Alan Kang', email:'jania902@gmail.com', accounts:['A', 'B']}).should_have(3, "accounts");
|
92
|
+
},
|
93
|
+
'Should have at least': function() {
|
94
|
+
value_of([1,2,3]).should_have_at_least(4, "items");
|
95
|
+
},
|
96
|
+
'Should include': function() {
|
97
|
+
value_of([1,2,3]).should_include(4);
|
98
|
+
},
|
99
|
+
'Should match': function() {
|
100
|
+
value_of("Hello").should_match(/bye/);
|
101
|
+
}
|
102
|
+
})
|
103
|
+
|
104
|
+
describe('"Should be"s', {
|
105
|
+
'String mismatch': function() {
|
106
|
+
value_of("Hello world").should_be("Good-bye world");
|
107
|
+
},
|
108
|
+
'Array item mismatch': function() {
|
109
|
+
value_of(['ab','cd','ef']).should_be(['ab','bd','ef']);
|
110
|
+
},
|
111
|
+
'Array length mismatch': function() {
|
112
|
+
value_of(['a',2,'4',5]).should_be([1,2,[4,5,6],6,7]);
|
113
|
+
},
|
114
|
+
'Undefined value': function() {
|
115
|
+
value_of("Test").should_be(undefined);
|
116
|
+
},
|
117
|
+
'Null value': function() {
|
118
|
+
value_of(null).should_be("Test");
|
119
|
+
},
|
120
|
+
'Boolean value 1': function() {
|
121
|
+
value_of(true).should_be(false);
|
122
|
+
},
|
123
|
+
'Boolean value 2': function() {
|
124
|
+
value_of(false).should_be_true();
|
125
|
+
},
|
126
|
+
'Boolean value 3': function() {
|
127
|
+
value_of(true).should_be_false();
|
128
|
+
},
|
129
|
+
'Number mismatch': function() {
|
130
|
+
value_of(1+2).should_be(4);
|
131
|
+
},
|
132
|
+
'Date mismatch': function() {
|
133
|
+
value_of(new Date(1979, 3, 27)).should_be(new Date(1976, 7, 23));
|
134
|
+
},
|
135
|
+
'Object mismatch 1': function() {
|
136
|
+
var actual = {a:1, b:2};
|
137
|
+
var expected = {a:1, b:2, d:3};
|
138
|
+
|
139
|
+
value_of(actual).should_be(expected);
|
140
|
+
},
|
141
|
+
'Object mismatch 2': function() {
|
142
|
+
var actual = {a:1, b:2, c:3, d:4};
|
143
|
+
var expected = {a:1, b:2, c:3};
|
144
|
+
|
145
|
+
value_of(actual).should_be(expected);
|
146
|
+
},
|
147
|
+
'Object mismatch 3': function() {
|
148
|
+
var actual = {a:1, b:4, c:3};
|
149
|
+
var expected = {a:1, b:2, c:3};
|
150
|
+
|
151
|
+
value_of(actual).should_be(expected);
|
152
|
+
},
|
153
|
+
'null should be null': function() {
|
154
|
+
value_of(null).should_be(null);
|
155
|
+
},
|
156
|
+
'null should not be undefined': function() {
|
157
|
+
value_of(null).should_be(undefined);
|
158
|
+
},
|
159
|
+
'null should not be null': function() {
|
160
|
+
value_of(null).should_not_be(null);
|
161
|
+
},
|
162
|
+
'empty array 1': function() {
|
163
|
+
value_of([]).should_be_empty();
|
164
|
+
value_of([1]).should_be_empty();
|
165
|
+
},
|
166
|
+
'empty array 2': function() {
|
167
|
+
value_of([1]).should_not_be_empty();
|
168
|
+
value_of([]).should_not_be_empty();
|
169
|
+
}
|
170
|
+
})
|
171
|
+
|
172
|
+
describe('Equality operator', {
|
173
|
+
'should work for different Date instances which have same value': function() {
|
174
|
+
var date1 = new Date(1979, 03, 27);
|
175
|
+
var date2 = new Date(1979, 03, 27);
|
176
|
+
value_of(date1).should_be(date2);
|
177
|
+
}
|
178
|
+
})
|
179
|
+
// ]]></script>
|
180
|
+
</head>
|
181
|
+
<body><div style="display:none;"><p>A</p><p>B</p></div></body>
|
182
|
+
</html>
|
@@ -0,0 +1 @@
|
|
1
|
+
function diff_match_patch(){this.Diff_Timeout=1.0;this.Diff_EditCost=4;this.Diff_DualThreshold=32;this.Match_Balance=0.5;this.Match_Threshold=0.5;this.Match_MinLength=100;this.Match_MaxLength=1000;this.Patch_Margin=4;function getMaxBits(){var maxbits=0;var oldi=1;var newi=2;while(oldi!=newi){maxbits++;oldi=newi;newi=newi<<1}return maxbits}this.Match_MaxBits=getMaxBits()}var DIFF_DELETE=-1;var DIFF_INSERT=1;var DIFF_EQUAL=0;diff_match_patch.prototype.diff_main=function(text1,text2,opt_checklines){if(text1==text2){return[[DIFF_EQUAL,text1]]}if(typeof opt_checklines=='undefined'){opt_checklines=true}var checklines=opt_checklines;var commonlength=this.diff_commonPrefix(text1,text2);var commonprefix=text1.substring(0,commonlength);text1=text1.substring(commonlength);text2=text2.substring(commonlength);commonlength=this.diff_commonSuffix(text1,text2);var commonsuffix=text1.substring(text1.length-commonlength);text1=text1.substring(0,text1.length-commonlength);text2=text2.substring(0,text2.length-commonlength);var diffs=this.diff_compute(text1,text2,checklines);if(commonprefix){diffs.unshift([DIFF_EQUAL,commonprefix])}if(commonsuffix){diffs.push([DIFF_EQUAL,commonsuffix])}this.diff_cleanupMerge(diffs);return diffs};diff_match_patch.prototype.diff_compute=function(text1,text2,checklines){var diffs;if(!text1){return[[DIFF_INSERT,text2]]}if(!text2){return[[DIFF_DELETE,text1]]}var longtext=text1.length>text2.length?text1:text2;var shorttext=text1.length>text2.length?text2:text1;var i=longtext.indexOf(shorttext);if(i!=-1){diffs=[[DIFF_INSERT,longtext.substring(0,i)],[DIFF_EQUAL,shorttext],[DIFF_INSERT,longtext.substring(i+shorttext.length)]];if(text1.length>text2.length){diffs[0][0]=diffs[2][0]=DIFF_DELETE}return diffs}longtext=shorttext=null;var hm=this.diff_halfMatch(text1,text2);if(hm){var text1_a=hm[0];var text1_b=hm[1];var text2_a=hm[2];var text2_b=hm[3];var mid_common=hm[4];var diffs_a=this.diff_main(text1_a,text2_a,checklines);var diffs_b=this.diff_main(text1_b,text2_b,checklines);return diffs_a.concat([[DIFF_EQUAL,mid_common]],diffs_b)}if(checklines&&text1.length+text2.length<250){checklines=false}var linearray;if(checklines){var a=this.diff_linesToChars(text1,text2);text1=a[0];text2=a[1];linearray=a[2]}diffs=this.diff_map(text1,text2);if(!diffs){diffs=[[DIFF_DELETE,text1],[DIFF_INSERT,text2]]}if(checklines){this.diff_charsToLines(diffs,linearray);this.diff_cleanupSemantic(diffs);diffs.push([DIFF_EQUAL,'']);var pointer=0;var count_delete=0;var count_insert=0;var text_delete='';var text_insert='';while(pointer<diffs.length){if(diffs[pointer][0]==DIFF_INSERT){count_insert++;text_insert+=diffs[pointer][1]}else if(diffs[pointer][0]==DIFF_DELETE){count_delete++;text_delete+=diffs[pointer][1]}else{if(count_delete>=1&&count_insert>=1){var a=this.diff_main(text_delete,text_insert,false);diffs.splice(pointer-count_delete-count_insert,count_delete+count_insert);pointer=pointer-count_delete-count_insert;for(var j=a.length-1;j>=0;j--){diffs.splice(pointer,0,a[j])}pointer=pointer+a.length}count_insert=0;count_delete=0;text_delete='';text_insert=''}pointer++}diffs.pop()}return diffs};diff_match_patch.prototype.diff_linesToChars=function(text1,text2){var linearray=[];var linehash={};linearray.push('');function diff_linesToCharsMunge(text){var chars='';while(text){var i=text.indexOf('\n');if(i==-1){i=text.length}var line=text.substring(0,i+1);text=text.substring(i+1);if(linehash.hasOwnProperty?linehash.hasOwnProperty(line):(linehash[line]!==undefined)){chars+=String.fromCharCode(linehash[line])}else{linearray.push(line);linehash[line]=linearray.length-1;chars+=String.fromCharCode(linearray.length-1)}}return chars}var chars1=diff_linesToCharsMunge(text1);var chars2=diff_linesToCharsMunge(text2);return[chars1,chars2,linearray]};diff_match_patch.prototype.diff_charsToLines=function(diffs,linearray){for(var x=0;x<diffs.length;x++){var chars=diffs[x][1];var text=[];for(var y=0;y<chars.length;y++){text.push(linearray[chars.charCodeAt(y)])}diffs[x][1]=text.join('')}};diff_match_patch.prototype.diff_map=function(text1,text2){var ms_end=(new Date()).getTime()+this.Diff_Timeout*1000;var max_d=text1.length+text2.length-1;var doubleEnd=this.Diff_DualThreshold*2<max_d;var v_map1=[];var v_map2=[];var v1={};var v2={};v1[1]=0;v2[1]=0;var x,y;var footstep;var footsteps={};var done=false;var hasOwnProperty=!!(footsteps.hasOwnProperty);var front=(text1.length+text2.length)%2;for(var d=0;d<max_d;d++){if(this.Diff_Timeout>0&&(new Date()).getTime()>ms_end){return null}v_map1[d]={};for(var k=-d;k<=d;k+=2){if(k==-d||k!=d&&v1[k-1]<v1[k+1]){x=v1[k+1]}else{x=v1[k-1]+1}y=x-k;if(doubleEnd){footstep=x+','+y;if(front&&(hasOwnProperty?footsteps.hasOwnProperty(footstep):(footsteps[footstep]!==undefined))){done=true}if(!front){footsteps[footstep]=d}}while(!done&&x<text1.length&&y<text2.length&&text1.charAt(x)==text2.charAt(y)){x++;y++;if(doubleEnd){footstep=x+','+y;if(front&&(hasOwnProperty?footsteps.hasOwnProperty(footstep):(footsteps[footstep]!==undefined))){done=true}if(!front){footsteps[footstep]=d}}}v1[k]=x;v_map1[d][x+','+y]=true;if(x==text1.length&&y==text2.length){return this.diff_path1(v_map1,text1,text2)}else if(done){v_map2=v_map2.slice(0,footsteps[footstep]+1);var a=this.diff_path1(v_map1,text1.substring(0,x),text2.substring(0,y));return a.concat(this.diff_path2(v_map2,text1.substring(x),text2.substring(y)))}}if(doubleEnd){v_map2[d]={};for(var k=-d;k<=d;k+=2){if(k==-d||k!=d&&v2[k-1]<v2[k+1]){x=v2[k+1]}else{x=v2[k-1]+1}y=x-k;footstep=(text1.length-x)+','+(text2.length-y);if(!front&&(hasOwnProperty?footsteps.hasOwnProperty(footstep):(footsteps[footstep]!==undefined))){done=true}if(front){footsteps[footstep]=d}while(!done&&x<text1.length&&y<text2.length&&text1.charAt(text1.length-x-1)==text2.charAt(text2.length-y-1)){x++;y++;footstep=(text1.length-x)+','+(text2.length-y);if(!front&&(hasOwnProperty?footsteps.hasOwnProperty(footstep):(footsteps[footstep]!==undefined))){done=true}if(front){footsteps[footstep]=d}}v2[k]=x;v_map2[d][x+','+y]=true;if(done){v_map1=v_map1.slice(0,footsteps[footstep]+1);var a=this.diff_path1(v_map1,text1.substring(0,text1.length-x),text2.substring(0,text2.length-y));return a.concat(this.diff_path2(v_map2,text1.substring(text1.length-x),text2.substring(text2.length-y)))}}}}return null};diff_match_patch.prototype.diff_path1=function(v_map,text1,text2){var path=[];var x=text1.length;var y=text2.length;var last_op=null;for(var d=v_map.length-2;d>=0;d--){while(1){if(v_map[d].hasOwnProperty?v_map[d].hasOwnProperty((x-1)+','+y):(v_map[d][(x-1)+','+y]!==undefined)){x--;if(last_op===DIFF_DELETE){path[0][1]=text1.charAt(x)+path[0][1]}else{path.unshift([DIFF_DELETE,text1.charAt(x)])}last_op=DIFF_DELETE;break}else if(v_map[d].hasOwnProperty?v_map[d].hasOwnProperty(x+','+(y-1)):(v_map[d][x+','+(y-1)]!==undefined)){y--;if(last_op===DIFF_INSERT){path[0][1]=text2.charAt(y)+path[0][1]}else{path.unshift([DIFF_INSERT,text2.charAt(y)])}last_op=DIFF_INSERT;break}else{x--;y--;if(last_op===DIFF_EQUAL){path[0][1]=text1.charAt(x)+path[0][1]}else{path.unshift([DIFF_EQUAL,text1.charAt(x)])}last_op=DIFF_EQUAL}}}return path};diff_match_patch.prototype.diff_path2=function(v_map,text1,text2){var path=[];var x=text1.length;var y=text2.length;var last_op=null;for(var d=v_map.length-2;d>=0;d--){while(1){if(v_map[d].hasOwnProperty?v_map[d].hasOwnProperty((x-1)+','+y):(v_map[d][(x-1)+','+y]!==undefined)){x--;if(last_op===DIFF_DELETE){path[path.length-1][1]+=text1.charAt(text1.length-x-1)}else{path.push([DIFF_DELETE,text1.charAt(text1.length-x-1)])}last_op=DIFF_DELETE;break}else if(v_map[d].hasOwnProperty?v_map[d].hasOwnProperty(x+','+(y-1)):(v_map[d][x+','+(y-1)]!==undefined)){y--;if(last_op===DIFF_INSERT){path[path.length-1][1]+=text2.charAt(text2.length-y-1)}else{path.push([DIFF_INSERT,text2.charAt(text2.length-y-1)])}last_op=DIFF_INSERT;break}else{x--;y--;if(last_op===DIFF_EQUAL){path[path.length-1][1]+=text1.charAt(text1.length-x-1)}else{path.push([DIFF_EQUAL,text1.charAt(text1.length-x-1)])}last_op=DIFF_EQUAL}}}return path};diff_match_patch.prototype.diff_commonPrefix=function(text1,text2){if(!text1||!text2||text1.charCodeAt(0)!==text2.charCodeAt(0)){return 0}var pointermin=0;var pointermax=Math.min(text1.length,text2.length);var pointermid=pointermax;var pointerstart=0;while(pointermin<pointermid){if(text1.substring(pointerstart,pointermid)==text2.substring(pointerstart,pointermid)){pointermin=pointermid;pointerstart=pointermin}else{pointermax=pointermid}pointermid=Math.floor((pointermax-pointermin)/2+pointermin)}return pointermid};diff_match_patch.prototype.diff_commonSuffix=function(text1,text2){if(!text1||!text2||text1.charCodeAt(text1.length-1)!==text2.charCodeAt(text2.length-1)){return 0}var pointermin=0;var pointermax=Math.min(text1.length,text2.length);var pointermid=pointermax;var pointerend=0;while(pointermin<pointermid){if(text1.substring(text1.length-pointermid,text1.length-pointerend)==text2.substring(text2.length-pointermid,text2.length-pointerend)){pointermin=pointermid;pointerend=pointermin}else{pointermax=pointermid}pointermid=Math.floor((pointermax-pointermin)/2+pointermin)}return pointermid};diff_match_patch.prototype.diff_halfMatch=function(text1,text2){var longtext=text1.length>text2.length?text1:text2;var shorttext=text1.length>text2.length?text2:text1;if(longtext.length<10||shorttext.length<1){return null}var dmp=this;function diff_halfMatchI(longtext,shorttext,i){var seed=longtext.substring(i,i+Math.floor(longtext.length/4));var j=-1;var best_common='';var best_longtext_a,best_longtext_b,best_shorttext_a,best_shorttext_b;while((j=shorttext.indexOf(seed,j+1))!=-1){var prefixLength=dmp.diff_commonPrefix(longtext.substring(i),shorttext.substring(j));var suffixLength=dmp.diff_commonSuffix(longtext.substring(0,i),shorttext.substring(0,j));if(best_common.length<suffixLength+prefixLength){best_common=shorttext.substring(j-suffixLength,j)+shorttext.substring(j,j+prefixLength);best_longtext_a=longtext.substring(0,i-suffixLength);best_longtext_b=longtext.substring(i+prefixLength);best_shorttext_a=shorttext.substring(0,j-suffixLength);best_shorttext_b=shorttext.substring(j+prefixLength)}}if(best_common.length>=longtext.length/2){return[best_longtext_a,best_longtext_b,best_shorttext_a,best_shorttext_b,best_common]}else{return null}}var hm1=diff_halfMatchI(longtext,shorttext,Math.ceil(longtext.length/4));var hm2=diff_halfMatchI(longtext,shorttext,Math.ceil(longtext.length/2));var hm;if(!hm1&&!hm2){return null}else if(!hm2){hm=hm1}else if(!hm1){hm=hm2}else{hm=hm1[4].length>hm2[4].length?hm1:hm2}var text1_a,text1_b,text2_a,text2_b;if(text1.length>text2.length){text1_a=hm[0];text1_b=hm[1];text2_a=hm[2];text2_b=hm[3]}else{text2_a=hm[0];text2_b=hm[1];text1_a=hm[2];text1_b=hm[3]}var mid_common=hm[4];return[text1_a,text1_b,text2_a,text2_b,mid_common]};diff_match_patch.prototype.diff_cleanupSemantic=function(diffs){var changes=false;var equalities=[];var lastequality=null;var pointer=0;var length_changes1=0;var length_changes2=0;while(pointer<diffs.length){if(diffs[pointer][0]==DIFF_EQUAL){equalities.push(pointer);length_changes1=length_changes2;length_changes2=0;lastequality=diffs[pointer][1]}else{length_changes2+=diffs[pointer][1].length;if(lastequality!==null&&(lastequality.length<=length_changes1)&&(lastequality.length<=length_changes2)){diffs.splice(equalities[equalities.length-1],0,[DIFF_DELETE,lastequality]);diffs[equalities[equalities.length-1]+1][0]=DIFF_INSERT;equalities.pop();equalities.pop();pointer=equalities.length?equalities[equalities.length-1]:-1;length_changes1=0;length_changes2=0;lastequality=null;changes=true}}pointer++}if(changes){this.diff_cleanupMerge(diffs)}this.diff_cleanupSemanticLossless(diffs)};diff_match_patch.prototype.diff_cleanupSemanticLossless=function(diffs){function diff_cleanupSemanticScore(one,two,three){var whitespace=/\s/;var score=0;if(one.charAt(one.length-1).match(whitespace)||two.charAt(0).match(whitespace)){score++}if(two.charAt(two.length-1).match(whitespace)||three.charAt(0).match(whitespace)){score++}return score}var pointer=1;while(pointer<diffs.length-1){if(diffs[pointer-1][0]==DIFF_EQUAL&&diffs[pointer+1][0]==DIFF_EQUAL){var equality1=diffs[pointer-1][1];var edit=diffs[pointer][1];var equality2=diffs[pointer+1][1];var commonOffset=this.diff_commonSuffix(equality1,edit);if(commonOffset){var commonString=edit.substring(edit.length-commonOffset);equality1=equality1.substring(0,equality1.length-commonOffset);edit=commonString+edit.substring(0,edit.length-commonOffset);equality2=commonString+equality2}var bestEquality1=equality1;var bestEdit=edit;var bestEquality2=equality2;var bestScore=diff_cleanupSemanticScore(equality1,edit,equality2);while(edit.charAt(0)===equality2.charAt(0)){equality1+=edit.charAt(0);edit=edit.substring(1)+equality2.charAt(0);equality2=equality2.substring(1);var score=diff_cleanupSemanticScore(equality1,edit,equality2);if(score>=bestScore){bestScore=score;bestEquality1=equality1;bestEdit=edit;bestEquality2=equality2}}if(diffs[pointer-1][1]!=bestEquality1){diffs[pointer-1][1]=bestEquality1;diffs[pointer][1]=bestEdit;diffs[pointer+1][1]=bestEquality2}}pointer++}};diff_match_patch.prototype.diff_cleanupEfficiency=function(diffs){var changes=false;var equalities=[];var lastequality='';var pointer=0;var pre_ins=false;var pre_del=false;var post_ins=false;var post_del=false;while(pointer<diffs.length){if(diffs[pointer][0]==DIFF_EQUAL){if(diffs[pointer][1].length<this.Diff_EditCost&&(post_ins||post_del)){equalities.push(pointer);pre_ins=post_ins;pre_del=post_del;lastequality=diffs[pointer][1]}else{equalities=[];lastequality=''}post_ins=post_del=false}else{if(diffs[pointer][0]==DIFF_DELETE){post_del=true}else{post_ins=true}if(lastequality&&((pre_ins&&pre_del&&post_ins&&post_del)||((lastequality.length<this.Diff_EditCost/2)&&(pre_ins+pre_del+post_ins+post_del)==3))){diffs.splice(equalities[equalities.length-1],0,[DIFF_DELETE,lastequality]);diffs[equalities[equalities.length-1]+1][0]=DIFF_INSERT;equalities.pop();lastequality='';if(pre_ins&&pre_del){post_ins=post_del=true;equalities=[]}else{equalities.pop();pointer=equalities.length?equalities[equalities.length-1]:-1;post_ins=post_del=false}changes=true}}pointer++}if(changes){this.diff_cleanupMerge(diffs)}};diff_match_patch.prototype.diff_cleanupMerge=function(diffs){diffs.push([DIFF_EQUAL,'']);var pointer=0;var count_delete=0;var count_insert=0;var text_delete='';var text_insert='';var commonlength;while(pointer<diffs.length){if(diffs[pointer][0]==DIFF_INSERT){count_insert++;text_insert+=diffs[pointer][1];pointer++}else if(diffs[pointer][0]==DIFF_DELETE){count_delete++;text_delete+=diffs[pointer][1];pointer++}else{if(count_delete!==0||count_insert!==0){if(count_delete!==0&&count_insert!==0){commonlength=this.diff_commonPrefix(text_insert,text_delete);if(commonlength!==0){if((pointer-count_delete-count_insert)>0&&diffs[pointer-count_delete-count_insert-1][0]==DIFF_EQUAL){diffs[pointer-count_delete-count_insert-1][1]+=text_insert.substring(0,commonlength)}else{diffs.splice(0,0,[DIFF_EQUAL,text_insert.substring(0,commonlength)]);pointer++}text_insert=text_insert.substring(commonlength);text_delete=text_delete.substring(commonlength)}commonlength=this.diff_commonSuffix(text_insert,text_delete);if(commonlength!==0){diffs[pointer][1]=text_insert.substring(text_insert.length-commonlength)+diffs[pointer][1];text_insert=text_insert.substring(0,text_insert.length-commonlength);text_delete=text_delete.substring(0,text_delete.length-commonlength)}}if(count_delete===0){diffs.splice(pointer-count_delete-count_insert,count_delete+count_insert,[DIFF_INSERT,text_insert])}else if(count_insert===0){diffs.splice(pointer-count_delete-count_insert,count_delete+count_insert,[DIFF_DELETE,text_delete])}else{diffs.splice(pointer-count_delete-count_insert,count_delete+count_insert,[DIFF_DELETE,text_delete],[DIFF_INSERT,text_insert])}pointer=pointer-count_delete-count_insert+(count_delete?1:0)+(count_insert?1:0)+1}else if(pointer!==0&&diffs[pointer-1][0]==DIFF_EQUAL){diffs[pointer-1][1]+=diffs[pointer][1];diffs.splice(pointer,1)}else{pointer++}count_insert=0;count_delete=0;text_delete='';text_insert=''}}if(diffs[diffs.length-1][1]===''){diffs.pop()}var changes=false;pointer=1;while(pointer<diffs.length-1){if(diffs[pointer-1][0]==DIFF_EQUAL&&diffs[pointer+1][0]==DIFF_EQUAL){if(diffs[pointer][1].substring(diffs[pointer][1].length-diffs[pointer-1][1].length)==diffs[pointer-1][1]){diffs[pointer][1]=diffs[pointer-1][1]+diffs[pointer][1].substring(0,diffs[pointer][1].length-diffs[pointer-1][1].length);diffs[pointer+1][1]=diffs[pointer-1][1]+diffs[pointer+1][1];diffs.splice(pointer-1,1);changes=true}else if(diffs[pointer][1].substring(0,diffs[pointer+1][1].length)==diffs[pointer+1][1]){diffs[pointer-1][1]+=diffs[pointer+1][1];diffs[pointer][1]=diffs[pointer][1].substring(diffs[pointer+1][1].length)+diffs[pointer+1][1];diffs.splice(pointer+1,1);changes=true}}pointer++}if(changes){this.diff_cleanupMerge(diffs)}};diff_match_patch.prototype.diff_addIndex=function(diffs){var i=0;for(var x=0;x<diffs.length;x++){diffs[x].push(i);if(diffs[x][0]!==DIFF_DELETE){i+=diffs[x][1].length}}};diff_match_patch.prototype.diff_xIndex=function(diffs,loc){var chars1=0;var chars2=0;var last_chars1=0;var last_chars2=0;var x;for(x=0;x<diffs.length;x++){if(diffs[x][0]!==DIFF_INSERT){chars1+=diffs[x][1].length}if(diffs[x][0]!==DIFF_DELETE){chars2+=diffs[x][1].length}if(chars1>loc){break}last_chars1=chars1;last_chars2=chars2}if(diffs.length!=x&&diffs[x][0]===DIFF_DELETE){return last_chars2}return last_chars2+(loc-last_chars1)};diff_match_patch.prototype.diff_prettyHtml=function(diffs){this.diff_addIndex(diffs);var html=[];for(var x=0;x<diffs.length;x++){var m=diffs[x][0];var t=diffs[x][1];var i=diffs[x][2];t=t.replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>');t=t.replace(/\n/g,'¶<BR>');if(m===DIFF_DELETE){html.push('<DEL STYLE="background:#FFE6E6;" TITLE="i=',i,'">',t,'</DEL>')}else if(m===DIFF_INSERT){html.push('<INS STYLE="background:#E6FFE6;" TITLE="i=',i,'">',t,'</INS>')}else{html.push('<SPAN TITLE="i=',i,'">',t,'</SPAN>')}}return html.join('')};diff_match_patch.prototype.diff_text1=function(diffs){var txt=[];for(var x=0;x<diffs.length;x++){if(diffs[x][0]!==DIFF_INSERT){txt.push(diffs[x][1])}}return txt.join('')};diff_match_patch.prototype.diff_text2=function(diffs){var txt=[];for(var x=0;x<diffs.length;x++){if(diffs[x][0]!==DIFF_DELETE){txt.push(diffs[x][1])}}return txt.join('')};diff_match_patch.prototype.diff_toDelta=function(diffs){var txt=[];for(var x=0;x<diffs.length;x++){switch(diffs[x][0]){case DIFF_DELETE:txt.push('-',diffs[x][1].length,'\t');break;case DIFF_EQUAL:txt.push('=',diffs[x][1].length,'\t');break;case DIFF_INSERT:txt.push('+',encodeURI(diffs[x][1]),'\t');break;default:alert('Invalid diff operation in diff_toDelta()')}}return txt.join('').replace(/%20/g,' ')};diff_match_patch.prototype.diff_fromDelta=function(text1,delta){var diffs=[];var pointer=0;var tokens=delta.split(/\t/g);for(var x=0;x<tokens.length;x++){var param=tokens[x].substring(1);switch(tokens[x].charAt(0)){case'-':case'=':var n=parseInt(param,10);if(isNaN(n)||n<0){alert('Invalid number in diff_fromDelta()')}else{var text=text1.substring(pointer,pointer+=n);if(tokens[x].charAt(0)=='='){diffs.push([DIFF_EQUAL,text])}else{diffs.push([DIFF_DELETE,text])}}break;case'+':diffs.push([DIFF_INSERT,decodeURI(param)]);break;default:if(tokens[x]){alert('Invalid diff operation in diff_fromDelta()')}}}if(pointer!=text1.length){alert('Text length mismatch in diff_fromDelta()')}return diffs};diff_match_patch.prototype.match_main=function(text,pattern,loc){loc=Math.max(0,Math.min(loc,text.length-pattern.length));if(text==pattern){return 0}else if(text.length===0){return null}else if(text.substring(loc,loc+pattern.length)==pattern){return loc}else{return this.match_bitap(text,pattern,loc)}};diff_match_patch.prototype.match_bitap=function(text,pattern,loc){if(pattern.length>this.Match_MaxBits){return alert('Pattern too long for this browser.')}var s=this.match_alphabet(pattern);var score_text_length=text.length;score_text_length=Math.max(score_text_length,this.Match_MinLength);score_text_length=Math.min(score_text_length,this.Match_MaxLength);var dmp=this;function match_bitapScore(e,x){var d=Math.abs(loc-x);return(e/pattern.length/dmp.Match_Balance)+(d/score_text_length/(1.0-dmp.Match_Balance))}var score_threshold=this.Match_Threshold;var best_loc=text.indexOf(pattern,loc);if(best_loc!=-1){score_threshold=Math.min(match_bitapScore(0,best_loc),score_threshold)}best_loc=text.lastIndexOf(pattern,loc+pattern.length);if(best_loc!=-1){score_threshold=Math.min(match_bitapScore(0,best_loc),score_threshold)}var matchmask=1<<(pattern.length-1);best_loc=null;var bin_min,bin_mid;var bin_max=Math.max(loc+loc,text.length);var last_rd;for(var d=0;d<pattern.length;d++){var rd=Array(text.length);bin_min=loc;bin_mid=bin_max;while(bin_min<bin_mid){if(match_bitapScore(d,bin_mid)<score_threshold){bin_min=bin_mid}else{bin_max=bin_mid}bin_mid=Math.floor((bin_max-bin_min)/2+bin_min)}bin_max=bin_mid;var start=Math.max(0,loc-(bin_mid-loc)-1);var finish=Math.min(text.length-1,pattern.length+bin_mid);if(text.charAt(finish)==pattern.charAt(pattern.length-1)){rd[finish]=(1<<(d+1))-1}else{rd[finish]=(1<<d)-1}for(var j=finish-1;j>=start;j--){if(d===0){rd[j]=((rd[j+1]<<1)|1)&s[text.charAt(j)]}else{rd[j]=((rd[j+1]<<1)|1)&s[text.charAt(j)]|((last_rd[j+1]<<1)|1)|((last_rd[j]<<1)|1)|last_rd[j+1]}if(rd[j]&matchmask){var score=match_bitapScore(d,j);if(score<=score_threshold){score_threshold=score;best_loc=j;if(j>loc){start=Math.max(0,loc-(j-loc))}else{break}}}}if(match_bitapScore(d+1,loc)>score_threshold){break}last_rd=rd}return best_loc};diff_match_patch.prototype.match_alphabet=function(pattern){var s=Object();for(var i=0;i<pattern.length;i++){s[pattern.charAt(i)]=0}for(var i=0;i<pattern.length;i++){s[pattern.charAt(i)]|=1<<(pattern.length-i-1)}return s};diff_match_patch.prototype.patch_addContext=function(patch,text){var pattern=text.substring(patch.start2,patch.start2+patch.length1);var padding=0;while(text.indexOf(pattern)!=text.lastIndexOf(pattern)&&pattern.length<this.Match_MaxBits-this.Patch_Margin-this.Patch_Margin){padding+=this.Patch_Margin;pattern=text.substring(patch.start2-padding,patch.start2+patch.length1+padding)}padding+=this.Patch_Margin;var prefix=text.substring(patch.start2-padding,patch.start2);if(prefix!==''){patch.diffs.unshift([DIFF_EQUAL,prefix])}var suffix=text.substring(patch.start2+patch.length1,patch.start2+patch.length1+padding);if(suffix!==''){patch.diffs.push([DIFF_EQUAL,suffix])}patch.start1-=prefix.length;patch.start2-=prefix.length;patch.length1+=prefix.length+suffix.length;patch.length2+=prefix.length+suffix.length};diff_match_patch.prototype.patch_make=function(text1,text2,opt_diffs){var diffs;if(typeof opt_diffs!='undefined'){diffs=opt_diffs}else{diffs=this.diff_main(text1,text2,true);if(diffs.length>2){this.diff_cleanupSemantic(diffs);this.diff_cleanupEfficiency(diffs)}}if(diffs.length===0){return[]}var patches=[];var patch=new patch_obj();var char_count1=0;var char_count2=0;var prepatch_text=text1;var postpatch_text=text1;for(var x=0;x<diffs.length;x++){var diff_type=diffs[x][0];var diff_text=diffs[x][1];if(patch.diffs.length===0&&diff_type!==DIFF_EQUAL){patch.start1=char_count1;patch.start2=char_count2}if(diff_type===DIFF_INSERT){patch.diffs.push(diffs[x]);patch.length2+=diff_text.length;postpatch_text=postpatch_text.substring(0,char_count2)+diff_text+postpatch_text.substring(char_count2)}else if(diff_type===DIFF_DELETE){patch.length1+=diff_text.length;patch.diffs.push(diffs[x]);postpatch_text=postpatch_text.substring(0,char_count2)+postpatch_text.substring(char_count2+diff_text.length)}else if(diff_type===DIFF_EQUAL&&diff_text.length<=2*this.Patch_Margin&&patch.diffs.length!==0&&diffs.length!=x+1){patch.diffs.push(diffs[x]);patch.length1+=diff_text.length;patch.length2+=diff_text.length}if(diff_type===DIFF_EQUAL&&diff_text.length>=2*this.Patch_Margin){if(patch.diffs.length!==0){this.patch_addContext(patch,prepatch_text);patches.push(patch);patch=new patch_obj();prepatch_text=postpatch_text}}if(diff_type!==DIFF_INSERT){char_count1+=diff_text.length}if(diff_type!==DIFF_DELETE){char_count2+=diff_text.length}}if(patch.diffs.length!==0){this.patch_addContext(patch,prepatch_text);patches.push(patch)}return patches};diff_match_patch.prototype.patch_apply=function(patches,text){this.patch_splitMax(patches);var results=[];var delta=0;for(var x=0;x<patches.length;x++){var expected_loc=patches[x].start2+delta;var text1=this.diff_text1(patches[x].diffs);var start_loc=this.match_main(text,text1,expected_loc);if(start_loc===null){results.push(false)}else{results.push(true);delta=start_loc-expected_loc;var text2=text.substring(start_loc,start_loc+text1.length);if(text1==text2){text=text.substring(0,start_loc)+this.diff_text2(patches[x].diffs)+text.substring(start_loc+text1.length)}else{var diffs=this.diff_main(text1,text2,false);this.diff_cleanupSemanticLossless(diffs);var index1=0;var index2;for(var y=0;y<patches[x].diffs.length;y++){var mod=patches[x].diffs[y];if(mod[0]!==DIFF_EQUAL){index2=this.diff_xIndex(diffs,index1)}if(mod[0]===DIFF_INSERT){text=text.substring(0,start_loc+index2)+mod[1]+text.substring(start_loc+index2)}else if(mod[0]===DIFF_DELETE){text=text.substring(0,start_loc+index2)+text.substring(start_loc+this.diff_xIndex(diffs,index1+mod[1].length))}if(mod[0]!==DIFF_DELETE){index1+=mod[1].length}}}}}return[text,results]};diff_match_patch.prototype.patch_splitMax=function(patches){for(var x=0;x<patches.length;x++){if(patches[x].length1>this.Match_MaxBits){var bigpatch=patches[x];patches.splice(x,1);var patch_size=this.Match_MaxBits;var start1=bigpatch.start1;var start2=bigpatch.start2;var precontext='';while(bigpatch.diffs.length!==0){var patch=new patch_obj();var empty=true;patch.start1=start1-precontext.length;patch.start2=start2-precontext.length;if(precontext!==''){patch.length1=patch.length2=precontext.length;patch.diffs.push([DIFF_EQUAL,precontext])}while(bigpatch.diffs.length!==0&&patch.length1<patch_size-this.Patch_Margin){var diff_type=bigpatch.diffs[0][0];var diff_text=bigpatch.diffs[0][1];if(diff_type===DIFF_INSERT){patch.length2+=diff_text.length;start2+=diff_text.length;patch.diffs.push(bigpatch.diffs.shift());empty=false}else{diff_text=diff_text.substring(0,patch_size-patch.length1-this.Patch_Margin);patch.length1+=diff_text.length;start1+=diff_text.length;if(diff_type===DIFF_EQUAL){patch.length2+=diff_text.length;start2+=diff_text.length}else{empty=false}patch.diffs.push([diff_type,diff_text]);if(diff_text==bigpatch.diffs[0][1]){bigpatch.diffs.shift()}else{bigpatch.diffs[0][1]=bigpatch.diffs[0][1].substring(diff_text.length)}}}precontext=this.diff_text2(patch.diffs);precontext=precontext.substring(precontext.length-this.Patch_Margin);var postcontext=this.diff_text1(bigpatch.diffs).substring(0,this.Patch_Margin);if(postcontext!==''){patch.length1+=postcontext.length;patch.length2+=postcontext.length;if(patch.diffs.length!==0&&patch.diffs[patch.diffs.length-1][0]===DIFF_EQUAL){patch.diffs[patch.diffs.length-1][1]+=postcontext}else{patch.diffs.push([DIFF_EQUAL,postcontext])}}if(!empty){patches.splice(x++,0,patch)}}}}};diff_match_patch.prototype.patch_toText=function(patches){var text=[];for(var x=0;x<patches.length;x++){text.push(patches[x])}return text.join('')};diff_match_patch.prototype.patch_fromText=function(textline){var patches=[];var text=textline.split('\n');while(text.length!==0){var m=text[0].match(/^@@ -(\d+),?(\d*) \+(\d+),?(\d*) @@$/);if(!m){return alert('Invalid patch string:\n'+text[0])}var patch=new patch_obj();patches.push(patch);patch.start1=parseInt(m[1],10);if(m[2]===''){patch.start1--;patch.length1=1}else if(m[2]=='0'){patch.length1=0}else{patch.start1--;patch.length1=parseInt(m[2],10)}patch.start2=parseInt(m[3],10);if(m[4]===''){patch.start2--;patch.length2=1}else if(m[4]=='0'){patch.length2=0}else{patch.start2--;patch.length2=parseInt(m[4],10)}text.shift();while(text.length!==0){var sign=text[0].charAt(0);var line=decodeURIComponent(text[0].substring(1));if(sign=='-'){patch.diffs.push([DIFF_DELETE,line])}else if(sign=='+'){patch.diffs.push([DIFF_INSERT,line])}else if(sign==' '){patch.diffs.push([DIFF_EQUAL,line])}else if(sign=='@'){break}else if(sign===''){}else{return alert('Invalid patch mode: "'+sign+'"\n'+line)}text.shift()}}return patches};function patch_obj(){this.diffs=[];this.start1=null;this.start2=null;this.length1=0;this.length2=0}patch_obj.prototype.toString=function(){var coords1,coords2;if(this.length1===0){coords1=this.start1+',0'}else if(this.length1==1){coords1=this.start1+1}else{coords1=(this.start1+1)+','+this.length1}if(this.length2===0){coords2=this.start2+',0'}else if(this.length2==1){coords2=this.start2+1}else{coords2=(this.start2+1)+','+this.length2}var txt=['@@ -',coords1,' +',coords2,' @@\n'];for(var x=0;x<this.diffs.length;x++){switch(this.diffs[x][0]){case DIFF_DELETE:txt.push('-');break;case DIFF_EQUAL:txt.push(' ');break;case DIFF_INSERT:txt.push('+');break;default:alert('Invalid diff operation in patch_obj.toString()')}txt.push(encodeURI(this.diffs[x][1]),'\n')}return txt.join('').replace(/%20/g,' ')};
|
data/lib/js_spec/dir.rb
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
module JsSpec
|
2
|
+
class Dir < File
|
3
|
+
def locate(name)
|
4
|
+
if file = file(name)
|
5
|
+
file
|
6
|
+
else
|
7
|
+
locate_spec_runner(name)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def get
|
12
|
+
SpecDirRunner.new(self).get
|
13
|
+
end
|
14
|
+
|
15
|
+
def glob(pattern)
|
16
|
+
expanded_pattern = absolute_path + pattern
|
17
|
+
::Dir.glob(expanded_pattern).map do |absolute_globbed_path|
|
18
|
+
relative_globbed_path = absolute_globbed_path.gsub(absolute_path, relative_path)
|
19
|
+
File.new(absolute_globbed_path, relative_globbed_path)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
protected
|
24
|
+
def determine_child_paths(name)
|
25
|
+
absolute_child_path = ::File.expand_path("#{absolute_path}/#{name}")
|
26
|
+
relative_child_path = ::File.expand_path("#{relative_path}/#{name}")
|
27
|
+
[absolute_child_path, relative_child_path]
|
28
|
+
end
|
29
|
+
|
30
|
+
def locate_spec_runner(name)
|
31
|
+
if subdir = subdir(name)
|
32
|
+
subdir
|
33
|
+
elsif file = file(name + '.js')
|
34
|
+
SpecFileRunner.new(file)
|
35
|
+
else
|
36
|
+
raise "No specs found at #{relative_path}/#{name}."
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def file(name)
|
41
|
+
absolute_file_path, relative_file_path = determine_child_paths(name)
|
42
|
+
if ::File.exists?(absolute_file_path) && !::File.directory?(absolute_file_path)
|
43
|
+
JsSpec::File.new(absolute_file_path, relative_file_path)
|
44
|
+
else
|
45
|
+
nil
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def subdir(name)
|
50
|
+
absolute_dir_path, relative_dir_path = determine_child_paths(name)
|
51
|
+
if ::File.directory?(absolute_dir_path)
|
52
|
+
JsSpec::Dir.new(absolute_dir_path, relative_dir_path)
|
53
|
+
else
|
54
|
+
nil
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
data/lib/js_spec/file.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
module JsSpec
|
2
|
+
class File
|
3
|
+
MIME_TYPES = {
|
4
|
+
'.js' => 'text/javascript',
|
5
|
+
'.css' => 'text/css',
|
6
|
+
}
|
7
|
+
|
8
|
+
attr_reader :absolute_path, :relative_path
|
9
|
+
|
10
|
+
def initialize(absolute_path, relative_path)
|
11
|
+
@absolute_path = absolute_path
|
12
|
+
@relative_path = relative_path
|
13
|
+
end
|
14
|
+
|
15
|
+
def get
|
16
|
+
extension = ::File.extname(absolute_path)
|
17
|
+
Server.response.headers['Content-Type'] = MIME_TYPES[extension] || 'text/html'
|
18
|
+
::File.read(absolute_path)
|
19
|
+
end
|
20
|
+
|
21
|
+
def ==(other)
|
22
|
+
return false unless other.is_a?(File)
|
23
|
+
absolute_path == other.absolute_path && relative_path == other.relative_path
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
module JsSpec
|
2
|
+
class Server
|
3
|
+
DEFAULT_HOST = "127.0.0.1"
|
4
|
+
DEFAULT_PORT = 8080
|
5
|
+
|
6
|
+
class << self
|
7
|
+
attr_accessor :instance
|
8
|
+
|
9
|
+
def run(spec_root_path, implementation_root_path, server_options = {})
|
10
|
+
server_options[:Host] ||= DEFAULT_HOST
|
11
|
+
server_options[:Port] ||= DEFAULT_PORT
|
12
|
+
@instance = new(spec_root_path, implementation_root_path, server_options[:Host], server_options[:Port])
|
13
|
+
Rack::Handler::Mongrel.run(instance, server_options)
|
14
|
+
end
|
15
|
+
|
16
|
+
def spec_root_path; instance.spec_root_path; end
|
17
|
+
def implementation_root_path; instance.implementation_root_path; end
|
18
|
+
def core_path; instance.core_path; end
|
19
|
+
def request; instance.request; end
|
20
|
+
def response; instance.response; end
|
21
|
+
end
|
22
|
+
|
23
|
+
attr_reader :host, :port, :spec_root_path, :implementation_root_path, :core_path
|
24
|
+
|
25
|
+
def initialize(spec_root_path, implementation_root_path, host=DEFAULT_HOST, port=DEFAULT_PORT)
|
26
|
+
dir = ::File.dirname(__FILE__)
|
27
|
+
@core_path = ::File.expand_path("#{dir}/../../core")
|
28
|
+
@spec_root_path = ::File.expand_path(spec_root_path)
|
29
|
+
@implementation_root_path = ::File.expand_path(implementation_root_path)
|
30
|
+
@host = host
|
31
|
+
@port = port
|
32
|
+
end
|
33
|
+
|
34
|
+
def call(env)
|
35
|
+
self.request = Rack::Request.new(env)
|
36
|
+
self.response = Rack::Response.new
|
37
|
+
method = request.request_method.downcase.to_sym
|
38
|
+
response.body = get_resource.send(method)
|
39
|
+
response.finish
|
40
|
+
ensure
|
41
|
+
self.request = nil
|
42
|
+
self.response = nil
|
43
|
+
end
|
44
|
+
|
45
|
+
def run(path)
|
46
|
+
system(%{firefox "http://#{host}:#{port}/#{path}"})
|
47
|
+
SuiteResult.new
|
48
|
+
end
|
49
|
+
|
50
|
+
def request
|
51
|
+
Thread.current[:request]
|
52
|
+
end
|
53
|
+
|
54
|
+
def response
|
55
|
+
Thread.current[:response]
|
56
|
+
end
|
57
|
+
|
58
|
+
protected
|
59
|
+
def request=(request)
|
60
|
+
Thread.current[:request] = request
|
61
|
+
end
|
62
|
+
|
63
|
+
def response=(response)
|
64
|
+
Thread.current[:response] = response
|
65
|
+
end
|
66
|
+
|
67
|
+
def path_parts
|
68
|
+
request.path_info.split('/').reject { |part| part == "" }
|
69
|
+
end
|
70
|
+
|
71
|
+
def get_resource
|
72
|
+
path_parts.inject(WebRoot.new) do |resource, child_resource_name|
|
73
|
+
resource.locate(child_resource_name)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module JsSpec
|
2
|
+
class SpecRunner
|
3
|
+
def get
|
4
|
+
html = <<-HTML
|
5
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
|
6
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ko">
|
7
|
+
<head>
|
8
|
+
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
|
9
|
+
<title>JSSpec results</title>
|
10
|
+
<link rel="stylesheet" type="text/css" href="/core/JSSpec.css" />
|
11
|
+
<script type="text/javascript" src="/core/diff_match_patch.js"></script>
|
12
|
+
<script type="text/javascript" src="/core/JSSpec.js"></script>
|
13
|
+
<script type="text/javascript" src="/core/JSSpecExtensions.js"></script>
|
14
|
+
HTML
|
15
|
+
spec_files.each do |file|
|
16
|
+
html << %{<script type="text/javascript" src="#{file.relative_path}"></script>\n}
|
17
|
+
end
|
18
|
+
|
19
|
+
html << <<-HTML
|
20
|
+
</head>
|
21
|
+
<body></body>
|
22
|
+
</html>
|
23
|
+
HTML
|
24
|
+
html.gsub(/^ /, "")
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module JsSpec
|
2
|
+
class WebRoot
|
3
|
+
def locate(name)
|
4
|
+
case name
|
5
|
+
when 'specs'
|
6
|
+
JsSpec::Dir.new(JsSpec::Server.spec_root_path, "/specs")
|
7
|
+
when 'core'
|
8
|
+
JsSpec::Dir.new(JsSpec::Server.core_path, "/core")
|
9
|
+
when 'implementations'
|
10
|
+
JsSpec::Dir.new(JsSpec::Server.implementation_root_path, "/implementations")
|
11
|
+
when 'results'
|
12
|
+
JsSpec::SuiteResult.new
|
13
|
+
else
|
14
|
+
raise "Invalid path: #{name}"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/js_spec.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require "rack"
|
3
|
+
require "mongrel"
|
4
|
+
|
5
|
+
dir = File.dirname(__FILE__)
|
6
|
+
require "#{dir}/js_spec/server"
|
7
|
+
require "#{dir}/js_spec/spec_runner"
|
8
|
+
require "#{dir}/js_spec/spec_file_runner"
|
9
|
+
require "#{dir}/js_spec/spec_dir_runner"
|
10
|
+
require "#{dir}/js_spec/file"
|
11
|
+
require "#{dir}/js_spec/dir"
|
12
|
+
require "#{dir}/js_spec/web_root"
|
13
|
+
require "#{dir}/js_spec/suite_result"
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
dir = File.dirname(__FILE__)
|
3
|
+
$LOAD_PATH.unshift "#{dir}/../../../plugins/rspec/lib"
|
4
|
+
require "spec"
|
5
|
+
|
6
|
+
$LOAD_PATH.unshift "#{dir}/../../lib"
|
7
|
+
require "js_spec"
|
8
|
+
require "hpricot"
|
9
|
+
|
10
|
+
module Spec::Example::ExampleMethods
|
11
|
+
attr_reader :spec_root_path
|
12
|
+
before(:all) do
|
13
|
+
dir = File.dirname(__FILE__)
|
14
|
+
@spec_root_path = "#{dir}/../example_specs"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
#JsSpec::Server.run
|
data/spec/spec_suite.rb
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/unit_spec_helper")
|
2
|
+
|
3
|
+
module JsSpec
|
4
|
+
describe Dir do
|
5
|
+
attr_reader :dir, :absolute_path, :relative_path
|
6
|
+
|
7
|
+
describe "in core dir" do
|
8
|
+
before do
|
9
|
+
@absolute_path = core_path
|
10
|
+
@relative_path = "/core"
|
11
|
+
@dir = JsSpec::Dir.new(absolute_path, relative_path)
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "#locate when passed a name of a real file" do
|
15
|
+
it "returns a JsSpec::File representing it" do
|
16
|
+
file = dir.locate("JSSpec.css")
|
17
|
+
file.relative_path.should == "/core/JSSpec.css"
|
18
|
+
file.absolute_path.should == "#{core_path}/JSSpec.css"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "in specs dir" do
|
24
|
+
before do
|
25
|
+
@absolute_path = spec_root_path
|
26
|
+
@relative_path = "/specs"
|
27
|
+
@dir = JsSpec::Dir.new(absolute_path, relative_path)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "has an absolute path" do
|
31
|
+
dir.absolute_path.should == absolute_path
|
32
|
+
end
|
33
|
+
|
34
|
+
it "has a relative path" do
|
35
|
+
dir.relative_path.should == relative_path
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "#locate when passed the name with an extension" do
|
39
|
+
it "when file exists, returns a JsSpec::File representing it" do
|
40
|
+
file = dir.locate("failing_spec.js")
|
41
|
+
file.relative_path.should == "/specs/failing_spec.js"
|
42
|
+
file.absolute_path.should == "#{spec_root_path}/failing_spec.js"
|
43
|
+
end
|
44
|
+
|
45
|
+
it "when file does not exist, raises error" do
|
46
|
+
lambda { dir.locate("nonexistent.js") }.should raise_error
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "#locate when passed a name without an extension" do
|
51
|
+
it "when the name corresponds to a .js file in the directory, returns a SpecFileRunner for the file" do
|
52
|
+
file_runner = dir.locate("failing_spec")
|
53
|
+
file_runner.should be_an_instance_of(SpecFileRunner)
|
54
|
+
file_runner.file.should == spec_file("/failing_spec.js")
|
55
|
+
end
|
56
|
+
|
57
|
+
it "when name corresponds to a subdirectory, returns a DirectoryRunner for the directory" do
|
58
|
+
subdir = dir.locate("foo")
|
59
|
+
subdir.should be_an_instance_of(JsSpec::Dir)
|
60
|
+
subdir.should == spec_dir("/foo")
|
61
|
+
end
|
62
|
+
|
63
|
+
it "when name does not correspond to a .js file or directory, raises an error" do
|
64
|
+
lambda do
|
65
|
+
dir.locate("nonexistent")
|
66
|
+
end.should raise_error
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe Dir, "#glob" do
|
71
|
+
it "returns an array of matching Files under this directory with the correct relative paths" do
|
72
|
+
globbed_files = dir.glob("/**/*_spec.js")
|
73
|
+
|
74
|
+
globbed_files.size.should == 3
|
75
|
+
globbed_files.should contain_spec_file_with_correct_paths("/failing_spec.js")
|
76
|
+
globbed_files.should contain_spec_file_with_correct_paths("/foo/failing_spec.js")
|
77
|
+
globbed_files.should contain_spec_file_with_correct_paths("/foo/passing_spec.js")
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|