From cc4e8105dc5dd08beab09c31bcb59cf4d35450e6 Mon Sep 17 00:00:00 2001 From: Francesco Rodriguez Date: Wed, 23 Nov 2016 01:27:30 +0100 Subject: [PATCH] Use Puma env detection helpers in tests. (#1156) * Use Puma env detection helpers in tests. * Check only once if environment is windows. Same as #jruby? --- lib/puma/detect.rb | 4 +++- test/test_cli.rb | 2 +- test/test_minissl.rb | 2 +- test/test_puma_server_ssl.rb | 8 ++++---- test/test_unix_socket.rb | 2 +- 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/puma/detect.rb b/lib/puma/detect.rb index 578898a1..b6e67dc9 100644 --- a/lib/puma/detect.rb +++ b/lib/puma/detect.rb @@ -5,7 +5,9 @@ module Puma IS_JRUBY end + IS_WINDOWS = RUBY_PLATFORM =~ /mswin|ming|cygwin/ + def self.windows? - RUBY_PLATFORM =~ /mswin|ming|cygwin/ + IS_WINDOWS end end diff --git a/test/test_cli.rb b/test/test_cli.rb index 94c21705..128153bd 100644 --- a/test/test_cli.rb +++ b/test/test_cli.rb @@ -62,7 +62,7 @@ class TestCLI < Minitest::Test t.join end - unless defined?(JRUBY_VERSION) || RbConfig::CONFIG["host_os"] =~ /mingw|mswin/ + unless Puma.jruby? || Puma.windows? def test_control_clustered url = "unix://#{@tmp_path}" diff --git a/test/test_minissl.rb b/test/test_minissl.rb index 80acb401..b11ee722 100644 --- a/test/test_minissl.rb +++ b/test/test_minissl.rb @@ -4,7 +4,7 @@ require "puma/minissl" class TestMiniSSL < Minitest::Test - if defined?(JRUBY_VERSION) + if Puma.jruby? def test_raises_with_invalid_keystore_file ctx = Puma::MiniSSL::Context.new diff --git a/test/test_puma_server_ssl.rb b/test/test_puma_server_ssl.rb index ad32cfe6..c0d779e8 100644 --- a/test/test_puma_server_ssl.rb +++ b/test/test_puma_server_ssl.rb @@ -31,7 +31,7 @@ class TestPumaServerSSL < Minitest::Test @ctx = Puma::MiniSSL::Context.new - if defined?(JRUBY_VERSION) + if Puma.jruby? @ctx.keystore = File.expand_path "../../examples/puma/keystore.jks", __FILE__ @ctx.keystore_pass = 'blahblah' else @@ -116,7 +116,7 @@ class TestPumaServerSSL < Minitest::Test Net::HTTP::Get.new '/' end end - unless defined?(JRUBY_VERSION) + unless Puma.jruby? assert_match("wrong version number", @events.error.message) if @events.error end end @@ -133,7 +133,7 @@ class TestPumaServerSSLClient < Minitest::Test @app = lambda { |env| [200, {}, [env['rack.url_scheme']]] } @ctx = Puma::MiniSSL::Context.new - if defined?(JRUBY_VERSION) + if Puma.jruby? @ctx.keystore = File.expand_path "../../examples/puma/client-certs/keystore.jks", __FILE__ @ctx.keystore_pass = 'blahblah' else @@ -168,7 +168,7 @@ class TestPumaServerSSLClient < Minitest::Test assert_equal !!error, client_error # The JRuby MiniSSL implementation lacks error capturing currently, so we can't inspect the # messages here - unless defined?(JRUBY_VERSION) + unless Puma.jruby? assert_match error, events.error.message if error assert_equal @host, events.addr if error assert_equal subject, events.cert.subject.to_s if subject diff --git a/test/test_unix_socket.rb b/test/test_unix_socket.rb index e9de3608..fad2af6e 100644 --- a/test/test_unix_socket.rb +++ b/test/test_unix_socket.rb @@ -2,7 +2,7 @@ require "test_helper" # UNIX sockets are not recommended on JRuby # (or Windows) -unless defined?(JRUBY_VERSION) || RbConfig::CONFIG["host_os"] =~ /mingw|mswin/ +unless Puma.jruby? || Puma.windows? class TestPumaUnixSocket < Minitest::Test App = lambda { |env| [200, {}, ["Works"]] }