Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 160 lines (134 sloc) 4.715 kb
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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
require "rubygems"
require "spec/rake/spectask"
require "rake/rdoctask"

task :default => %w[spec:unit spec:integration]

task :dev_console do
  sh "irb -I lib -rubygems -r braintree -r env/development"
end

task :qa_console do
  sh "irb -I lib -rubygems -r braintree -r env/qa"
end

desc "Run units"
Spec::Rake::SpecTask.new("spec:unit") do |t|
  t.spec_files = FileList["spec/unit/**/*_spec.rb"]
end

desc "Run integration"
Spec::Rake::SpecTask.new("spec:integration") do |t|
  t.spec_files = FileList["spec/integration/**/*_spec.rb"]
end

desc "run integration keeping the gateway server and sphinx running"
task :start_servers_and_run_integration_specs do
  begin
    Rake::Task["start_gateway"].invoke
    Rake::Task["start_sphinx"].invoke
    Rake::Task["spec:integration"].invoke
  ensure
    Rake::Task["stop_gateway"].invoke
    Rake::Task["stop_sphinx"].invoke
  end
end

desc "run integration tests after preping the gateway (including git clone and db reset), what the build needs to run"
task :run_integration_specs_for_cruise do
  begin
    Rake::Task["prep_gateway"].invoke
    Rake::Task["spec:integration"].invoke
  ensure
    Rake::Task["stop_gateway"].invoke
    Rake::Task["stop_sphinx"].invoke
  end
end

def configure_rdoc_task(t)
  t.main = "README.rdoc"
  t.rdoc_files.include("README.rdoc", "CHANGELOG.rdoc", "LICENSE", "lib/**/*.rb")
  t.title = "Braintree Ruby Documentation"
end

Rake::RDocTask.new do |t|
  configure_rdoc_task(t)
  t.rdoc_dir = "rdoc"
end

Rake::RDocTask.new(:bt_rdoc) do |t|
  configure_rdoc_task(t)
  t.rdoc_dir = "bt_rdoc"
  t.template = "bt_rdoc_template/braintree"
end

task :bt_rdoc_postprocessing do
  FileUtils.cp "bt_rdoc_template/braintree.gif", "bt_rdoc"
  FileUtils.cp "bt_rdoc_template/ruby.png", "bt_rdoc"
  Dir.glob("bt_rdoc/**/*.html") do |html_file|
    original = File.read(html_file)
    next unless original =~ /STYLE_URL/
    base_url = original[/STYLE_URL = (.*)\/.*/, 1]
    updated = original.gsub("BASE_URL", base_url)
    File.open(html_file, "w") { |f| f.write updated }
  end
end
task(:bt_rdoc) { Rake::Task["bt_rdoc_postprocessing"].invoke }

require File.dirname(__FILE__) + "/lib/braintree/version.rb"
gem_spec = Gem::Specification.new do |s|
  s.name = "braintree"
  s.summary = "Braintree Gateway Ruby Client Library"
  s.description = "Ruby library for integrating with the Braintree Gateway"
  s.version = Braintree::Version::String
  s.author = "Braintree Payment Solutions"
  s.email = "devs@getbraintree.com"
  s.homepage = "http://www.braintreepaymentsolutions.com/gateway"
  s.rubyforge_project = "braintree"
  s.has_rdoc = false
  s.files = FileList["README.rdoc", "LICENSE", "{lib,spec}/**/*.rb", "lib/**/*.crt"]
end

task :gem do
  Gem::Builder.new(gem_spec).build
end

require File.dirname(__FILE__) + "/lib/braintree/configuration.rb"

CRUISE_BUILD = "CRUISE_BUILD=#{ENV['CRUISE_BUILD']}"
GATEWAY_ROOT = File.dirname(__FILE__) + "/../gateway" unless defined?(GATEWAY_ROOT)
Braintree::Configuration.environment = :development
PID_FILE = "/tmp/gateway_server_#{Braintree::Configuration.port}.pid"

task :prep_gateway do
  Dir.chdir(GATEWAY_ROOT) do
    sh "git pull"
    sh "env RAILS_ENV=integration #{CRUISE_BUILD} SPHINX_PORT=#{ENV['SPHINX_PORT']} rake db:migrate:reset --trace"
    sh "env RAILS_ENV=integration #{CRUISE_BUILD} SPHINX_PORT=#{ENV['SPHINX_PORT']} ruby script/populate_data"
    Rake::Task[:start_gateway].invoke
    Rake::Task[:start_sphinx].invoke
  end
end

task :start_gateway do
  Dir.chdir(GATEWAY_ROOT) do
    spawn_server(PID_FILE, Braintree::Configuration.port, "integration")
  end
end

task :start_sphinx do
  Dir.chdir(GATEWAY_ROOT) do
    sh "env RAILS_ENV=integration #{CRUISE_BUILD} SPHINX_PORT=#{ENV['SPHINX_PORT']} rake ts:rebuild --trace"
  end
end

task :stop_gateway do
  Dir.chdir(GATEWAY_ROOT) do
    shutdown_server(PID_FILE)
  end
end

task :stop_sphinx do
  Dir.chdir(GATEWAY_ROOT) do
    sh "env RAILS_ENV=integration rake ts:stop --trace"
  end
end

desc 'Cleans generated files'
task :clean do
  rm_f Dir.glob('*.gem').join(" ")
  rm_rf "bt_rdoc"
  rm_rf "rdoc"
end

def spawn_server(pid_file, port, environment="test")
  require File.dirname(__FILE__) + "/spec/hacks/tcp_socket"

  FileUtils.rm(pid_file) if File.exist?(pid_file)
  command = "mongrel_rails start --environment #{environment} --daemon --port #{port} --pid #{pid_file}"

  sh command
  puts "== waiting for web server - port: #{port}"
  TCPSocket.wait_for_service :host => "127.0.0.1", :port => port
end

def shutdown_server(pid_file)
  10.times { unless File.exists?(pid_file); sleep 1; end }
  puts "\n== killing web server - pid: #{File.read(pid_file).to_i}"
  Process.kill "TERM", File.read(pid_file).to_i
end
Something went wrong with that request. Please try again.