ichabod 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +11 -2
- data/Rakefile +2 -22
- data/VERSION +1 -0
- data/examples/qunit/index.html +20 -0
- data/examples/qunit/klass.js +52 -0
- data/examples/qunit/lib/qunit.css +205 -0
- data/examples/qunit/lib/qunit.js +1428 -0
- data/examples/qunit/model.js +206 -0
- data/examples/qunit/model.test.js +45 -0
- data/ichabod.gemspec +62 -0
- data/lib/ichabod/version.rb +1 -1
- data/lib/js/jasmine.js +0 -1
- data/lib/js/qunit.js +21 -5
- metadata +11 -3
@@ -0,0 +1,206 @@
|
|
1
|
+
Math.guid = function(){
|
2
|
+
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
|
3
|
+
var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
|
4
|
+
return v.toString(16);
|
5
|
+
}).toUpperCase();
|
6
|
+
};
|
7
|
+
|
8
|
+
var Model = Klass.create();
|
9
|
+
|
10
|
+
// Alias create
|
11
|
+
Model.setup = Model.create;
|
12
|
+
|
13
|
+
Model.extend({
|
14
|
+
init: function(){
|
15
|
+
this.records = {};
|
16
|
+
this.attributes = [];
|
17
|
+
},
|
18
|
+
|
19
|
+
find: function(id){
|
20
|
+
var record = this.records[id];
|
21
|
+
if ( !record ) throw("Unknown record");
|
22
|
+
return record.dup();
|
23
|
+
},
|
24
|
+
|
25
|
+
exists: function(id){
|
26
|
+
try {
|
27
|
+
return this.find(id);
|
28
|
+
} catch (e) {
|
29
|
+
return false;
|
30
|
+
}
|
31
|
+
},
|
32
|
+
|
33
|
+
populate: function(values){
|
34
|
+
// Reset model & records
|
35
|
+
this.init();
|
36
|
+
|
37
|
+
for (var i=0, il = values.length; i < il; i++) {
|
38
|
+
var record = this.inst(values[i]);
|
39
|
+
record.newRecord = false;
|
40
|
+
this.records[record.id] = record;
|
41
|
+
}
|
42
|
+
},
|
43
|
+
|
44
|
+
select: function(callback){
|
45
|
+
var result = [];
|
46
|
+
|
47
|
+
for (var key in this.records)
|
48
|
+
if (callback(this.records[key]))
|
49
|
+
result.push(this.records[key]);
|
50
|
+
|
51
|
+
return this.dupArray(result);
|
52
|
+
},
|
53
|
+
|
54
|
+
findByAttribute: function(name, value){
|
55
|
+
for (var key in this.records)
|
56
|
+
if (this.records[key][name] == value)
|
57
|
+
return this.records[key].dup();
|
58
|
+
},
|
59
|
+
|
60
|
+
findAllByAttribute: function(name, value){
|
61
|
+
return(this.select(function(item){
|
62
|
+
return(item[name] == value);
|
63
|
+
}));
|
64
|
+
},
|
65
|
+
|
66
|
+
each: function(callback){
|
67
|
+
for (var key in this.records) {
|
68
|
+
callback(this.records[key]);
|
69
|
+
}
|
70
|
+
},
|
71
|
+
|
72
|
+
all: function(){
|
73
|
+
return this.dupArray(this.recordsValues());
|
74
|
+
},
|
75
|
+
|
76
|
+
first: function(){
|
77
|
+
var record = this.recordsValues()[0];
|
78
|
+
return(record && record.dup());
|
79
|
+
},
|
80
|
+
|
81
|
+
last: function(){
|
82
|
+
var values = this.recordsValues()
|
83
|
+
var record = values[values.length - 1];
|
84
|
+
return(record && record.dup());
|
85
|
+
},
|
86
|
+
|
87
|
+
count: function(){
|
88
|
+
return this.recordsValues().length;
|
89
|
+
},
|
90
|
+
|
91
|
+
deleteAll: function(){
|
92
|
+
for (var key in this.records)
|
93
|
+
delete this.records[key];
|
94
|
+
},
|
95
|
+
|
96
|
+
destroyAll: function(){
|
97
|
+
for (var key in this.records)
|
98
|
+
this.records[key].destroy();
|
99
|
+
},
|
100
|
+
|
101
|
+
update: function(id, atts){
|
102
|
+
this.find(id).updateAttributes(atts);
|
103
|
+
},
|
104
|
+
|
105
|
+
create: function(atts){
|
106
|
+
var record = this.inst(atts);
|
107
|
+
record.save();
|
108
|
+
return record;
|
109
|
+
},
|
110
|
+
|
111
|
+
destroy: function(id){
|
112
|
+
this.find(id).destroy();
|
113
|
+
},
|
114
|
+
|
115
|
+
// Private
|
116
|
+
|
117
|
+
recordsValues: function(){
|
118
|
+
var result = []
|
119
|
+
for (var key in this.records)
|
120
|
+
result.push(this.records[key])
|
121
|
+
return result;
|
122
|
+
},
|
123
|
+
|
124
|
+
dupArray: function(array){
|
125
|
+
return array.map(function(item){
|
126
|
+
return item.dup();
|
127
|
+
});
|
128
|
+
}
|
129
|
+
});
|
130
|
+
|
131
|
+
Model.include({
|
132
|
+
newRecord: true,
|
133
|
+
|
134
|
+
init: function(atts){
|
135
|
+
if (atts) this.load(atts);
|
136
|
+
},
|
137
|
+
|
138
|
+
isNew: function(){
|
139
|
+
return this.newRecord;
|
140
|
+
},
|
141
|
+
|
142
|
+
validate: function(){ },
|
143
|
+
|
144
|
+
load: function(attributes){
|
145
|
+
for(var name in attributes)
|
146
|
+
this[name] = attributes[name];
|
147
|
+
},
|
148
|
+
|
149
|
+
attributes: function(){
|
150
|
+
var result = {};
|
151
|
+
for(var i in this.parent.attributes) {
|
152
|
+
var attr = this.parent.attributes[i];
|
153
|
+
result[attr] = this[attr];
|
154
|
+
}
|
155
|
+
result.id = this.id;
|
156
|
+
return result;
|
157
|
+
},
|
158
|
+
|
159
|
+
eql: function(rec){
|
160
|
+
return(rec && rec.id === this.id &&
|
161
|
+
rec.parent === this.parent);
|
162
|
+
},
|
163
|
+
|
164
|
+
save: function(){
|
165
|
+
if (this.validate() == false) return false;
|
166
|
+
this.newRecord ? this.create() : this.update();
|
167
|
+
},
|
168
|
+
|
169
|
+
updateAttribute: function(name, value){
|
170
|
+
this[name] = value;
|
171
|
+
return this.save();
|
172
|
+
},
|
173
|
+
|
174
|
+
updateAttributes: function(attributes){
|
175
|
+
this.load(attributes);
|
176
|
+
return this.save();
|
177
|
+
},
|
178
|
+
|
179
|
+
destroy: function(){
|
180
|
+
delete this.parent.records[this.id];
|
181
|
+
},
|
182
|
+
|
183
|
+
dup: function(){
|
184
|
+
return Object.create(this);
|
185
|
+
},
|
186
|
+
|
187
|
+
toJSON: function(){
|
188
|
+
return(JSON.stringify(this.attributes()));
|
189
|
+
},
|
190
|
+
|
191
|
+
// Private
|
192
|
+
|
193
|
+
update: function(){
|
194
|
+
this.parent.records[this.id] = this.dup();
|
195
|
+
},
|
196
|
+
|
197
|
+
generateID: function(){
|
198
|
+
return Math.guid();
|
199
|
+
},
|
200
|
+
|
201
|
+
create: function(){
|
202
|
+
if ( !this.id ) this.id = this.generateID();
|
203
|
+
this.newRecord = false;
|
204
|
+
this.parent.records[this.id] = this.dup();
|
205
|
+
}
|
206
|
+
});
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module("Model test", {
|
2
|
+
setup: function(){
|
3
|
+
this.Asset = Model.setup();
|
4
|
+
}
|
5
|
+
});
|
6
|
+
|
7
|
+
test("load()", function(){
|
8
|
+
var a = this.Asset.inst();
|
9
|
+
a.load({
|
10
|
+
local: true,
|
11
|
+
name: "test.pdf"
|
12
|
+
});
|
13
|
+
|
14
|
+
ok(a.local, "Load sets properties");
|
15
|
+
equals(a.name, "test.pdf", "load() sets properties (2)");
|
16
|
+
|
17
|
+
var b = this.Asset.inst({
|
18
|
+
name: "test2.pdf"
|
19
|
+
});
|
20
|
+
|
21
|
+
equals(b.name, "test2.pdf", "Calls load() on instantiation");
|
22
|
+
});
|
23
|
+
|
24
|
+
test("attributes()", function(){
|
25
|
+
this.Asset.attributes = ["name"];
|
26
|
+
|
27
|
+
var a = this.Asset.inst();
|
28
|
+
a.name = "test.pdf";
|
29
|
+
a.id = 1;
|
30
|
+
|
31
|
+
same(a.attributes(), {
|
32
|
+
name: "test.pdf",
|
33
|
+
id: 1
|
34
|
+
});
|
35
|
+
});
|
36
|
+
|
37
|
+
test("find()", function(){
|
38
|
+
var a = this.Asset.create();
|
39
|
+
|
40
|
+
equals(this.Asset.find(a.id).id, a.id, "Returns saved assets");
|
41
|
+
|
42
|
+
raises(function(){
|
43
|
+
this.Asset.find("non-existant-id");
|
44
|
+
}, "Raises when Asset doesn't exist");
|
45
|
+
});
|
data/ichabod.gemspec
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{ichabod}
|
8
|
+
s.version = "0.0.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Alex MacCaw"]
|
12
|
+
s.date = %q{2011-03-15}
|
13
|
+
s.default_executable = %q{ichabod}
|
14
|
+
s.email = %q{info@eribium.org}
|
15
|
+
s.executables = ["ichabod"]
|
16
|
+
s.extra_rdoc_files = [
|
17
|
+
"README.md"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
"MIT-LICENSE",
|
21
|
+
"README.md",
|
22
|
+
"Rakefile",
|
23
|
+
"VERSION",
|
24
|
+
"bin/ichabod",
|
25
|
+
"examples/index.html",
|
26
|
+
"examples/jasmine/index.html",
|
27
|
+
"examples/jasmine/klass.js",
|
28
|
+
"examples/jasmine/lib/MIT.LICENSE",
|
29
|
+
"examples/jasmine/lib/jasmine-html.js",
|
30
|
+
"examples/jasmine/lib/jasmine.css",
|
31
|
+
"examples/jasmine/lib/jasmine.js",
|
32
|
+
"examples/jasmine/model.js",
|
33
|
+
"examples/jasmine/model.spec.js",
|
34
|
+
"lib/ichabod.rb",
|
35
|
+
"lib/ichabod/coercion.rb",
|
36
|
+
"lib/ichabod/delegate/load.rb",
|
37
|
+
"lib/ichabod/delegate/ui.rb",
|
38
|
+
"lib/ichabod/repl.rb",
|
39
|
+
"lib/ichabod/runtime.rb",
|
40
|
+
"lib/ichabod/script_object/ichabod.rb",
|
41
|
+
"lib/ichabod/script_object/ruby.rb",
|
42
|
+
"lib/ichabod/tests.rb",
|
43
|
+
"lib/ichabod/version.rb",
|
44
|
+
"lib/js/jasmine.js",
|
45
|
+
"lib/js/qunit.js"
|
46
|
+
]
|
47
|
+
s.homepage = %q{http://github.com/maccman/ichabod}
|
48
|
+
s.licenses = ["MIT"]
|
49
|
+
s.require_paths = ["lib"]
|
50
|
+
s.rubygems_version = %q{1.6.0}
|
51
|
+
s.summary = %q{Ichabod allows headless JavaScript testing using WebKit from the command line.}
|
52
|
+
|
53
|
+
if s.respond_to? :specification_version then
|
54
|
+
s.specification_version = 3
|
55
|
+
|
56
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
57
|
+
else
|
58
|
+
end
|
59
|
+
else
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
data/lib/ichabod/version.rb
CHANGED
data/lib/js/jasmine.js
CHANGED
data/lib/js/qunit.js
CHANGED
@@ -1,10 +1,26 @@
|
|
1
1
|
window.addEventListener("load", function(){
|
2
|
+
var ansi = {
|
3
|
+
green: '\033[32m',
|
4
|
+
red: '\033[31m',
|
5
|
+
yellow: '\033[33m',
|
6
|
+
none: '\033[0m'
|
7
|
+
};
|
8
|
+
|
9
|
+
var puts = function(str){
|
10
|
+
Ruby.puts(str);
|
11
|
+
};
|
12
|
+
|
13
|
+
var print = function(str){
|
14
|
+
Ruby.print(str);
|
15
|
+
};
|
16
|
+
|
2
17
|
QUnit.testDone = function(result){
|
3
|
-
|
18
|
+
puts("Results for: " + result.name);
|
19
|
+
print(ansi.red + result.failed + " failed, " + ansi.none);
|
20
|
+
print(ansi.green + result.passed + " passed, " + ansi.none);
|
21
|
+
print("Total " + result.total);
|
22
|
+
puts("");
|
23
|
+
|
4
24
|
Ichabod.exit();
|
5
|
-
// result.name
|
6
|
-
// result.failed
|
7
|
-
// result.passed
|
8
|
-
// result.total
|
9
25
|
};
|
10
26
|
});
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: ichabod
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Alex MacCaw
|
@@ -14,7 +14,7 @@ date: 2011-03-15 00:00:00 +13:00
|
|
14
14
|
default_executable: ichabod
|
15
15
|
dependencies: []
|
16
16
|
|
17
|
-
description:
|
17
|
+
description:
|
18
18
|
email: info@eribium.org
|
19
19
|
executables:
|
20
20
|
- ichabod
|
@@ -26,6 +26,7 @@ files:
|
|
26
26
|
- MIT-LICENSE
|
27
27
|
- README.md
|
28
28
|
- Rakefile
|
29
|
+
- VERSION
|
29
30
|
- bin/ichabod
|
30
31
|
- examples/index.html
|
31
32
|
- examples/jasmine/index.html
|
@@ -36,6 +37,13 @@ files:
|
|
36
37
|
- examples/jasmine/lib/jasmine.js
|
37
38
|
- examples/jasmine/model.js
|
38
39
|
- examples/jasmine/model.spec.js
|
40
|
+
- examples/qunit/index.html
|
41
|
+
- examples/qunit/klass.js
|
42
|
+
- examples/qunit/lib/qunit.css
|
43
|
+
- examples/qunit/lib/qunit.js
|
44
|
+
- examples/qunit/model.js
|
45
|
+
- examples/qunit/model.test.js
|
46
|
+
- ichabod.gemspec
|
39
47
|
- lib/ichabod.rb
|
40
48
|
- lib/ichabod/coercion.rb
|
41
49
|
- lib/ichabod/delegate/load.rb
|
@@ -75,6 +83,6 @@ rubyforge_project:
|
|
75
83
|
rubygems_version: 1.6.0
|
76
84
|
signing_key:
|
77
85
|
specification_version: 3
|
78
|
-
summary: Ichabod
|
86
|
+
summary: Ichabod allows headless JavaScript testing using WebKit from the command line.
|
79
87
|
test_files: []
|
80
88
|
|