diff options
author | Robert Speicher <rspeicher@gmail.com> | 2018-08-15 16:12:35 -0500 |
---|---|---|
committer | Robert Speicher <rspeicher@gmail.com> | 2018-08-15 16:13:10 -0500 |
commit | 21182ae60d4ed7b43afc53a36f6e428bb2f98133 (patch) | |
tree | 57e774163a06071f94aec82eaad1cec6390c040d /spec | |
parent | 03055503802193e155f9b1267e55cdbdd8125060 (diff) | |
download | gitlab-shell-21182ae60d4ed7b43afc53a36f6e428bb2f98133.tar.gz |
Reorganize spec_helper; add support files for VCR and HTTPUNIXServer
Diffstat (limited to 'spec')
-rw-r--r-- | spec/spec_helper.rb | 39 | ||||
-rw-r--r-- | spec/support/http_unix_server.rb | 29 | ||||
-rw-r--r-- | spec/support/vcr.rb | 7 |
3 files changed, 40 insertions, 35 deletions
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 8549818..5defedf 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,48 +1,17 @@ require 'simplecov' SimpleCov.start -require 'vcr' require 'webmock' -require 'webrick' require 'gitlab_init' -VCR.configure do |c| - c.cassette_library_dir = 'spec/vcr_cassettes' - c.hook_into :webmock - c.configure_rspec_metadata! -end +Dir[File.expand_path('support/**/*.rb', __dir__)].each { |f| require f } RSpec.configure do |config| + config.run_all_when_everything_filtered = true + config.filter_run :focus + config.before(:each) do stub_const('ROOT_PATH', File.expand_path('..', __dir__)) end end - -# like WEBrick::HTTPServer, but listens on UNIX socket -class HTTPUNIXServer < WEBrick::HTTPServer - def listen(address, port) - socket = Socket.unix_server_socket(address) - socket.autoclose = false - server = UNIXServer.for_fd(socket.fileno) - socket.close - @listeners << server - end - - # Workaround: - # https://bugs.ruby-lang.org/issues/10956 - # Affecting Ruby 2.2 - # Fix for 2.2 is at https://github.com/ruby/ruby/commit/ab0a64e1 - # However, this doesn't work with 2.1. The following should work for both: - def start(&block) - @shutdown_pipe = IO.pipe - shutdown_pipe = @shutdown_pipe - super(&block) - end - - def cleanup_shutdown_pipe(shutdown_pipe) - @shutdown_pipe = nil - return if !shutdown_pipe - super(shutdown_pipe) - end -end diff --git a/spec/support/http_unix_server.rb b/spec/support/http_unix_server.rb new file mode 100644 index 0000000..d786238 --- /dev/null +++ b/spec/support/http_unix_server.rb @@ -0,0 +1,29 @@ +require 'webrick' + +# like WEBrick::HTTPServer, but listens on UNIX socket +class HTTPUNIXServer < WEBrick::HTTPServer + def listen(address, port) + socket = Socket.unix_server_socket(address) + socket.autoclose = false + server = UNIXServer.for_fd(socket.fileno) + socket.close + @listeners << server + end + + # Workaround: + # https://bugs.ruby-lang.org/issues/10956 + # Affecting Ruby 2.2 + # Fix for 2.2 is at https://github.com/ruby/ruby/commit/ab0a64e1 + # However, this doesn't work with 2.1. The following should work for both: + def start(&block) + @shutdown_pipe = IO.pipe + shutdown_pipe = @shutdown_pipe + super(&block) + end + + def cleanup_shutdown_pipe(shutdown_pipe) + @shutdown_pipe = nil + return if !shutdown_pipe + super(shutdown_pipe) + end +end diff --git a/spec/support/vcr.rb b/spec/support/vcr.rb new file mode 100644 index 0000000..a47cb97 --- /dev/null +++ b/spec/support/vcr.rb @@ -0,0 +1,7 @@ +require 'vcr' + +VCR.configure do |c| + c.cassette_library_dir = 'spec/vcr_cassettes' + c.hook_into :webmock + c.configure_rspec_metadata! +end |