From 9003387a00b31a5d275b387d7226f33865a9eb27 Mon Sep 17 00:00:00 2001 From: John Nunemaker Date: Sun, 15 Apr 2012 23:29:36 -0400 Subject: [PATCH] More ssl test helper cleanup. --- spec/support/ssl_test_helper.rb | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/spec/support/ssl_test_helper.rb b/spec/support/ssl_test_helper.rb index a29ab4a..d9d8577 100644 --- a/spec/support/ssl_test_helper.rb +++ b/spec/support/ssl_test_helper.rb @@ -1,29 +1,30 @@ +require 'pathname' + module HTTParty module SSLTestHelper def ssl_verify_test(mode, ca_basename, server_cert_filename) + path = Pathname(__FILE__).join('..', '..', 'fixtures', 'ssl', 'generated').expand_path options = { :format => :json, :timeout => 30, } if mode - ca_path = File.expand_path("../../fixtures/ssl/generated/#{ca_basename}", __FILE__) - raise ArgumentError.new("#{ca_path} does not exist") unless File.exist?(ca_path) + ca_path = path.join(ca_basename) + raise ArgumentError.new("#{ca_path} does not exist") unless ca_path.exist? options[mode] = ca_path end - begin - test_server = SSLTestServer.new({ - :rsa_key => File.read(File.expand_path("../../fixtures/ssl/generated/server.key", __FILE__)), - :cert => File.read(File.expand_path("../../fixtures/ssl/generated/#{server_cert_filename}", __FILE__)), - }) + test_server = SSLTestServer.new({ + :rsa_key => path.join('server.key').read, + :cert => path.join(server_cert_filename).read, + }) - test_server.start + test_server.start - HTTParty.get("https://localhost:#{test_server.port}/", options) - ensure - test_server.stop if test_server - end + HTTParty.get("https://localhost:#{test_server.port}/", options) + ensure + test_server.stop if test_server end end end