mirage 4.0.0.alpha6 → 4.0.0.alpha8

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
  SHA1:
3
- metadata.gz: d515c9196308c045d6d8bfbba86ef54214e4994d
4
- data.tar.gz: 4c8795fbae565b9f3c51baa5fcef5d1d0bcb52bf
3
+ metadata.gz: 8e664377381f5dc9cc7913777720dbcf8725ce74
4
+ data.tar.gz: a082d2793a96efded9c66d24319793415ef69558
5
5
  SHA512:
6
- metadata.gz: 97438ad78627aa8f1198fdf56b41dbaf705ae52e228a085c9564114d770714fecb078eb142d0ac1c0cd1e8d7171eefb3411c2e90b32eaad775f169a8072842c2
7
- data.tar.gz: 2ee6762d6d516771a446b6528a77cd9cef6af742a2d7fb616e44b07d4c9325b6d7195b81fba0834e47a81855b6add3b6b318e9cb5ff91d7b738820b1b8eb252a
6
+ metadata.gz: 4350871c5affaf2c92539110e6b1cc3bc3f53f670200ccd8b93e66dfa4074354630cf72395b9a9ac0fc6d9ee9bb7bc843cc7d645482109323fa749bdadafcbb4
7
+ data.tar.gz: 2f2120fbc55ac958b0c95fe3bce1ad7ca92b7ffd50ba6c8b6d0d448e049eb9907532084cfad607d618085ee487945337d0bb4b3b99d78ee1c23562c44ba211dd
@@ -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 { |arg| arg.to_s }
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) { Mirage.running?(options) }
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=~/\d+/ ? port.to_i : 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 { |process_id| kill process_id }
101
- wait_until { mirage_process_ids(options[:port]).empty? }
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
@@ -1,7 +1,6 @@
1
1
  require 'rubygems'
2
2
  ROOT_DIR = File.dirname(__FILE__)
3
- $LOAD_PATH.unshift("#{ROOT_DIR}/lib")
4
- $LOAD_PATH.unshift("#{ROOT_DIR}/server")
3
+ $LOAD_PATH.unshift("#{ROOT_DIR}/lib", "#{ROOT_DIR}/server")
5
4
 
6
5
  require 'sinatra/base'
7
6
  require 'extensions/object'
@@ -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
- return result unless result.nil?
6
- result = find_all do |key, value|
7
- key.is_a?(Regexp) && desired_key.is_a?(String) && key.match(desired_key) && value[http_method.upcase]
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
- result.first && result.first[1]
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
@@ -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,
@@ -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/#{name}", "/requests/#{mock_response.response_id}")
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.alpha6
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-01-16 00:00:00.000000000 Z
11
+ date: 2018-07-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sinatra