Skip to content

Instantly share code, notes, and snippets.

@thomo
Created August 12, 2010 08:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thomo/520596 to your computer and use it in GitHub Desktop.
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.
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