/
spec_helper.rb
45 lines (34 loc) · 966 Bytes
/
spec_helper.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
require 'rubygems'
require 'bundler/setup'
require 'json'
ROOT = File.expand_path("../..", __FILE__)
$LOAD_PATH.unshift(File.join(ROOT, "lib"))
require 'couchup'
# Spec stuff
require 'awesome_print'
require 'couchrest'
HOST = ENV['HOST'] || "127.0.0.1"
PORT = ENV['PORT'] || "5984"
TEST_DATABASE = 'couchup_test'
def database
@db ||= CouchRest.database!("http://#{HOST}:#{PORT}/#{TEST_DATABASE}")
end
def reset_data!
database.documents(:include_docs => true)["rows"].collect{|r| r["doc"]}.each {|d|database.delete_doc(d) unless d["_id"] =~ /_design/}
end
def ap(*params)
# no op
end
RSpec.configure do |config|
config.before(:all) do
begin
database.delete!
database.create!
Couchup::Couchup.host = HOST
Couchup::Couchup.port = PORT
Couchup::Couchup.database = TEST_DATABASE
rescue
ap "Looks like the couch db does not exist. Use HOST and or PORT env param to set the couchdb server"
end
end
end