rspec-httpd 0.3.6 → 0.3.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f127a5abd4a8ac754c24cd3a58360ab60e749ca847fa65d1859ca3b9a4fd5e54
4
- data.tar.gz: 6b76d26b499b3e411e36efee597ca6406b1f52f82b24c5163a848b89c86712f4
3
+ metadata.gz: df631d1591425ab8d6221ecdf8d3e77c571d825a3bd42b875bf732414c171533
4
+ data.tar.gz: 1443d91ac725578992ba6506cf3cfca8b0c95a002e38e0a0aecbf95aab2f8593
5
5
  SHA512:
6
- metadata.gz: fcc7057d59576c750558e3cc3bc39fc075bad75722f82f6d14a10fa73cf89b274a6a18ca3b09316f081069e826ae6987d7e790328b725616cac7b24fe46a3910
7
- data.tar.gz: 1fc2cd38d2387ba5f78ab5f6cc8ed3d1ff5ea2c47f44edf5a03b6976ac7867baebe9573154ab96cbb1b66357820208f27cc0b85b083a199e766d7691ce02b24f
6
+ metadata.gz: 8dd5412f5b2acb94b439b7fb40874deb8add05673056e52022551b12ff53733913fcdfc8ffd43e1cc3d9db107f2786730f550090b39fc9db2afaf9fa3219283e
7
+ data.tar.gz: a4209b8cfedbbbd80d0d7eae762753718ce9d20431f889b955cae48abadabc5cf09892555cde3b5b7c70a942a14767e6ed93204906fa6a7b6be2e1aa8e88959a
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.6
1
+ 0.3.7
data/lib/rspec/httpd.rb CHANGED
@@ -5,6 +5,7 @@ require "expectation"
5
5
  # rubocop:disable Metrics/AbcSize
6
6
  # rubocop:disable Metrics/CyclomaticComplexity
7
7
  # rubocop:disable Metrics/PerceivedComplexity
8
+ # rubocop:disable Metrics/MethodLength
8
9
 
9
10
  module RSpec::Httpd
10
11
  end
@@ -1,7 +1,5 @@
1
1
  # rubocop:disable Lint/HandleExceptions
2
2
  # rubocop:disable Metrics/AbcSize
3
- # rubocop:disable Metrics/CyclomaticComplexity
4
- # rubocop:disable Metrics/MethodLength
5
3
 
6
4
  require "socket"
7
5
  require "timeout"
@@ -70,35 +68,32 @@ module RSpec::Httpd
70
68
  pid = spawn(command, pgroup: true)
71
69
  pgid = Process.getpgid(pid)
72
70
 
71
+ # Install an at_exit handler. This will kill the server. The command
72
+ # argument is passed in for logging only.
73
73
  at_exit do
74
- begin
75
- logger.debug "Terminating server in pgid #{pgid}: #{command}"
76
- Process.kill("TERM", -pgid)
77
- sleep 0.2
78
- rescue Errno::ESRCH
79
- end
80
-
81
- if port_open?(host, port)
82
- begin
83
- logger.debug "Killing server in pgid #{pgid}: #{command}"
84
- Process.kill("KILL", -pgid)
85
- rescue Errno::ESRCH, Errno::EPERM
86
- end
87
- end
74
+ kill_server "TERM", pgid, command: command, sleep: 0.2 if port_open?(host, port)
75
+ kill_server "KILL", pgid, command: command, sleep: 0.2 if port_open?(host, port)
88
76
 
89
77
  logger.warn "Cannot stop server at pid #{pid}: #{command}" if port_open?(host, port)
90
- exit 0
91
78
  end
92
79
 
93
80
  unless wait_for_server(host: host, port: port, pid: pid, timeout: MAX_STARTUP_TIME)
94
81
  logger.error "server didn't start at http://#{host}:#{port} pid #{pid}: #{command}"
95
- exit 1
82
+ exit! 1
96
83
  end
97
84
 
98
85
  logger.info "Started server at pid #{pid}: #{command}"
99
86
  pid
100
87
  end
101
88
 
89
+ def kill_server(signal, pgid, command:, sleep: nil)
90
+ logger.debug "Kill server in pgid #{pgid} w/#{signal}: #{command}"
91
+
92
+ Process.kill(signal, -pgid)
93
+ Kernel.sleep(sleep) if sleep
94
+ rescue Errno::ESRCH, Errno::EPERM
95
+ end
96
+
102
97
  def wait_for_server(host:, port:, pid: nil, timeout:)
103
98
  while timeout > 0
104
99
  sleep 0.1
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-httpd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.6
4
+ version: 0.3.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Enrico Thierbach