spacialdb 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,582 @@
1
+ # Copyright 2011 Keith Rarick
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in
11
+ # all copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ # THE SOFTWARE.
20
+
21
+ # See https://github.com/kr/okjson for updates.
22
+
23
+ require 'stringio'
24
+
25
+ # Some parts adapted from
26
+ # http://golang.org/src/pkg/json/decode.go and
27
+ # http://golang.org/src/pkg/utf8/utf8.go
28
+ module OkJson
29
+ extend self
30
+
31
+ class ParserError < ::StandardError; end
32
+
33
+ # Decodes a json document in string s and
34
+ # returns the corresponding ruby value.
35
+ # String s must be valid UTF-8. If you have
36
+ # a string in some other encoding, convert
37
+ # it first.
38
+ #
39
+ # String values in the resulting structure
40
+ # will be UTF-8.
41
+ def decode(s)
42
+ ts = lex(s)
43
+ v, ts = textparse(ts)
44
+ if ts.length > 0
45
+ raise Error, 'trailing garbage'
46
+ end
47
+ v
48
+ end
49
+
50
+
51
+ # Parses a "json text" in the sense of RFC 4627.
52
+ # Returns the parsed value and any trailing tokens.
53
+ # Note: this is almost the same as valparse,
54
+ # except that it does not accept atomic values.
55
+ def textparse(ts)
56
+ if ts.length < 0
57
+ raise Error, 'empty'
58
+ end
59
+
60
+ typ, _, val = ts[0]
61
+ case typ
62
+ when '{' then objparse(ts)
63
+ when '[' then arrparse(ts)
64
+ else
65
+ raise Error, "unexpected #{val.inspect}"
66
+ end
67
+ end
68
+
69
+
70
+ # Parses a "value" in the sense of RFC 4627.
71
+ # Returns the parsed value and any trailing tokens.
72
+ def valparse(ts)
73
+ if ts.length < 0
74
+ raise Error, 'empty'
75
+ end
76
+
77
+ typ, _, val = ts[0]
78
+ case typ
79
+ when '{' then objparse(ts)
80
+ when '[' then arrparse(ts)
81
+ when :val,:str then [val, ts[1..-1]]
82
+ else
83
+ raise Error, "unexpected #{val.inspect}"
84
+ end
85
+ end
86
+
87
+
88
+ # Parses an "object" in the sense of RFC 4627.
89
+ # Returns the parsed value and any trailing tokens.
90
+ def objparse(ts)
91
+ ts = eat('{', ts)
92
+ obj = {}
93
+
94
+ if ts[0][0] == '}'
95
+ return obj, ts[1..-1]
96
+ end
97
+
98
+ k, v, ts = pairparse(ts)
99
+ obj[k] = v
100
+
101
+ if ts[0][0] == '}'
102
+ return obj, ts[1..-1]
103
+ end
104
+
105
+ loop do
106
+ ts = eat(',', ts)
107
+
108
+ k, v, ts = pairparse(ts)
109
+ obj[k] = v
110
+
111
+ if ts[0][0] == '}'
112
+ return obj, ts[1..-1]
113
+ end
114
+ end
115
+ end
116
+
117
+
118
+ # Parses a "member" in the sense of RFC 4627.
119
+ # Returns the parsed values and any trailing tokens.
120
+ def pairparse(ts)
121
+ (typ, _, k), ts = ts[0], ts[1..-1]
122
+ if typ != :str
123
+ raise Error, "unexpected #{k.inspect}"
124
+ end
125
+ ts = eat(':', ts)
126
+ v, ts = valparse(ts)
127
+ [k, v, ts]
128
+ end
129
+
130
+
131
+ # Parses an "array" in the sense of RFC 4627.
132
+ # Returns the parsed value and any trailing tokens.
133
+ def arrparse(ts)
134
+ ts = eat('[', ts)
135
+ arr = []
136
+
137
+ if ts[0][0] == ']'
138
+ return arr, ts[1..-1]
139
+ end
140
+
141
+ v, ts = valparse(ts)
142
+ arr << v
143
+
144
+ if ts[0][0] == ']'
145
+ return arr, ts[1..-1]
146
+ end
147
+
148
+ loop do
149
+ ts = eat(',', ts)
150
+
151
+ v, ts = valparse(ts)
152
+ arr << v
153
+
154
+ if ts[0][0] == ']'
155
+ return arr, ts[1..-1]
156
+ end
157
+ end
158
+ end
159
+
160
+
161
+ def eat(typ, ts)
162
+ if ts[0][0] != typ
163
+ raise Error, "expected #{typ} (got #{ts[0].inspect})"
164
+ end
165
+ ts[1..-1]
166
+ end
167
+
168
+
169
+ # Sans s and returns a list of json tokens,
170
+ # excluding white space (as defined in RFC 4627).
171
+ def lex(s)
172
+ ts = []
173
+ while s.length > 0
174
+ typ, lexeme, val = tok(s)
175
+ if typ == nil
176
+ raise Error, "invalid character at #{s[0,10].inspect}"
177
+ end
178
+ if typ != :space
179
+ ts << [typ, lexeme, val]
180
+ end
181
+ s = s[lexeme.length..-1]
182
+ end
183
+ ts
184
+ end
185
+
186
+
187
+ # Scans the first token in s and
188
+ # returns a 3-element list, or nil
189
+ # if no such token exists.
190
+ #
191
+ # The first list element is one of
192
+ # '{', '}', ':', ',', '[', ']',
193
+ # :val, :str, and :space.
194
+ #
195
+ # The second element is the lexeme.
196
+ #
197
+ # The third element is the value of the
198
+ # token for :val and :str, otherwise
199
+ # it is the lexeme.
200
+ def tok(s)
201
+ case s[0]
202
+ when ?{ then ['{', s[0,1], s[0,1]]
203
+ when ?} then ['}', s[0,1], s[0,1]]
204
+ when ?: then [':', s[0,1], s[0,1]]
205
+ when ?, then [',', s[0,1], s[0,1]]
206
+ when ?[ then ['[', s[0,1], s[0,1]]
207
+ when ?] then [']', s[0,1], s[0,1]]
208
+ when ?n then nulltok(s)
209
+ when ?t then truetok(s)
210
+ when ?f then falsetok(s)
211
+ when ?" then strtok(s)
212
+ when Spc then [:space, s[0,1], s[0,1]]
213
+ when ?\t then [:space, s[0,1], s[0,1]]
214
+ when ?\n then [:space, s[0,1], s[0,1]]
215
+ when ?\r then [:space, s[0,1], s[0,1]]
216
+ else numtok(s)
217
+ end
218
+ end
219
+
220
+
221
+ def nulltok(s); s[0,4] == 'null' && [:val, 'null', nil] end
222
+ def truetok(s); s[0,4] == 'true' && [:val, 'true', true] end
223
+ def falsetok(s); s[0,5] == 'false' && [:val, 'false', false] end
224
+
225
+
226
+ def numtok(s)
227
+ m = /-?([1-9][0-9]+|[0-9])([.][0-9]+)?([eE][+-]?[0-9]+)?/.match(s)
228
+ if m && m.begin(0) == 0
229
+ if m[3] && !m[2]
230
+ [:val, m[0], Integer(m[1])*(10**Integer(m[3][1..-1]))]
231
+ elsif m[2]
232
+ [:val, m[0], Float(m[0])]
233
+ else
234
+ [:val, m[0], Integer(m[0])]
235
+ end
236
+ end
237
+ end
238
+
239
+
240
+ def strtok(s)
241
+ m = /"([^"\\]|\\["\/\\bfnrt]|\\u[0-9a-fA-F]{4})*"/.match(s)
242
+ if ! m
243
+ raise Error, "invalid string literal at #{abbrev(s)}"
244
+ end
245
+ [:str, m[0], unquote(m[0])]
246
+ end
247
+
248
+
249
+ def abbrev(s)
250
+ t = s[0,10]
251
+ p = t['`']
252
+ t = t[0,p] if p
253
+ t = t + '...' if t.length < s.length
254
+ '`' + t + '`'
255
+ end
256
+
257
+
258
+ # Converts a quoted json string literal q into a UTF-8-encoded string.
259
+ # The rules are different than for Ruby, so we cannot use eval.
260
+ # Unquote will raise an error if q contains control characters.
261
+ def unquote(q)
262
+ q = q[1...-1]
263
+ a = q.dup # allocate a big enough string
264
+ r, w = 0, 0
265
+ while r < q.length
266
+ c = q[r]
267
+ case true
268
+ when c == ?\\
269
+ r += 1
270
+ if r >= q.length
271
+ raise Error, "string literal ends with a \"\\\": \"#{q}\""
272
+ end
273
+
274
+ case q[r]
275
+ when ?",?\\,?/,?'
276
+ a[w] = q[r]
277
+ r += 1
278
+ w += 1
279
+ when ?b,?f,?n,?r,?t
280
+ a[w] = Unesc[q[r]]
281
+ r += 1
282
+ w += 1
283
+ when ?u
284
+ r += 1
285
+ uchar = begin
286
+ hexdec4(q[r,4])
287
+ rescue RuntimeError => e
288
+ raise Error, "invalid escape sequence \\u#{q[r,4]}: #{e}"
289
+ end
290
+ r += 4
291
+ if surrogate? uchar
292
+ if q.length >= r+6
293
+ uchar1 = hexdec4(q[r+2,4])
294
+ uchar = subst(uchar, uchar1)
295
+ if uchar != Ucharerr
296
+ # A valid pair; consume.
297
+ r += 6
298
+ end
299
+ end
300
+ end
301
+ w += ucharenc(a, w, uchar)
302
+ else
303
+ raise Error, "invalid escape char #{q[r]} in \"#{q}\""
304
+ end
305
+ when c == ?", c < Spc
306
+ raise Error, "invalid character in string literal \"#{q}\""
307
+ else
308
+ # Copy anything else byte-for-byte.
309
+ # Valid UTF-8 will remain valid UTF-8.
310
+ # Invalid UTF-8 will remain invalid UTF-8.
311
+ a[w] = c
312
+ r += 1
313
+ w += 1
314
+ end
315
+ end
316
+ a[0,w]
317
+ end
318
+
319
+
320
+ # Encodes unicode character u as UTF-8
321
+ # bytes in string a at position i.
322
+ # Returns the number of bytes written.
323
+ def ucharenc(a, i, u)
324
+ case true
325
+ when u <= Uchar1max
326
+ a[i] = (u & 0xff).chr
327
+ 1
328
+ when u <= Uchar2max
329
+ a[i+0] = (Utag2 | ((u>>6)&0xff)).chr
330
+ a[i+1] = (Utagx | (u&Umaskx)).chr
331
+ 2
332
+ when u <= Uchar3max
333
+ a[i+0] = (Utag3 | ((u>>12)&0xff)).chr
334
+ a[i+1] = (Utagx | ((u>>6)&Umaskx)).chr
335
+ a[i+2] = (Utagx | (u&Umaskx)).chr
336
+ 3
337
+ else
338
+ a[i+0] = (Utag4 | ((u>>18)&0xff)).chr
339
+ a[i+1] = (Utagx | ((u>>12)&Umaskx)).chr
340
+ a[i+2] = (Utagx | ((u>>6)&Umaskx)).chr
341
+ a[i+3] = (Utagx | (u&Umaskx)).chr
342
+ 4
343
+ end
344
+ end
345
+
346
+
347
+ def hexdec4(s)
348
+ if s.length != 4
349
+ raise Error, 'short'
350
+ end
351
+ (nibble(s[0])<<12) | (nibble(s[1])<<8) | (nibble(s[2])<<4) | nibble(s[3])
352
+ end
353
+
354
+
355
+ def subst(u1, u2)
356
+ if Usurr1 <= u1 && u1 < Usurr2 && Usurr2 <= u2 && u2 < Usurr3
357
+ return ((u1-Usurr1)<<10) | (u2-Usurr2) + Usurrself
358
+ end
359
+ return Ucharerr
360
+ end
361
+
362
+
363
+ def unsubst(u)
364
+ if u < Usurrself || u > Umax || surrogate?(u)
365
+ return Ucharerr, Ucharerr
366
+ end
367
+ u -= Usurrself
368
+ [Usurr1 + ((u>>10)&0x3ff), Usurr2 + (u&0x3ff)]
369
+ end
370
+
371
+
372
+ def surrogate?(u)
373
+ Usurr1 <= u && u < Usurr3
374
+ end
375
+
376
+
377
+ def nibble(c)
378
+ case true
379
+ when ?0 <= c && c <= ?9 then c.ord - ?0.ord
380
+ when ?a <= c && c <= ?z then c.ord - ?a.ord + 10
381
+ when ?A <= c && c <= ?Z then c.ord - ?A.ord + 10
382
+ else
383
+ raise Error, "invalid hex code #{c}"
384
+ end
385
+ end
386
+
387
+
388
+ # Encodes x into a json text. It may contain only
389
+ # Array, Hash, String, Numeric, true, false, nil.
390
+ # (Note, this list excludes Symbol.)
391
+ # X itself must be an Array or a Hash.
392
+ # No other value can be encoded, and an error will
393
+ # be raised if x contains any other value, such as
394
+ # Nan, Infinity, Symbol, and Proc, or if a Hash key
395
+ # is not a String.
396
+ # Strings contained in x must be valid UTF-8.
397
+ def encode(x)
398
+ case x
399
+ when Hash then objenc(x)
400
+ when Array then arrenc(x)
401
+ else
402
+ raise Error, 'root value must be an Array or a Hash'
403
+ end
404
+ end
405
+
406
+
407
+ def valenc(x)
408
+ case x
409
+ when Hash then objenc(x)
410
+ when Array then arrenc(x)
411
+ when String then strenc(x)
412
+ when Numeric then numenc(x)
413
+ when true then "true"
414
+ when false then "false"
415
+ when nil then "null"
416
+ else
417
+ raise Error, "cannot encode #{x.class}: #{x.inspect}"
418
+ end
419
+ end
420
+
421
+
422
+ def objenc(x)
423
+ '{' + x.map{|k,v| keyenc(k) + ':' + valenc(v)}.join(',') + '}'
424
+ end
425
+
426
+
427
+ def arrenc(a)
428
+ '[' + a.map{|x| valenc(x)}.join(',') + ']'
429
+ end
430
+
431
+
432
+ def keyenc(k)
433
+ case k
434
+ when String then strenc(k)
435
+ else
436
+ raise Error, "Hash key is not a string: #{k.inspect}"
437
+ end
438
+ end
439
+
440
+
441
+ def strenc(s)
442
+ t = StringIO.new
443
+ t.putc(?")
444
+ r = 0
445
+ while r < s.length
446
+ case s[r]
447
+ when ?" then t.print('\\"')
448
+ when ?\\ then t.print('\\\\')
449
+ when ?\b then t.print('\\b')
450
+ when ?\f then t.print('\\f')
451
+ when ?\n then t.print('\\n')
452
+ when ?\r then t.print('\\r')
453
+ when ?\t then t.print('\\t')
454
+ else
455
+ c = s[r]
456
+ case true
457
+ when Spc <= c && c <= ?~
458
+ t.putc(c)
459
+ when true
460
+ u, size = uchardec(s, r)
461
+ r += size - 1 # we add one more at the bottom of the loop
462
+ if u < 0x10000
463
+ t.print('\\u')
464
+ hexenc4(t, u)
465
+ else
466
+ u1, u2 = unsubst(u)
467
+ t.print('\\u')
468
+ hexenc4(t, u1)
469
+ t.print('\\u')
470
+ hexenc4(t, u2)
471
+ end
472
+ else
473
+ # invalid byte; skip it
474
+ end
475
+ end
476
+ r += 1
477
+ end
478
+ t.putc(?")
479
+ t.string
480
+ end
481
+
482
+
483
+ def hexenc4(t, u)
484
+ t.putc(Hex[(u>>12)&0xf])
485
+ t.putc(Hex[(u>>8)&0xf])
486
+ t.putc(Hex[(u>>4)&0xf])
487
+ t.putc(Hex[u&0xf])
488
+ end
489
+
490
+
491
+ def numenc(x)
492
+ if x.nan? || x.infinite?
493
+ return 'null'
494
+ end rescue nil
495
+ "#{x}"
496
+ end
497
+
498
+
499
+ # Decodes unicode character u from UTF-8
500
+ # bytes in string s at position i.
501
+ # Returns u and the number of bytes read.
502
+ def uchardec(s, i)
503
+ n = s.length - i
504
+ return [Ucharerr, 1] if n < 1
505
+
506
+ c0 = s[i].ord
507
+
508
+ # 1-byte, 7-bit sequence?
509
+ if c0 < Utagx
510
+ return [c0, 1]
511
+ end
512
+
513
+ # unexpected continuation byte?
514
+ return [Ucharerr, 1] if c0 < Utag2
515
+
516
+ # need continuation byte
517
+ return [Ucharerr, 1] if n < 2
518
+ c1 = s[i+1].ord
519
+ return [Ucharerr, 1] if c1 < Utagx || Utag2 <= c1
520
+
521
+ # 2-byte, 11-bit sequence?
522
+ if c0 < Utag3
523
+ u = (c0&Umask2)<<6 | (c1&Umaskx)
524
+ return [Ucharerr, 1] if u <= Uchar1max
525
+ return [u, 2]
526
+ end
527
+
528
+ # need second continuation byte
529
+ return [Ucharerr, 1] if n < 3
530
+ c2 = s[i+2].ord
531
+ return [Ucharerr, 1] if c2 < Utagx || Utag2 <= c2
532
+
533
+ # 3-byte, 16-bit sequence?
534
+ if c0 < Utag4
535
+ u = (c0&Umask3)<<12 | (c1&Umaskx)<<6 | (c2&Umaskx)
536
+ return [Ucharerr, 1] if u <= Uchar2max
537
+ return [u, 3]
538
+ end
539
+
540
+ # need third continuation byte
541
+ return [Ucharerr, 1] if n < 4
542
+ c3 = s[i+3].ord
543
+ return [Ucharerr, 1] if c3 < Utagx || Utag2 <= c3
544
+
545
+ # 4-byte, 21-bit sequence?
546
+ if c0 < Utag5
547
+ u = (c0&Umask4)<<18 | (c1&Umaskx)<<12 | (c2&Umaskx)<<6 | (c3&Umaskx)
548
+ return [Ucharerr, 1] if u <= Uchar3max
549
+ return [u, 4]
550
+ end
551
+
552
+ return [Ucharerr, 1]
553
+ end
554
+
555
+
556
+ class Error < ::StandardError
557
+ end
558
+
559
+
560
+ Utagx = 0x80 # 1000 0000
561
+ Utag2 = 0xc0 # 1100 0000
562
+ Utag3 = 0xe0 # 1110 0000
563
+ Utag4 = 0xf0 # 1111 0000
564
+ Utag5 = 0xF8 # 1111 1000
565
+ Umaskx = 0x3f # 0011 1111
566
+ Umask2 = 0x1f # 0001 1111
567
+ Umask3 = 0x0f # 0000 1111
568
+ Umask4 = 0x07 # 0000 0111
569
+ Uchar1max = (1<<7) - 1
570
+ Uchar2max = (1<<11) - 1
571
+ Uchar3max = (1<<16) - 1
572
+ Ucharerr = 0xFFFD # unicode "replacement char"
573
+ Usurrself = 0x10000
574
+ Usurr1 = 0xd800
575
+ Usurr2 = 0xdc00
576
+ Usurr3 = 0xe000
577
+ Umax = 0x10ffff
578
+
579
+ Spc = ' '[0]
580
+ Unesc = {?b=>?\b, ?f=>?\f, ?n=>?\n, ?r=>?\r, ?t=>?\t}
581
+ Hex = '0123456789abcdef'
582
+ end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+ require 'spacialdb/client'
3
+ require "spacialdb/helpers"
4
+
5
+ describe Spacialdb::Client do
6
+ include Spacialdb::Helpers
7
+
8
+ before do
9
+ @client = Spacialdb::Client.new(nil, nil)
10
+ end
11
+
12
+ it 'Client.auth -> get user details' do
13
+ user_info = {"private_api_key"=>"abc", "email"=>"abc@de.com"}
14
+ stub_request(:get, 'http://foo:bar@beta.spacialdb.com/api/users/credentials').to_return(:body => json_encode(user_info))
15
+ Spacialdb::Client.auth('foo', 'bar').should == user_info
16
+ end
17
+
18
+ it 'Client.create -> create a new database' do
19
+ database_info = { 'host'=>'localhost',
20
+ 'name'=>'spacialdb0_john',
21
+ 'password'=>'b1641e3943',
22
+ 'username'=>'john',
23
+ 'port'=>5432 }
24
+ stub_api_request(:post, '/api/databases').to_return(:status => 200, :body => database_info)
25
+ @client.create.should == database_info
26
+ end
27
+
28
+ it 'Client.destroy(name) -> destroy the named database' do
29
+ stub_api_request(:delete, "/api/databases/spacialdb0_john")
30
+ @client.destroy("spacialdb0_john")
31
+ end
32
+ end
@@ -0,0 +1,27 @@
1
+ require "spec_helper"
2
+ require "spacialdb/command/db"
3
+
4
+ module Spacialdb::Command
5
+ describe Db do
6
+ before(:each) do
7
+ @cli = prepare_command(Db)
8
+ # @cli.stub(:options).and_return(:db => "mydb")
9
+ end
10
+
11
+ it "destroys the db specified with --db if user confirms" do
12
+ Spacialdb::Client.stub!(:auth).and_return({'email' => 'foo', 'private_api_key' => 'bar'})
13
+ @cli.stub!(:options).and_return(:db => "mydb")
14
+ @cli.should_receive(:confirm_command).with("mydb").and_return(true)
15
+ @cli.spacialdb.should_receive(:destroy).with('mydb')
16
+ @cli.destroy
17
+ end
18
+
19
+ it "doesn't destroy the db if the user doesn't confirms" do
20
+ Spacialdb::Client.stub!(:auth).and_return({'email' => 'foo', 'private_api_key' => 'bar'})
21
+ @cli.stub!(:options).and_return(:db => "mydb")
22
+ @cli.should_receive(:confirm_command).with("mydb").and_return(false)
23
+ @cli.spacialdb.should_not_receive(:destroy).with('mydb')
24
+ @cli.destroy
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,15 @@
1
+ require "spec_helper"
2
+ require "spacialdb/command/version"
3
+
4
+ module Spacialdb::Command
5
+ describe Version do
6
+ before do
7
+ @version = prepare_command(Version)
8
+ end
9
+
10
+ it "shows the gems version" do
11
+ @version.should_receive(:display).with(Spacialdb::Client.gem_version_string)
12
+ @version.index
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,12 @@
1
+ require "spec_helper"
2
+ require "spacialdb/command"
3
+
4
+ describe Spacialdb::Command do
5
+ it "correctly resolves commands" do
6
+ require "spacialdb/command/help"
7
+ require "spacialdb/command/db"
8
+
9
+ Spacialdb::Command.parse("unknown").should be_nil
10
+ Spacialdb::Command.parse("list").should include(:klass => Spacialdb::Command::Db, :method => :index)
11
+ end
12
+ end
@@ -0,0 +1,28 @@
1
+ require 'rubygems'
2
+ require "bundler/setup"
3
+
4
+ require 'rspec'
5
+ require "webmock/rspec"
6
+
7
+ include WebMock::API
8
+
9
+ def stub_api_request(method, path)
10
+ stub_request(method, "http://beta.spacialdb.com#{path}")
11
+ end
12
+
13
+ def prepare_command(klass)
14
+ command = klass.new
15
+ command.stub!(:ask).and_return("")
16
+ command.stub!(:display)
17
+ command.stub!(:spacialdb).and_return(mock('spacialdb client', :host => 'beta.spacialdb.com'))
18
+ command
19
+ end
20
+
21
+ module Spacialdb::Helpers
22
+ def display(msg, newline=true)
23
+ end
24
+ end
25
+
26
+ Rspec.configure do |config|
27
+ config.color_enabled = true
28
+ end