mirage 4.0.0.alpha6 → 4.0.0.alpha8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mirage/client/runner.rb +10 -8
- data/mirage_server.rb +1 -2
- data/server/mock_response_set.rb +11 -5
- data/server/routes/responses.rb +1 -0
- data/server/routes/templates.rb +2 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8e664377381f5dc9cc7913777720dbcf8725ce74
|
4
|
+
data.tar.gz: a082d2793a96efded9c66d24319793415ef69558
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4350871c5affaf2c92539110e6b1cc3bc3f53f670200ccd8b93e66dfa4074354630cf72395b9a9ac0fc6d9ee9bb7bc843cc7d645482109323fa749bdadafcbb4
|
7
|
+
data.tar.gz: 2f2120fbc55ac958b0c95fe3bce1ad7ca92b7ffd50ba6c8b6d0d448e049eb9907532084cfad607d618085ee487945337d0bb4b3b99d78ee1c23562c44ba211dd
|
data/lib/mirage/client/runner.rb
CHANGED
@@ -10,8 +10,8 @@ module Mirage
|
|
10
10
|
# Example Usage:
|
11
11
|
#
|
12
12
|
# Mirage.start :port => 9001 -> Configured MirageClient ready to use.
|
13
|
-
def start options={}
|
14
|
-
options={:port => 7001}.merge(options)
|
13
|
+
def start options = {}
|
14
|
+
options = {:port => 7001}.merge(options)
|
15
15
|
Runner.new.invoke(:start, [], options)
|
16
16
|
Mirage::Client.new(options)
|
17
17
|
end
|
@@ -22,7 +22,7 @@ module Mirage
|
|
22
22
|
# Mirage.stop -> Will stop mirage if there is only instance running. Can be running on any port.
|
23
23
|
# Mirage.stop :port => port -> stop mirage on a given port
|
24
24
|
# Mirage.stop :port => [port1, port2...] -> stops multiple running instances of Mirage
|
25
|
-
def stop options={:port => []}
|
25
|
+
def stop options = {:port => []}
|
26
26
|
options = {:port => :all} if options == :all
|
27
27
|
|
28
28
|
if options[:port]
|
@@ -78,27 +78,29 @@ module Mirage
|
|
78
78
|
end
|
79
79
|
|
80
80
|
|
81
|
-
command = command.concat(options.to_a).flatten.collect {
|
81
|
+
command = command.concat(options.to_a).flatten.collect {|arg| arg.to_s}
|
82
82
|
ChildProcess.build(*command).start
|
83
83
|
|
84
|
-
wait_until(:timeout_after => 30) {
|
84
|
+
wait_until(:timeout_after => 30) {Mirage.running?(options)}
|
85
85
|
|
86
86
|
begin
|
87
87
|
Mirage::Client.new(options).prime
|
88
88
|
rescue Mirage::InternalServerException => e
|
89
89
|
puts "WARN: #{e.message}"
|
90
90
|
end
|
91
|
+
|
92
|
+
|
91
93
|
end
|
92
94
|
|
93
95
|
desc "stop", "Stops mirage"
|
94
96
|
method_option :port, :aliases => "-p", :type => :array, :default => [], :banner => "[port_1 port_2|all]", :desc => "port(s) of mirage instance(s). ALL stops all running instances"
|
95
97
|
|
96
98
|
def stop
|
97
|
-
ports = options[:port].collect{|port| port
|
99
|
+
ports = options[:port].collect {|port| port =~ /\d+/ ? port.to_i : port}
|
98
100
|
process_ids = mirage_process_ids(ports)
|
99
101
|
raise ClientError.new("Mirage is running on ports #{process_ids.keys.sort.join(", ")}. Please run mirage stop -p [PORT(s)] instead") if (process_ids.size > 1 && ports.empty?)
|
100
|
-
process_ids.values.each {
|
101
|
-
wait_until {
|
102
|
+
process_ids.values.each {|process_id| kill process_id}
|
103
|
+
wait_until {mirage_process_ids(options[:port]).empty?}
|
102
104
|
end
|
103
105
|
|
104
106
|
end
|
data/mirage_server.rb
CHANGED
data/server/mock_response_set.rb
CHANGED
@@ -1,14 +1,20 @@
|
|
1
1
|
module Mirage
|
2
2
|
class MockResponseSet < Hash
|
3
3
|
def fuzzy_find desired_key, http_method
|
4
|
+
http_method = http_method.upcase
|
4
5
|
result = self[desired_key]
|
5
|
-
|
6
|
-
|
7
|
-
key.is_a?(Regexp) && desired_key.is_a?(String) && key.match(desired_key) && value[http_method
|
8
|
-
end.sort do |a,b|
|
6
|
+
|
7
|
+
results = find_all do |key, value|
|
8
|
+
key.is_a?(Regexp) && desired_key.is_a?(String) && key.match(desired_key) && value[http_method]
|
9
|
+
end.sort do |a, b|
|
9
10
|
b.first.source.size <=> a.first.source.size
|
10
11
|
end
|
11
|
-
|
12
|
+
|
13
|
+
return result unless results && results.first
|
14
|
+
|
15
|
+
return results.first[1] unless result && result[http_method]
|
16
|
+
|
17
|
+
{http_method => result[http_method].concat(results.first[1][http_method])}
|
12
18
|
end
|
13
19
|
end
|
14
20
|
end
|
data/server/routes/responses.rb
CHANGED
@@ -4,6 +4,7 @@ module Mirage
|
|
4
4
|
%w(get post delete put options head).each do |http_method|
|
5
5
|
send(http_method, '/responses/*') do |name|
|
6
6
|
body, query_string = request.body.read.to_s, request.query_string
|
7
|
+
name = "/#{name}"
|
7
8
|
|
8
9
|
options = {:body => body,
|
9
10
|
:http_method => http_method,
|
data/server/routes/templates.rb
CHANGED
@@ -15,11 +15,12 @@ module Mirage
|
|
15
15
|
|
16
16
|
put '/templates/*' do |name|
|
17
17
|
content_type :json
|
18
|
+
name = "/#{name}"
|
18
19
|
mock_response = synchronize do
|
19
20
|
MockResponse.new(name, JSON.parse(request.body.read))
|
20
21
|
end
|
21
22
|
|
22
|
-
mock_response.requests_url = request.url.gsub("/templates
|
23
|
+
mock_response.requests_url = request.url.gsub("/templates#{name}", "/requests/#{mock_response.response_id}")
|
23
24
|
{:id => mock_response.response_id}.to_json
|
24
25
|
end
|
25
26
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mirage
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.0.0.
|
4
|
+
version: 4.0.0.alpha8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Leon Davis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-07-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sinatra
|