fakeit 0.4.2 → 0.5.0

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: fa4cb42c0187e460b3cbf72489ba5d0b7c8b3556a89a9ab770c4c263c271e633
4
- data.tar.gz: f2285fe3eb42ac9e0b5f02130cab64794d2be425dd1f09a21b1334ba34f94125
3
+ metadata.gz: 6b1ca4895251e4df53783b1dd731713c771a412cedd720fedf09ba3c106242b9
4
+ data.tar.gz: 369077526902a6c6f3c591dc63f0b7c9bc6358c87b27085bc8fe338abb9447ba
5
5
  SHA512:
6
- metadata.gz: '08c47760084910719518328975bcd2768428fc76a7cfe9da3a4a2075aebac66865b8a13e67344a19b3899a3598a0bf9a34aca8437ba860bba6a3f0dcc61ca868'
7
- data.tar.gz: 8a29d3e962e7ecbd8f3cab02b480d01be9f279ae2f4d87194c3b58009dea2426e8acd5dd718e19a93215bfbff63a57569c11deecf0c2d0ffba614bb6e9470b85
6
+ metadata.gz: 56468fca4c3aad622617a0d53ff8ae662b55d28667ac44773decc81aa13fed3f1344998d48b1bdc5509b119483bdd6a7f9e4698ddfe36d704b0391bee1f9f40c
7
+ data.tar.gz: 5fe807bf73718c1a381a7fc66e9950ffab63663fd0430c2a2b815da295ecefaabb65e9e7a5158cfdc5cb5787d60b7d48c9258c5b6de19c109271155edb0f8874
data/.circleci/config.yml CHANGED
@@ -12,7 +12,7 @@ jobs:
12
12
 
13
13
  docker:
14
14
  # specify the version you desire here
15
- - image: circleci/ruby:2.6.2
15
+ - image: circleci/ruby:2.7.0
16
16
 
17
17
  # Specify service dependencies here if necessary
18
18
  # CircleCI maintains a library of pre-built images
data/.rubocop.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  AllCops:
2
- TargetRubyVersion: 2.6
2
+ TargetRubyVersion: 2.7
3
3
 
4
4
  Style/Documentation:
5
5
  Enabled: false
@@ -7,7 +7,7 @@ Style/Documentation:
7
7
  Style/FrozenStringLiteralComment:
8
8
  Enabled: false
9
9
 
10
- Metrics/LineLength:
10
+ Layout/LineLength:
11
11
  Max: 120
12
12
 
13
13
  Metrics/BlockLength:
@@ -17,3 +17,12 @@ Metrics/BlockLength:
17
17
 
18
18
  Security/Open:
19
19
  Enabled: false
20
+
21
+ Style/HashEachMethods:
22
+ Enabled: true
23
+
24
+ Style/HashTransformKeys:
25
+ Enabled: false
26
+
27
+ Style/HashTransformValues:
28
+ Enabled: true
data/Gemfile.lock CHANGED
@@ -1,9 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fakeit (0.4.2)
4
+ fakeit (0.5.0)
5
5
  faker (~> 2.2)
6
- openapi_parser (= 0.6.1)
6
+ openapi_parser (= 0.8.0)
7
7
  rack (~> 2.0)
8
8
  rack-cors (~> 1.0)
9
9
  rainbow (~> 3.0)
@@ -13,55 +13,55 @@ GEM
13
13
  remote: https://rubygems.org/
14
14
  specs:
15
15
  ast (2.4.0)
16
- byebug (11.0.1)
17
- concurrent-ruby (1.1.5)
16
+ byebug (11.1.1)
17
+ concurrent-ruby (1.1.6)
18
18
  diff-lcs (1.3)
19
19
  docile (1.3.2)
20
- faker (2.7.0)
21
- i18n (>= 1.6, < 1.8)
22
- i18n (1.7.0)
20
+ faker (2.10.2)
21
+ i18n (>= 1.6, < 2)
22
+ i18n (1.8.2)
23
23
  concurrent-ruby (~> 1.0)
24
24
  jaro_winkler (1.5.4)
25
- json (2.2.0)
26
- openapi_parser (0.6.1)
27
- parallel (1.19.0)
28
- parser (2.6.5.0)
25
+ openapi_parser (0.8.0)
26
+ parallel (1.19.1)
27
+ parser (2.7.0.2)
29
28
  ast (~> 2.4.0)
