anymock 0.2.2 → 0.2.3

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: 3cee9c37a7dcea91bb1db3492713f243b98a2cc7f0355680947826145bce4f91
4
- data.tar.gz: 47cfef7c365016c7b3ec1635bcc3b33a3ec797cfe76f9e49b6b4489a8ca4f536
3
+ metadata.gz: f33ecb35b1a6474cb58b63fc5a35a6f89b84a7e2cdb91f93e86ec216aa8279d2
4
+ data.tar.gz: f58df06d1d72f8c5cd62abdccca38003da37a18a17da1ede18f5123f391f97e7
5
5
  SHA512:
6
- metadata.gz: 421b938461fc6162331304f3993921341bbdf668fa70b4155f342054c4d5042c17cd44cf80e0ea3aeb181c6d32983300d1069599ea513c54edabe12f0cc94676
7
- data.tar.gz: d90eee3509aacabfdc18e5ce26d358eb56a6f4dc4d33740d8d7dbc3bcf6faf174f8338ed09c3fdad2a48837aa7def743352a706a87291aada4100a17ca6ce32e
6
+ metadata.gz: de404d0ab4b656c531eeb7b51b7c3a5792fa33c213ebc5ac28d50ea9c9f0e1413a66ad774f5d47b6328faa3d472642a607b9124f4e041a09522b9ac3eddc2d4d
7
+ data.tar.gz: 4ba439ae5e9f186b0cd278c536398114e1c2598a28e30b12b9a750972b122d8fb1b11dd4f2a539239506c66d10606b47a4ddf693f3dc00f3146b57561b01d7db
@@ -2,6 +2,7 @@ require "anymock/version"
2
2
  require "anymock/cli"
3
3
  require "webrick"
4
4
  require "json"
5
+ require "logger"
5
6
 
6
7
  module Anymock
7
8
  class Server
@@ -12,12 +13,18 @@ module Anymock
12
13
  @address = opts[:address]
13
14
  @port = opts[:port]
14
15
  @response = opts[:response]
16
+ @log = opts[:log]
15
17
  @mirror = opts[:mirror]
18
+ @json = opts[:json]
16
19
  end
17
20
 
18
21
  def start
19
22
  server.mount_proc '/' do |req, res|
20
- req_string = { req.request_method => req.query }.to_json
23
+ output_params = {
24
+ path: req.path,
25
+ method: req.request_method,
26
+ query: req.query
27
+ }
21
28
  res.status = status_code(req.request_method)
22
29
  if @response
23
30
  res.body = @response
@@ -26,20 +33,22 @@ module Anymock
26
33
  else
27
34
  res.status = 204
28
35
  end
29
- output req_string, res.body
36
+ output output_params.merge({ response: res.body })
30
37
  end
31
38
  server.start
32
39
  end
33
40
 
34
- def output(req_string, body)
35
- puts "request:"
36
- puts "----"
37
- puts req_string
38
- puts "----"
39
- puts "response:"
40
- puts "----"
41
- puts body
42
- puts "----"
41
+ def output(params)
42
+ if @json
43
+ logger.info params.to_json
44
+ else
45
+ logger.info '----'
46
+ %i(path method query response).each do |n|
47
+ logger.info "#{n}:"
48
+ logger.info params[n]
49
+ end
50
+ logger.info '----'
51
+ end
43
52
  end
44
53
 
45
54
  private
@@ -55,6 +64,14 @@ module Anymock
55
64
  end
56
65
  end
57
66
 
67
+ def logger
68
+ @logger ||= Logger.new(log)
69
+ end
70
+
71
+ def log
72
+ @log || STDOUT
73
+ end
74
+
58
75
  def server
59
76
  @server ||= WEBrick::HTTPServer.new({
60
77
  DocumentRoot: document_root,
@@ -8,7 +8,9 @@ module Anymock
8
8
  option :a, type: :string, default: 'localhost'
9
9
  option :p, type: :string, default: '8080'
10
10
  option :r, type: :string, default: nil
11
+ option :l, type: :string
11
12
  option :m, type: :boolean, default: false
13
+ option :j, type: :boolean, default: false
12
14
 
13
15
  desc "start", "start mock server"
14
16
 
@@ -28,7 +30,9 @@ module Anymock
28
30
  address: options[:a],
29
31
  port: options[:p],
30
32
  response: options[:r],
31
- mirror: options[:m]
33
+ log: options[:l],
34
+ mirror: options[:m],
35
+ json: options[:j]
32
36
  }
33
37
  end
34
38
  end
@@ -1,3 +1,3 @@
1
1
  module Anymock
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: anymock
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jun Yokoyama