spec/spec_helper.rb in etcd-0.2.0.alpha vs spec/spec_helper.rb in etcd-0.2.0.beta.1

- old
+ new

@@ -1,50 +1,49 @@ # encoding: utf-8 -$:.unshift(File.expand_path("../lib", __FILE__)) -$:.unshift(File.expand_path("../spec", __FILE__)) +$LOAD_PATH.unshift(File.expand_path('../lib', __FILE__)) +$LOAD_PATH.unshift(File.expand_path('../spec', __FILE__)) require 'coco' require 'uuid' require 'etcd' module Etcd module SpecHelper - @@pids = [] def self.etcd_binary - if File.exists? './etcd/etcd' - './etcd/etcd' - elsif !! ENV['ETCD_BIN'] + if File.exists? './etcd/bin/etcd' + './etcd/bin/etcd' + elsif !!ENV['ETCD_BIN'] ENV['ETCD_BIN'] else - raise 'etcd binary not found., you need to set ETCD_BIN' + fail 'etcd binary not found., you need to set ETCD_BIN' end end def self.start_etcd_servers @@tmpdir = Dir.mktmpdir - pid = spawn_etcd_server(@@tmpdir+'/leader') + pid = spawn_etcd_server(@@tmpdir + '/leader') @@pids = Array(pid) leader = '127.0.0.1:7001' 4.times do |n| client_port = 4002 + n server_port = 7002 + n - pid = spawn_etcd_server(@@tmpdir+client_port.to_s, client_port, server_port, leader) + pid = spawn_etcd_server(@@tmpdir + client_port.to_s, client_port, server_port, leader) @@pids << pid end end def self.stop_etcd_servers @@pids.each do |pid| - Process.kill("TERM", pid) + Process.kill('TERM', pid) end FileUtils.remove_entry_secure(@@tmpdir, true) end - def self.spawn_etcd_server(dir, client_port=4001, server_port=7001, leader = nil) + def self.spawn_etcd_server(dir, client_port = 4001, server_port = 7001, leader = nil) args = " -addr 127.0.0.1:#{client_port} -peer-addr 127.0.0.1:#{server_port} -data-dir #{dir} -name node_#{client_port}" command = if leader.nil? etcd_binary + args else etcd_binary + args + " -peers #{leader}" @@ -57,28 +56,28 @@ def uuid @uuid ||= UUID.new end - def random_key(n=1) - key='' + def random_key(n = 1) + key = '' n.times do - key << '/'+ uuid.generate + key << '/' + uuid.generate end key end def etcd_servers - (1..5).map{|n| "http://127.0.0.1:700#{n}"} + (1..5).map { |n| "http://127.0.0.1:700#{n}" } end def other_client Etcd.client end def read_only_client - Etcd.client(:allow_redirect=>false, :port=> 4004) + Etcd.client(allow_redirect: false, port: 4004) end end end RSpec.configure do |c| @@ -89,6 +88,5 @@ end c.after(:suite) do Etcd::SpecHelper.stop_etcd_servers end end -