30
- rack (2.0.7)
31
- rack-cors (1.1.0)
29
+ rack (2.2.2)
30
+ rack-cors (1.1.1)
32
31
  rack (>= 2.0.0)
33
32
  rack-test (1.1.0)
34
33
  rack (>= 1.0, < 3)
35
34
  rainbow (3.0.0)
36
35
  rake (12.3.3)
36
+ rexml (3.2.4)
37
37
  rspec (3.9.0)
38
38
  rspec-core (~> 3.9.0)
39
39
  rspec-expectations (~> 3.9.0)
40
40
  rspec-mocks (~> 3.9.0)
41
- rspec-core (3.9.0)
42
- rspec-support (~> 3.9.0)
41
+ rspec-core (3.9.1)
42
+ rspec-support (~> 3.9.1)
43
43
  rspec-expectations (3.9.0)
44
44
  diff-lcs (>= 1.2.0, < 2.0)
45
45
  rspec-support (~> 3.9.0)
46
- rspec-mocks (3.9.0)
46
+ rspec-mocks (3.9.1)
47
47
  diff-lcs (>= 1.2.0, < 2.0)
48
48
  rspec-support (~> 3.9.0)
49
- rspec-support (3.9.0)
50
- rubocop (0.76.0)
49
+ rspec-support (3.9.2)
50
+ rubocop (0.80.0)
51
51
  jaro_winkler (~> 1.5.1)
52
52
  parallel (~> 1.10)
53
- parser (>= 2.6)
53
+ parser (>= 2.7.0.1)
54
54
  rainbow (>= 2.2.2, < 4.0)
55
+ rexml
55
56
  ruby-progressbar (~> 1.7)
56
57
  unicode-display_width (>= 1.4.0, < 1.7)
57
58
  ruby-progressbar (1.10.1)
58
- simplecov (0.17.1)
59
+ simplecov (0.18.2)
59
60
  docile (~> 1.1)
60
- json (>= 1.8, < 3)
61
- simplecov-html (~> 0.10.0)
62
- simplecov-html (0.10.2)
63
- slop (4.7.0)
64
- unicode-display_width (1.6.0)
61
+ simplecov-html (~> 0.11)
62
+ simplecov-html (0.12.0)
63
+ slop (4.8.0)
64
+ unicode-display_width (1.6.1)
65
65
 
66
66
  PLATFORMS
67
67
  ruby
@@ -73,8 +73,8 @@ DEPENDENCIES
73
73
  rack-test (~> 1.1)
74
74
  rake (~> 12.0)
75
75
  rspec (~> 3.0)
76
- rubocop (~> 0.67)
77
- simplecov (~> 0.16)
76
+ rubocop (~> 0.80)
77
+ simplecov (~> 0.18)
78
78
 
79
79
  BUNDLED WITH
80
- 2.0.2
80
+ 2.1.2
data/bin/fakeit CHANGED
@@ -14,7 +14,7 @@ begin
14
14
  o.bool '--use-example', 'use example provided in spec if exists'
15
15
  o.bool '--static', 'generate static response'
16
16
  o.array '--static-types', 'generate static value for specified types, e.g. --static-types integer,string'
17
- o.array '--static-properties', 'generate static value for specified properties, e.g. --static-types id,uuid'
17
+ o.array '--static-properties', 'generate static value for specified properties, e.g. --static-properties id,uuid'
18
18
  o.separator ''
19
19
  o.separator 'other options:'
20
20
  o.on '-v', '--version' do
data/docs/random.md CHANGED
@@ -18,6 +18,7 @@ The following Openapi properties are supported in random response generation
18
18
  | |format=email| |
19
19
  | |format=date|In past 100 days|
20
20
  | |format=date-time|In past 100 days|
21
+ | |format=binary|Length is a multiple of `4` between `4` ~ `100`|
21
22
  | |minLength|Default: `0`|
22
23
  | |maxLength|Default: `minLength + 10`|
23
24
  |integer|enum| |
data/docs/static.md CHANGED
@@ -17,6 +17,7 @@ Static value generation rule
17
17
  | |format=email|`some@email.com`|
18
18
  | |format=date|today|
19
19
  | |format=date-time|midnight today|
20
+ | |format=binary|`1111`|
20
21
  | |minLength|`1` repeats for (minLength + 10) times if no maxLength specified|
21
22
  | |maxLength|`1` repeats for maxLength times|
22
23
  |integer|N/A|`2^31 - 1`|
