Created
August 12, 2010 08:50
-
-
Save thomo/520596 to your computer and use it in GitHub Desktop.
Environment file for cucumber + couchapp. Use test db defined in .couchapprc for feature run.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'culerity' | |
require 'cucumber/formatter/unicode' | |
require 'restclient' | |
require 'couchrest' | |
def read_couchapprc | |
json = "" | |
File.open(File.join(APP_PATH, ".couchapprc")).each { |line| json << line } | |
JSON.parse(json) | |
end | |
def app_dir | |
APP_PATH.split(File.PATH_SEPARATOR).reverse[0] | |
end | |
def get_design_doc_id | |
id = "" | |
File.open(File.join(APP_PATH, "_id")).each { |line| id << line } | |
id.chomp! | |
id.empty? ? "_design/#{app_dir}" : id | |
end | |
def init_from_couchapprc | |
couchapprc = read_couchapprc | |
uri = URI.parse(couchapprc["env"]["test"]["db"] || "http://localhost:5984/hejhej") | |
cfg = {} | |
cfg[:host] = "http://#{uri.host}:#{uri.port}" | |
cfg[:database] = uri.path.sub("/","") | |
cfg | |
end | |
def host | |
$config[:host] | |
end | |
def database | |
$config[:database] | |
end | |
def design_doc_id | |
$config[:design_doc_id] | |
end | |
Before do | |
$config = init_from_couchapprc | |
$config[:design_doc_id] = get_design_doc_id | |
RestClient.delete "#{host}/#{database}" rescue nil | |
RestClient.put "#{host}/#{database}", "" | |
system "couchapp push . #{host}/#{database} 2> /dev/null" | |
@couch_db = CouchRest.database!("#{host}/#{database}") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment