summaryrefslogtreecommitdiff
path: root/spec/support
diff options
context:
space:
mode:
authorNick Thomas <nick@gitlab.com>2018-08-16 12:58:50 +0000
committerNick Thomas <nick@gitlab.com>2018-08-16 12:58:50 +0000
commitfb8606f65a60808e52539f71f09fba871b5aba6b (patch)
treefffd9f99b45b063e318c0e954116c98647737ef9 /spec/support
parent122d84a403d3534dea743d94aa23d4115cc804a8 (diff)
parent710f75186009cb85c996d0de723ec3524299ecd8 (diff)
downloadgitlab-shell-fb8606f65a60808e52539f71f09fba871b5aba6b.tar.gz
Merge branch 'rs-rspec' into 'master'
Update to RSpec 3 Closes #54 See merge request gitlab-org/gitlab-shell!229
Diffstat (limited to 'spec/support')
-rw-r--r--spec/support/http_unix_server.rb35
-rw-r--r--spec/support/vcr.rb7
-rw-r--r--spec/support/webmock.rb3
3 files changed, 45 insertions, 0 deletions
diff --git a/spec/support/http_unix_server.rb b/spec/support/http_unix_server.rb
new file mode 100644
index 0000000..113df57
--- /dev/null
+++ b/spec/support/http_unix_server.rb
@@ -0,0 +1,35 @@
+require 'webrick'
+
+# like WEBrick::HTTPServer, but listens on UNIX socket
+class HTTPUNIXServer < WEBrick::HTTPServer
+ def initialize(config = {})
+ null_log = WEBrick::Log.new(IO::NULL, 7)
+
+ super(config.merge(Logger: null_log, AccessLog: null_log))
+ end
+
+ 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
diff --git a/spec/support/webmock.rb b/spec/support/webmock.rb
new file mode 100644
index 0000000..ed4fe6d
--- /dev/null
+++ b/spec/support/webmock.rb
@@ -0,0 +1,3 @@
+require 'webmock/rspec'
+
+WebMock.disable_net_connect!(allow_localhost: true)