data/fakeit.gemspec CHANGED
@@ -22,18 +22,18 @@ Gem::Specification.new do |spec|
22
22
  spec.executables = 'fakeit'
23
23
  spec.require_paths = ['lib']
24
24
 
25
- spec.required_ruby_version = '>= 2.6.0'
25
+ spec.required_ruby_version = '>= 2.7.0'
26
26
 
27
27
  spec.add_development_dependency 'bundler', '~> 2.0'
28
28
  spec.add_development_dependency 'byebug', '~> 11.0'
29
29
  spec.add_development_dependency 'rack-test', '~> 1.1'
30
30
  spec.add_development_dependency 'rake', '~> 12.0'
31
31
  spec.add_development_dependency 'rspec', '~> 3.0'
32
- spec.add_development_dependency 'rubocop', '~> 0.67'
33
- spec.add_development_dependency 'simplecov', '~> 0.16'
32
+ spec.add_development_dependency 'rubocop', '~> 0.80'
33
+ spec.add_development_dependency 'simplecov', '~> 0.18'
34
34
 
35
35
  spec.add_dependency 'faker', '~> 2.2'
36
- spec.add_dependency 'openapi_parser', '0.6.1'
36
+ spec.add_dependency 'openapi_parser', '0.8.0'
37
37
  spec.add_dependency 'rack', '~> 2.0'
38
38
  spec.add_dependency 'rack-cors', '~> 1.0'
39
39
  spec.add_dependency 'rainbow', '~> 3.0'
data/lib/fakeit.rb CHANGED
@@ -7,7 +7,7 @@ require 'rack'
7
7
  require 'logger'
8
8
  require 'rainbow'
9
9
 
10
- Dir.glob(File.join(File.dirname(__FILE__), 'fakeit', '**/*.rb')).each { |file| require file }
10
+ Dir.glob(File.join(File.dirname(__FILE__), 'fakeit', '**/*.rb')).sort.each { require _1 }
11
11
 
12
12
  module Fakeit
13
13
  class << self
@@ -8,7 +8,7 @@ module Fakeit
8
8
  request = Rack::Request.new(env)
9
9
  specification
10
10
  .operation(request.request_method.downcase.to_sym, request.path_info, options)
11
- .then { |operation| operation ? handle(operation, request, options) : not_found }
11
+ .then { _1 ? handle(_1, request, options) : not_found }
12
12
  end
13
13
  end
14
14
 
@@ -8,7 +8,7 @@ module Fakeit
8
8
  def call(env)
9
9
  env
10
10
  .tap(&method(:log_request))
11
- .then { |e| @app.call(e) }
11
+ .then { @app.call(_1) }
12
12
  .tap(&method(:log_response))
13
13
  end
14
14
 
@@ -14,7 +14,7 @@ module Fakeit
14
14
 
15
15
  def generate_array_example(example_options, get_size)
16
16
  size = retries = get_size[]
17
- [].tap { |result| generate_items(size, retries, example_options, result) }
17
+ [].tap { generate_items(size, retries, example_options, _1) }
18
18
  end
19
19
 
20
20
  def random_array_size(example_options)
@@ -16,12 +16,12 @@ module Fakeit
16
16
 
17
17
  def static_number_example
18
18
  (num_rand_end * num_multiple)
19
- .then { |result| multipleOf ? result : result.round(2) }
19
+ .then { multipleOf ? _1 : _1.round(2) }
20
20
  end
21
21
 
22
22
  def random_number_example
23
23
  (Faker::Number.between(from: num_rand_begin, to: num_rand_end) * num_multiple)
24
- .then { |result| multipleOf ? result : result.round(2) }
24
+ .then { multipleOf ? _1 : _1.round(2) }
25
25
  end
26
26
 
27
27
  def num_rand_begin
@@ -10,7 +10,8 @@ module Fakeit
10
10
  'date-time' => lambda do
11
11
  now = Time.now
12
12
  Time.new(now.year, now.month, now.day, 0, 0, 0, now.utc_offset).iso8601
13
- end
13
+ end,
14
+ 'binary' => -> { '1111' }
14
15
  }.freeze
15
16
 
