derfred-httpstub 0.1.0.0.0.1 → 0.1.1

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.
Files changed (2) hide show
  1. data/lib/httpstub.rb +15 -6
  2. metadata +1 -1
data/lib/httpstub.rb CHANGED
@@ -9,12 +9,16 @@ class HTTPStub
9
9
  @@thread = nil
10
10
 
11
11
  def self.listen_on(ports)
12
- @@root_server = WEBrick::HTTPServer.new :Port => 10000, :DoNotListen => true
13
- [ports].flatten.each do |port|
14
- @@root_server.virtual_host HTTPStubServer.new(port)
15
- @@root_server.listen "0.0.0.0", port
12
+ stop_server
13
+
14
+ unless @@root_server
15
+ @@root_server = WEBrick::HTTPServer.new :Port => 10000, :DoNotListen => true
16
+ [ports].flatten.each do |port|
17
+ @@root_server.virtual_host HTTPStubServer.new(port)
18
+ @@root_server.listen "0.0.0.0", port
19
+ end
20
+ @@thread = Thread.new(@@root_server) { |server| server.start }
16
21
  end
17
- @@thread = Thread.new(@@root_server) { |server| server.start }
18
22
  end
19
23
 
20
24
  def self.initialize_server(port)
@@ -52,7 +56,12 @@ class HTTPStub
52
56
  def self.stub(method, url, metadata, body)
53
57
  parsed_url = URI.parse(url)
54
58
  server = initialize_server parsed_url.port
55
- server.servlet.send("stub_#{method}", "#{parsed_url.path}?#{parsed_url.query}", metadata, body)
59
+ path = if parsed_url.query.nil? or parsed_url.query == ""
60
+ parsed_url.path
61
+ else
62
+ "#{parsed_url.path}?#{parsed_url.query}"
63
+ end
64
+ server.servlet.send("stub_#{method}", path, metadata, body)
56
65
  end
57
66
 
58
67
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: derfred-httpstub
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.0.0.1
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Frederik Fix