set_builder 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/MIT-LICENSE +20 -0
- data/README.md +35 -0
- data/Rakefile +14 -0
- data/assets/javascripts/array.js +100 -0
- data/assets/javascripts/set_builder.js +415 -0
- data/init.rb +1 -0
- data/install.rb +1 -0
- data/lib/set_builder.rb +58 -0
- data/lib/set_builder/constraint.rb +67 -0
- data/lib/set_builder/modifier.rb +134 -0
- data/lib/set_builder/modifier/adverb.rb +11 -0
- data/lib/set_builder/modifier/base.rb +105 -0
- data/lib/set_builder/modifier/verb.rb +24 -0
- data/lib/set_builder/modifier_collection.rb +41 -0
- data/lib/set_builder/modifiers.rb +3 -0
- data/lib/set_builder/modifiers/date_modifier.rb +83 -0
- data/lib/set_builder/modifiers/number_modifier.rb +48 -0
- data/lib/set_builder/modifiers/string_modifier.rb +81 -0
- data/lib/set_builder/query_builders/string.rb +0 -0
- data/lib/set_builder/set.rb +81 -0
- data/lib/set_builder/trait.rb +74 -0
- data/lib/set_builder/traits.rb +42 -0
- data/lib/set_builder/value_map.rb +62 -0
- data/lib/set_builder/version.rb +3 -0
- data/set_builder.gemspec +25 -0
- data/spec/commands/example_command.rb +19 -0
- data/spec/dom.html +24 -0
- data/spec/lib/images/bg.png +0 -0
- data/spec/lib/images/hr.png +0 -0
- data/spec/lib/images/loading.gif +0 -0
- data/spec/lib/images/sprites.bg.png +0 -0
- data/spec/lib/images/sprites.png +0 -0
- data/spec/lib/images/vr.png +0 -0
- data/spec/lib/jspec.css +149 -0
- data/spec/lib/jspec.growl.js +115 -0
- data/spec/lib/jspec.jquery.js +88 -0
- data/spec/lib/jspec.js +1908 -0
- data/spec/lib/jspec.nodejs.js +18 -0
- data/spec/lib/jspec.shell.js +39 -0
- data/spec/lib/jspec.timers.js +154 -0
- data/spec/lib/jspec.xhr.js +210 -0
- data/spec/node.js +10 -0
- data/spec/rhino.js +10 -0
- data/spec/server.html +18 -0
- data/spec/server.rb +4 -0
- data/spec/unit/array.spec.js +82 -0
- data/spec/unit/set_builder.spec.js +166 -0
- data/spec/unit/spec.helper.js +0 -0
- data/test/date_modifier_test.rb +13 -0
- data/test/inflector_test.rb +27 -0
- data/test/modifier_test.rb +90 -0
- data/test/set_test.rb +96 -0
- data/test/test_helper.rb +79 -0
- data/test/trait_test.rb +49 -0
- data/test/traits_test.rb +41 -0
- data/test/value_map_test.rb +30 -0
- data/uninstall.rb +1 -0
- metadata +191 -0
@@ -0,0 +1,18 @@
|
|
1
|
+
|
2
|
+
// JSpec - node - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)
|
3
|
+
|
4
|
+
JSpec
|
5
|
+
.include({
|
6
|
+
name: 'node',
|
7
|
+
|
8
|
+
// --- Matchers
|
9
|
+
|
10
|
+
matchers : {
|
11
|
+
have_enumerable_property: 'actual.propertyIsEnumerable(expected)',
|
12
|
+
have_writable_property: 'Object.getOwnPropertyDescriptor(actual, expected).writable === true',
|
13
|
+
have_configurable_property: 'Object.getOwnPropertyDescriptor(actual, expected).configurable === true',
|
14
|
+
have_keys: 'does(Object.keys(actual), "eql", expected)',
|
15
|
+
have_prototype: 'Object.getPrototypeOf(actual) === expected'
|
16
|
+
}
|
17
|
+
})
|
18
|
+
|
@@ -0,0 +1,39 @@
|
|
1
|
+
|
2
|
+
// JSpec - Shell - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)
|
3
|
+
|
4
|
+
;(function(){
|
5
|
+
|
6
|
+
var _quit = quit
|
7
|
+
|
8
|
+
Shell = {
|
9
|
+
|
10
|
+
// --- Global
|
11
|
+
|
12
|
+
main: this,
|
13
|
+
|
14
|
+
// --- Commands
|
15
|
+
|
16
|
+
commands: {
|
17
|
+
quit: ['Terminate the shell', function(){ _quit() }],
|
18
|
+
exit: ['Terminate the shell', function(){ _quit() }],
|
19
|
+
p: ['Inspect an object', function(o){ return o.toSource() }]
|
20
|
+
},
|
21
|
+
|
22
|
+
/**
|
23
|
+
* Start the interactive shell.
|
24
|
+
*
|
25
|
+
* @api public
|
26
|
+
*/
|
27
|
+
|
28
|
+
start : function() {
|
29
|
+
for (var name in this.commands)
|
30
|
+
if (this.commands.hasOwnProperty(name))
|
31
|
+
this.commands[name][1].length ?
|
32
|
+
this.main[name] = this.commands[name][1] :
|
33
|
+
this.main.__defineGetter__(name, this.commands[name][1])
|
34
|
+
}
|
35
|
+
}
|
36
|
+
|
37
|
+
Shell.start()
|
38
|
+
|
39
|
+
})()
|
@@ -0,0 +1,154 @@
|
|
1
|
+
|
2
|
+
// Mock Timers - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)
|
3
|
+
|
4
|
+
;(function(){
|
5
|
+
|
6
|
+
/**
|
7
|
+
* Localized timer stack.
|
8
|
+
*/
|
9
|
+
var timers = [];
|
10
|
+
|
11
|
+
// nodejs, rhino don't have a window object
|
12
|
+
var global = this;
|
13
|
+
|
14
|
+
// if they where mocked before this library is loaded - bad luck
|
15
|
+
var savedGlobals = {
|
16
|
+
setTimeout: global.setTimeout,
|
17
|
+
setInterval: global.setInterval,
|
18
|
+
clearInterval: global.clearInterval,
|
19
|
+
clearTimeout: global.clearTimeout,
|
20
|
+
|
21
|
+
// those should not be globals, but are mocked none the less, so we save them
|
22
|
+
resetTimers: global.resetTimers,
|
23
|
+
tick: global.tick
|
24
|
+
};
|
25
|
+
var hadResetTimers = 'resetTimers' in global;
|
26
|
+
var hadTick = 'tick' in global;
|
27
|
+
|
28
|
+
function forEachProperty(anObject, aClosure) {
|
29
|
+
for (var key in anObject) {
|
30
|
+
if ( ! anObject.hasOwnProperty(key))
|
31
|
+
continue;
|
32
|
+
|
33
|
+
aClosure(key, anObject[key]);
|
34
|
+
}
|
35
|
+
}
|
36
|
+
|
37
|
+
global.MockTimers = {
|
38
|
+
|
39
|
+
mockTimersVersion: '2.0.0',
|
40
|
+
|
41
|
+
mockGlobalTimerFunctions: function() {
|
42
|
+
forEachProperty(this.mocks, function(aName, aFunction) {
|
43
|
+
global[aName] = aFunction;
|
44
|
+
});
|
45
|
+
},
|
46
|
+
|
47
|
+
unmockGlobalTimerFunctions: function() {
|
48
|
+
forEachProperty(this.savedGlobals, function(aName, aFunction) {
|
49
|
+
global[aName] = aFunction;
|
50
|
+
});
|
51
|
+
|
52
|
+
if ( ! hadResetTimers)
|
53
|
+
delete global['resetTimers'];
|
54
|
+
if ( ! hadTick)
|
55
|
+
delete global['tick'];
|
56
|
+
|
57
|
+
}
|
58
|
+
};
|
59
|
+
|
60
|
+
function clearTimer(id) {
|
61
|
+
return delete timers[--id];
|
62
|
+
}
|
63
|
+
|
64
|
+
var mocks = {
|
65
|
+
|
66
|
+
/**
|
67
|
+
* Set mock timeout with _callback_ and timeout of _ms_.
|
68
|
+
*
|
69
|
+
* @param {function} callback
|
70
|
+
* @param {int} ms
|
71
|
+
* @return {int}
|
72
|
+
* @api public
|
73
|
+
*/
|
74
|
+
setTimeout: function(callback, ms) {
|
75
|
+
var id;
|
76
|
+
return id = setInterval(function(){
|
77
|
+
callback();
|
78
|
+
clearInterval(id);
|
79
|
+
}, ms);
|
80
|
+
},
|
81
|
+
|
82
|
+
|
83
|
+
/**
|
84
|
+
* Set mock interval with _callback_ and interval of _ms_.
|
85
|
+
*
|
86
|
+
* @param {function} callback
|
87
|
+
* @param {int} ms
|
88
|
+
* @return {int}
|
89
|
+
* @api public
|
90
|
+
*/
|
91
|
+
setInterval: function(callback, ms) {
|
92
|
+
// REFACT: use wrapper object so callback is not changed -> state leak
|
93
|
+
callback.step = ms;
|
94
|
+
callback.current = callback.last = 0;
|
95
|
+
timers[timers.length] = callback;
|
96
|
+
return timers.length;
|
97
|
+
},
|
98
|
+
|
99
|
+
/**
|
100
|
+
* Destroy timer with _id_.
|
101
|
+
*
|
102
|
+
* @param {int} id
|
103
|
+
* @return {bool}
|
104
|
+
* @api public
|
105
|
+
*/
|
106
|
+
clearInterval: clearTimer,
|
107
|
+
clearTimeout: clearTimer
|
108
|
+
};
|
109
|
+
|
110
|
+
// additional functions that are not originally in the global namespace
|
111
|
+
/**
|
112
|
+
* Reset timers.
|
113
|
+
*
|
114
|
+
* @return {array}
|
115
|
+
* @api public
|
116
|
+
*/
|
117
|
+
mocks.resetTimers = function() {
|
118
|
+
return timers = [];
|
119
|
+
};
|
120
|
+
|
121
|
+
/**
|
122
|
+
* Increment each timers internal clock by _ms_.
|
123
|
+
*
|
124
|
+
* @param {int} ms
|
125
|
+
* @api public
|
126
|
+
*/
|
127
|
+
mocks.tick = function(ms) {
|
128
|
+
for (var i = 0, len = timers.length; i < len; ++i) {
|
129
|
+
if ( ! timers[i] || ! (timers[i].current += ms))
|
130
|
+
continue;
|
131
|
+
|
132
|
+
if (timers[i].current - timers[i].last < timers[i].step)
|
133
|
+
continue;
|
134
|
+
|
135
|
+
var times = Math.floor((timers[i].current - timers[i].last) / timers[i].step);
|
136
|
+
var remainder = (timers[i].current - timers[i].last) % timers[i].step;
|
137
|
+
timers[i].last = timers[i].current - remainder;
|
138
|
+
while (times-- && timers[i])
|
139
|
+
timers[i]();
|
140
|
+
}
|
141
|
+
};
|
142
|
+
|
143
|
+
// make them available publicly
|
144
|
+
MockTimers.mocks = mocks;
|
145
|
+
|
146
|
+
JSpec.include({
|
147
|
+
beforeSpec: function(){
|
148
|
+
MockTimers.mockGlobalTimerFunctions();
|
149
|
+
},
|
150
|
+
afterSpec : function() {
|
151
|
+
MockTimers.unmockGlobalTimerFunctions();
|
152
|
+
}
|
153
|
+
});
|
154
|
+
})();
|
@@ -0,0 +1,210 @@
|
|
1
|
+
|
2
|
+
// JSpec - XHR - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)
|
3
|
+
|
4
|
+
(function(){
|
5
|
+
|
6
|
+
var lastRequest
|
7
|
+
|
8
|
+
// --- Original XMLHttpRequest
|
9
|
+
|
10
|
+
var OriginalXMLHttpRequest = 'XMLHttpRequest' in this ?
|
11
|
+
XMLHttpRequest :
|
12
|
+
function(){}
|
13
|
+
var OriginalActiveXObject = 'ActiveXObject' in this ?
|
14
|
+
ActiveXObject :
|
15
|
+
undefined
|
16
|
+
|
17
|
+
// --- MockXMLHttpRequest
|
18
|
+
|
19
|
+
var MockXMLHttpRequest = function() {
|
20
|
+
this.requestHeaders = {}
|
21
|
+
}
|
22
|
+
|
23
|
+
MockXMLHttpRequest.prototype = {
|
24
|
+
status: 0,
|
25
|
+
async: true,
|
26
|
+
readyState: 0,
|
27
|
+
responseXML: null,
|
28
|
+
responseText: '',
|
29
|
+
abort: function(){},
|
30
|
+
onreadystatechange: function(){},
|
31
|
+
|
32
|
+
/**
|
33
|
+
* Return response headers hash.
|
34
|
+
*/
|
35
|
+
|
36
|
+
getAllResponseHeaders : function(){
|
37
|
+
return JSpec.inject(this.responseHeaders, '', function(buf, key, val){
|
38
|
+
return buf + key + ': ' + val + '\r\n'
|
39
|
+
})
|
40
|
+
},
|
41
|
+
|
42
|
+
/**
|
43
|
+
* Return case-insensitive value for header _name_.
|
44
|
+
*/
|
45
|
+
|
46
|
+
getResponseHeader : function(name) {
|
47
|
+
return this.responseHeaders[name.toLowerCase()]
|
48
|
+
},
|
49
|
+
|
50
|
+
/**
|
51
|
+
* Set case-insensitive _value_ for header _name_.
|
52
|
+
*/
|
53
|
+
|
54
|
+
setRequestHeader : function(name, value) {
|
55
|
+
this.requestHeaders[name.toLowerCase()] = value
|
56
|
+
},
|
57
|
+
|
58
|
+
/**
|
59
|
+
* Open mock request.
|
60
|
+
*/
|
61
|
+
|
62
|
+
open : function(method, url, async, user, password) {
|
63
|
+
this.user = user
|
64
|
+
this.password = password
|
65
|
+
this.url = url
|
66
|
+
this.readyState = 1
|
67
|
+
this.method = method.toUpperCase()
|
68
|
+
if (async != undefined) this.async = async
|
69
|
+
if (this.async) this.onreadystatechange()
|
70
|
+
},
|
71
|
+
|
72
|
+
/**
|
73
|
+
* Send request _data_.
|
74
|
+
*/
|
75
|
+
|
76
|
+
send : function(data) {
|
77
|
+
var self = this
|
78
|
+
this.data = data
|
79
|
+
this.readyState = 4
|
80
|
+
if (this.method == 'HEAD') this.responseText = null
|
81
|
+
this.responseHeaders['content-length'] = (this.responseText || '').length
|
82
|
+
if(this.async) this.onreadystatechange()
|
83
|
+
this.populateResponseXML()
|
84
|
+
lastRequest = function(){
|
85
|
+
return self
|
86
|
+
}
|
87
|
+
},
|
88
|
+
|
89
|
+
/**
|
90
|
+
* Parse request body and populate responseXML if response-type is xml
|
91
|
+
* Based on the standard specification : http://www.w3.org/TR/XMLHttpRequest/
|
92
|
+
*/
|
93
|
+
populateResponseXML: function() {
|
94
|
+
var type = this.getResponseHeader("content-type")
|
95
|
+
if (!type || !this.responseText || !type.match(/(text\/xml|application\/xml|\+xml$)/g))
|
96
|
+
return
|
97
|
+
this.responseXML = JSpec.parseXML(this.responseText)
|
98
|
+
}
|
99
|
+
}
|
100
|
+
|
101
|
+
// --- Response status codes
|
102
|
+
|
103
|
+
JSpec.statusCodes = {
|
104
|
+
100: 'Continue',
|
105
|
+
101: 'Switching Protocols',
|
106
|
+
200: 'OK',
|
107
|
+
201: 'Created',
|
108
|
+
202: 'Accepted',
|
109
|
+
203: 'Non-Authoritative Information',
|
110
|
+
204: 'No Content',
|
111
|
+
205: 'Reset Content',
|
112
|
+
206: 'Partial Content',
|
113
|
+
300: 'Multiple Choice',
|
114
|
+
301: 'Moved Permanently',
|
115
|
+
302: 'Found',
|
116
|
+
303: 'See Other',
|
117
|
+
304: 'Not Modified',
|
118
|
+
305: 'Use Proxy',
|
119
|
+
307: 'Temporary Redirect',
|
120
|
+
400: 'Bad Request',
|
121
|
+
401: 'Unauthorized',
|
122
|
+
402: 'Payment Required',
|
123
|
+
403: 'Forbidden',
|
124
|
+
404: 'Not Found',
|
125
|
+
405: 'Method Not Allowed',
|
126
|
+
406: 'Not Acceptable',
|
127
|
+
407: 'Proxy Authentication Required',
|
128
|
+
408: 'Request Timeout',
|
129
|
+
409: 'Conflict',
|
130
|
+
410: 'Gone',
|
131
|
+
411: 'Length Required',
|
132
|
+
412: 'Precondition Failed',
|
133
|
+
413: 'Request Entity Too Large',
|
134
|
+
414: 'Request-URI Too Long',
|
135
|
+
415: 'Unsupported Media Type',
|
136
|
+
416: 'Requested Range Not Satisfiable',
|
137
|
+
417: 'Expectation Failed',
|
138
|
+
422: 'Unprocessable Entity',
|
139
|
+
500: 'Internal Server Error',
|
140
|
+
501: 'Not Implemented',
|
141
|
+
502: 'Bad Gateway',
|
142
|
+
503: 'Service Unavailable',
|
143
|
+
504: 'Gateway Timeout',
|
144
|
+
505: 'HTTP Version Not Supported'
|
145
|
+
}
|
146
|
+
|
147
|
+
/**
|
148
|
+
* Mock XMLHttpRequest requests.
|
149
|
+
*
|
150
|
+
* mockRequest().and_return('some data', 'text/plain', 200, { 'X-SomeHeader' : 'somevalue' })
|
151
|
+
*
|
152
|
+
* @return {hash}
|
153
|
+
* @api public
|
154
|
+
*/
|
155
|
+
|
156
|
+
function mockRequest() {
|
157
|
+
return { and_return : function(body, type, status, headers) {
|
158
|
+
XMLHttpRequest = MockXMLHttpRequest
|
159
|
+
ActiveXObject = false
|
160
|
+
status = status || 200
|
161
|
+
headers = headers || {}
|
162
|
+
headers['content-type'] = type
|
163
|
+
JSpec.extend(XMLHttpRequest.prototype, {
|
164
|
+
responseText: body,
|
165
|
+
responseHeaders: headers,
|
166
|
+
status: status,
|
167
|
+
statusText: JSpec.statusCodes[status]
|
168
|
+
})
|
169
|
+
}}
|
170
|
+
}
|
171
|
+
|
172
|
+
/**
|
173
|
+
* Unmock XMLHttpRequest requests.
|
174
|
+
*
|
175
|
+
* @api public
|
176
|
+
*/
|
177
|
+
|
178
|
+
function unmockRequest() {
|
179
|
+
XMLHttpRequest = OriginalXMLHttpRequest
|
180
|
+
ActiveXObject = OriginalActiveXObject
|
181
|
+
}
|
182
|
+
|
183
|
+
JSpec.include({
|
184
|
+
name: 'Mock XHR',
|
185
|
+
|
186
|
+
// --- Utilities
|
187
|
+
|
188
|
+
utilities : {
|
189
|
+
mockRequest: mockRequest,
|
190
|
+
unmockRequest: unmockRequest
|
191
|
+
},
|
192
|
+
|
193
|
+
// --- Hooks
|
194
|
+
|
195
|
+
afterSpec : function() {
|
196
|
+
unmockRequest()
|
197
|
+
},
|
198
|
+
|
199
|
+
// --- DSLs
|
200
|
+
|
201
|
+
DSLs : {
|
202
|
+
snake : {
|
203
|
+
mock_request: mockRequest,
|
204
|
+
unmock_request: unmockRequest,
|
205
|
+
last_request: function(){ return lastRequest() }
|
206
|
+
}
|
207
|
+
}
|
208
|
+
|
209
|
+
})
|
210
|
+
})()
|
data/spec/node.js
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
|
2
|
+
require.paths.unshift('spec', './spec/lib', 'lib')
|
3
|
+
require('jspec')
|
4
|
+
require('unit/spec.helper')
|
5
|
+
require('yourlib')
|
6
|
+
|
7
|
+
JSpec
|
8
|
+
.exec('spec/unit/spec.js')
|
9
|
+
.run({ reporter: JSpec.reporters.Terminal, fixturePath: 'spec/fixtures', failuresOnly: true })
|
10
|
+
.report()
|
data/spec/rhino.js
ADDED