16
17
  RANDOM_FORMAT_HANDLERS = {
@@ -19,7 +20,8 @@ module Fakeit
19
20
  'guid' => -> { SecureRandom.uuid },
20
21
  'email' => -> { Faker::Internet.email },
21
22
  'date' => -> { Faker::Date.backward(days: 100).iso8601 },
22
- 'date-time' => -> { Faker::Time.backward(days: 100).iso8601 }
23
+ 'date-time' => -> { Faker::Time.backward(days: 100).iso8601 },
24
+ 'binary' => -> { Faker::String.random(length: (4..100).step(4)) }
23
25
  }.freeze
24
26
 
25
27
  def string_example(example_options)
@@ -13,9 +13,9 @@ module Fakeit
13
13
 
14
14
  def headers
15
15
  response_headers
16
- &.map { |k, v| [k, v.schema.to_example(example_options)] }
17
16
  .to_h
18
- .tap { |headers| headers['Content-Type'] = response_content_type if response_content_type }
17
+ .transform_values { _1.schema.to_example(example_options) }
18
+ .tap { _1['Content-Type'] = response_content_type if response_content_type }
19
19
  end
20
20
 
21
21
  def body
@@ -27,7 +27,7 @@ module Fakeit
27
27
  end
28
28
 
29
29
  def validate(**request_parts)
30
- @validator.validate(request_parts)
30
+ @validator.validate(**request_parts)
31
31
  end
32
32
 
33
33
  private
@@ -10,7 +10,7 @@ module Fakeit
10
10
  module Schema
11
11
  include Fakeit::Openapi::Example
12
12
 
13
- def to_example(**example_options)
13
+ def to_example(example_options)
14
14
  return example if example_options[:use_example] && example
15
15
 
16
16
  return one_of_example(example_options) if one_of
@@ -32,20 +32,20 @@ module Fakeit
32
32
 
33
33
  def all_of_example(example_options)
34
34
  all_of
35
- .select { |option| option.type == 'object' }
36
- .map { |option| option.to_example(example_options) }
35
+ .select { _1.type == 'object' }
36
+ .map { _1.to_example(example_options) }
37
37
  .reduce(&:merge)
38
38
  end
39
39
 
40
40
  def any_of_example(example_options)
41
41
  any_of_options(example_options)
42
- .map { |option| option.to_example(example_options) }
42
+ .map { _1.to_example(example_options) }
43
43
  .reduce(&:merge)
44
44
  end
45
45
 
46
46
  def any_of_options(example_options)
47
47
  any_of
48
- .select { |option| option.type == 'object' }
48
+ .select { _1.type == 'object' }
49
49
  .then do |options|
50
50
  if example_options[:use_static][property: example_options[:property]]
51
51
  options
@@ -12,7 +12,7 @@ module Fakeit
12
12
 
13
13
  @doc
14
14
  .request_operation(method, path)
15
- &.then { |operation| Operation.new(operation, options) }
15
+ &.then { Operation.new(_1, options) }
16
16
  end
17
17
 
18
18
  private
@@ -1,3 +1,3 @@
1
1
  module Fakeit
2
- VERSION = '0.4.2'.freeze
2
+ VERSION = '0.5.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fakeit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Feng
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-11-22 00:00:00.000000000 Z
11
+ date: 2020-04-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -86,28 +86,28 @@ dependencies:
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '0.67'
89
+ version: '0.80'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '0.67'
96
+ version: '0.80'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: simplecov
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '0.16'
103
+ version: '0.18'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: '0.16'
110
+ version: '0.18'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: faker
113
113
  requirement: !ruby/object:Gem::Requirement
@@ -128,14 +128,14 @@ dependencies:
128
128
  requirements:
129
129
  - - '='
130
130
  - !ruby/object:Gem::Version
131
- version: 0.6.1
131
+ version: 0.8.0
132
132
  type: :runtime
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
136
  - - '='
137
137
  - !ruby/object:Gem::Version
138
- version: 0.6.1
138
+ version: 0.8.0
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: rack
141
141
  requirement: !ruby/object:Gem::Requirement
@@ -245,14 +245,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
245
245
  requirements:
246
246
  - - ">="
247
247
  - !ruby/object:Gem::Version
248
- version: 2.6.0
248
+ version: 2.7.0
249
249
  required_rubygems_version: !ruby/object:Gem::Requirement
250
250
  requirements:
251
251
  - - ">="
252
252
  - !ruby/object:Gem::Version
253
253
  version: '0'
254
254
  requirements: []
255
- rubygems_version: 3.0.3
255
+ rubygems_version: 3.1.2
256
256
  signing_key:
257
257
  specification_version: 4
258
258
  summary: Create mock server from Openapi specification