rspec-httpd 0.3.5 → 0.3.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e96bcab8620e1f538baf7047997a4ff231114e99f7ffe3fb407d0a103338276c
4
- data.tar.gz: ed027dac119e4611748d07cadbce59a56ebc8437b16e0f9d88660a561b3c83e2
3
+ metadata.gz: f127a5abd4a8ac754c24cd3a58360ab60e749ca847fa65d1859ca3b9a4fd5e54
4
+ data.tar.gz: 6b76d26b499b3e411e36efee597ca6406b1f52f82b24c5163a848b89c86712f4
5
5
  SHA512:
6
- metadata.gz: a5ce6ac0ca6eedd92d944f0802d74693f79c200ecea1e3ed796d963177b51a22766acb45717a9cfdd00c457477e875ffb62aca6bdb6e33a35a6024d3807d65c0
7
- data.tar.gz: 56eaea570426c3e7ae24fb178091213b70c1a5a26440ce20e6c1bbe8e5fa7b6807e160d3d2c3c976941aebb667f803f915e02401e1c61bf5e2840f9e3e2392b9
6
+ metadata.gz: fcc7057d59576c750558e3cc3bc39fc075bad75722f82f6d14a10fa73cf89b274a6a18ca3b09316f081069e826ae6987d7e790328b725616cac7b24fe46a3910
7
+ data.tar.gz: 1fc2cd38d2387ba5f78ab5f6cc8ed3d1ff5ea2c47f44edf5a03b6976ac7867baebe9573154ab96cbb1b66357820208f27cc0b85b083a199e766d7691ce02b24f
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.5
1
+ 0.3.6
data/lib/rspec/httpd.rb CHANGED
@@ -84,9 +84,9 @@ module RSpec::Httpd
84
84
 
85
85
  if response.status >= 400
86
86
  error_message += <<~MSG
87
- ---- response.body ----------------------------------------------------
88
- #{response.body}
89
- -----------------------------------------------------------------------
87
+ ---- response.body ----------------------------------------------------
88
+ #{response.body}
89
+ -----------------------------------------------------------------------
90
90
  MSG
91
91
  end
92
92
 
@@ -7,7 +7,7 @@ class RSpec::Httpd::Config
7
7
  def initialize
8
8
  self.host = "127.0.0.1"
9
9
  self.port = 12_345
10
- self.command = "bundle exec rackup -E test -p 12345"
10
+ self.command = nil
11
11
  self.logger = Logger.new(STDERR).tap { |logger| logger.level = Logger::INFO }
12
12
  end
13
13
  end
@@ -37,24 +37,32 @@ module RSpec::Httpd
37
37
  # You can use this method to retrieve a client connection to a server
38
38
  # specified via host:, port:, and, optionally, a command.
39
39
  def start!(host: "0.0.0.0", port:, command:, logger: nil)
40
+ puts "start! command: #{command.inspect}"
40
41
  @servers ||= {}
41
- @servers[[host, port, command]] ||= do_start(host, port, command)
42
+ @servers[[host, port, command]] ||= command ? do_start(host, port, command) : check_server(host, port)
42
43
  @logger = logger if logger
43
44
  end
44
45
 
45
46
  private
46
47
 
48
+ def check_server(host, port)
49
+ unless wait_for_server(host: host, port: port, timeout: MAX_STARTUP_TIME)
50
+ logger.error "cannot reach server at http://#{host}:#{port}"
51
+ exit 1
52
+ end
53
+ end
54
+
47
55
  def do_start(host, port, command)
48
56
  if port_open?(host, port)
49
57
  logger.error "A process is already running on #{host}:#{port}"
50
58
  exit 2
51
59
  end
52
-
60
+
53
61
  STDERR.puts <<~MSG
54
- ==== Starting server ================================================================
55
- #{command}
56
- =====================================================================================
57
- MSG
62
+ ==== Starting server ================================================================
63
+ #{command}
64
+ =====================================================================================
65
+ MSG
58
66
 
59
67
  # start child process in a separate process group. at exit we'll
60
68
  # kill the entire process group. This helps if the started process
@@ -91,11 +99,11 @@ module RSpec::Httpd
91
99
  pid
92
100
  end
93
101
 
94
- def wait_for_server(host:, port:, pid:, timeout:)
102
+ def wait_for_server(host:, port:, pid: nil, timeout:)
95
103
  while timeout > 0
96
104
  sleep 0.1
97
105
  return true if port_open?(host, port)
98
- return false if Process.waitpid(pid, Process::WNOHANG)
106
+ return false if pid && Process.waitpid(pid, Process::WNOHANG)
99
107
 
100
108
  timeout -= 0.1
101
109
  next if timeout > 0
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.5
4
+ version: 0.3.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Enrico Thierbach
@@ -114,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
114
114
  - !ruby/object:Gem::Version
115
115
  version: '0'
116
116
  requirements: []
117
- rubygems_version: 3.0.2
117
+ rubygems_version: 3.0.6
118
118
  signing_key:
119
119
  specification_version: 4
120
120
  summary: RSpec testing for HTTP requests