From 2662c17bad70fc324e473d3957db224bc64879fc Mon Sep 17 00:00:00 2001 From: Ryan Lue Date: Wed, 9 May 2018 18:26:17 +0800 Subject: [PATCH] Avoid running websocket server spec on Travis (lacks IPv6 support) --- spec/scripts/websocket_server_spec.rb | 5 +++-- spec/support/script_helper.rb | 11 +++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 spec/support/script_helper.rb diff --git a/spec/scripts/websocket_server_spec.rb b/spec/scripts/websocket_server_spec.rb index b9ffc4c66..1aa57a1df 100644 --- a/spec/scripts/websocket_server_spec.rb +++ b/spec/scripts/websocket_server_spec.rb @@ -1,7 +1,8 @@ require 'spec_helper' +require 'support/script_helper' require 'timeout' -describe 'websocket-server' do +describe 'websocket-server', type: :script do # Why not Rails.root.join here? # Because it's not avaialable in this spec (no 'rails_helper' = faster start-up) let(:app_root) { File.expand_path('../..', __dir__) } @@ -10,7 +11,7 @@ describe 'websocket-server' do let(:output_log) { File.expand_path('log/websocket-server_out.log', app_root) } let(:error_log) { File.expand_path('log/websocket-server_err.log', app_root) } - context 'with IPv6 bind address (via -b option)', if: File.exist?('/proc/net/if_inet6') do + context 'with IPv6 bind address (via -b option)', if: has_ipv6? do # This error is raised for invalid bind addresses let(:error_msg) { "`start_tcp_server': no acceptor" } let(:ipv6_addr) { '::1/128' } diff --git a/spec/support/script_helper.rb b/spec/support/script_helper.rb new file mode 100644 index 000000000..f37bf85f8 --- /dev/null +++ b/spec/support/script_helper.rb @@ -0,0 +1,11 @@ +module ScriptHelper + def has_ipv6? + File.exist?('/proc/net/if_inet6') && system('ip -6 addr | grep ::1') + end +end + +RSpec.configure do |config| + # #extend adds setup methods for example groups (#describe / #context); + # #include adds methods within actual examples (#it blocks) + config.extend ScriptHelper, type: :script +end