fakeit 0.3.0 → 0.3.1

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: 9828311f1d6fb26ae16bf4bf4ec2fc5c52f5f88bfcdfc3df9ff4b9192671bf06
4
- data.tar.gz: 6c739c443ae6506a9584ae8f41f37db3821ef7fc8533321bfdb762ef5d29a0ed
3
+ metadata.gz: e00b82e5234f7a84b09aa97b54ca9bc6b3d21e180d70d04093cc9abfa70df47b
4
+ data.tar.gz: 2d4e588379c5e8d5db03044353c37318388eb3abbc44f1ff8582d29e1fcd70dc
5
5
  SHA512:
6
- metadata.gz: af522acb4552e1f45a6595a55aa1159ecf875813ac5547580fee0bd1a9962dfec73e58cc7f02cb53a0398b296537aca72f1cd733d2fbf0241994e9caf391e549
7
- data.tar.gz: 9d0ddac0516f7019bb8459172f72570aa2d670d3aca019ac31deec62b165246438b1c0df3f1305a5ab6c9dd28344d195bf389a86b54150db00e3b5d14e90d058
6
+ metadata.gz: b31b1a0365c538bcd89f9a9b61d09477a36a522e2bc12dc88dc71603856c6e9c269aadb378dd83f34f37910fe2b76693a8bb11444306deaf1e54526b306cc294
7
+ data.tar.gz: 4db7cb39db416d99e1585a9bb141f803d5f555d7203fa4f4095b587f0d883593c7f9498093b3ba71ec30f6696a219dcb6925e10e18256268d30ddd2e1ab50057
@@ -1,11 +1,12 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fakeit (0.3.0)
5
- faker (~> 1.9)
4
+ fakeit (0.3.1)
5
+ faker (~> 2.2)
6
6
  openapi_parser (= 0.3.1)
7
7
  rack (~> 2.0)
8
8
  rack-cors (~> 1.0)
9
+ rainbow (~> 3.0)
9
10
  slop (~> 4.6)
10
11
 
11
12
  GEM
@@ -16,15 +17,15 @@ GEM
16
17
  concurrent-ruby (1.1.5)
17
18
  diff-lcs (1.3)
18
19
  docile (1.3.2)
19
- faker (1.9.6)
20
- i18n (>= 0.7)
20
+ faker (2.2.1)
21
+ i18n (>= 0.8)
21
22
  i18n (1.6.0)
22
23
  concurrent-ruby (~> 1.0)
23
24
  jaro_winkler (1.5.3)
24
25
  json (2.2.0)
25
26
  openapi_parser (0.3.1)
26
27
  parallel (1.17.0)
27
- parser (2.6.3.0)
28
+ parser (2.6.4.0)
28
29
  ast (~> 2.4.0)
29
30
  rack (2.0.7)
30
31
  rack-cors (1.0.3)
data/README.md CHANGED
@@ -26,7 +26,7 @@ Openapi mock server is one of core components to support contract based developm
26
26
  }
27
27
  ```
28
28
 
29
- After tried several existing options, we cannot find a best solution to meet all the requirements. So we decide to __'Fakeit till you make it'__.
29
+ After tried several existing options, we cannot find a best solution to meet all the requirements. So we end up with __Fakeit__.
30
30
 
31
31
  ## Features
32
32
 
@@ -32,9 +32,10 @@ Gem::Specification.new do |spec|
32
32
  spec.add_development_dependency 'rubocop', '~> 0.67'
33
33
  spec.add_development_dependency 'simplecov', '~> 0.16'
34
34
 
35
- spec.add_dependency 'faker', '~> 1.9'
35
+ spec.add_dependency 'faker', '~> 2.2'
36
36
  spec.add_dependency 'openapi_parser', '0.3.1'
37
37
  spec.add_dependency 'rack', '~> 2.0'
38
38
  spec.add_dependency 'rack-cors', '~> 1.0'
39
+ spec.add_dependency 'rainbow', '~> 3.0'
39
40
  spec.add_dependency 'slop', '~> 4.6'
40
41
  end
@@ -5,6 +5,7 @@ require 'openapi_parser'
5
5
  require 'faker'
6
6
  require 'rack'
7
7
  require 'logger'
8
+ require 'rainbow'
8
9
 
9
10
  Dir.glob(File.join(File.dirname(__FILE__), 'fakeit', '**/*.rb')).each { |file| require file }
10
11
 
@@ -18,12 +18,8 @@ module Fakeit
18
18
  validate(operation, request)
19
19
  response(operation)
20
20
  rescue Fakeit::Validation::ValidationError => e
21
- if options.permissive
22
- Fakeit::Logger.warn(e.message)
23
- response(operation)
24
- else
25
- error(e)
26
- end
21
+ Fakeit::Logger.warn(Rainbow(e.message).red)
22
+ options.permissive ? response(operation) : error(e)
27
23
  end
28
24
 
29
25
  def error(err)
@@ -18,10 +18,14 @@ module Fakeit
18
18
  end
19
19
 
20
20
  def random_array_example(example_options)
21
- size = retries = uniqueItems ? min_array : Faker::Number.between(min_array, max_array(example_options[:depth]))
21
+ size = retries = random_array_size(example_options)
22
22
  [].tap { |result| generate_items(size, retries, example_options, result) }
23
23
  end
24
24
 
25
+ def random_array_size(example_options)
26
+ uniqueItems ? min_array : Faker::Number.between(from: min_array, to: max_array(example_options[:depth]))
27
+ end
28
+
25
29
  def generate_items(size, retries, example_options, result)
26
30
  loop do
27
31
  item = items.to_example(example_options)
@@ -35,7 +39,7 @@ module Fakeit
35
39
  end
36
40
 
37
41
  def add_depth(example_options)
38
- example_options.merge(depth: example_options[:depth] + 1)
42
+ { **example_options, depth: example_options[:depth] + 1 }
39
43
  end
40
44
 
41
45
  def need_retry?(item, result, retries)
@@ -23,7 +23,7 @@ module Fakeit
23
23
  if enum
24
24
  enum.to_a.sample
25
25
  else
26
- Faker::Number.between(int_rand_begin, int_rand_end) * int_multiple
26
+ Faker::Number.between(from: int_rand_begin, to: int_rand_end) * int_multiple
27
27
  end
28
28
  end
29
29
 
@@ -20,7 +20,7 @@ module Fakeit
20
20
  end
21
21
 
22
22
  def random_number_example
23
- (Faker::Number.between(num_rand_begin, num_rand_end) * num_multiple)
23
+ (Faker::Number.between(from: num_rand_begin, to: num_rand_end) * num_multiple)
24
24
  .then { |result| multipleOf ? result : result.round(2) }
25
25
  end
26
26
 
@@ -3,7 +3,7 @@ module Fakeit
3
3
  module Example
4
4
  def object_example(example_options)
5
5
  properties.each_with_object({}) do |(name, schema), obj|
6
- obj[name] = schema.to_example(example_options.merge(property: name))
6
+ obj[name] = schema.to_example(**example_options, property: name)
7
7
  end
8
8
  end
9
9
  end
@@ -18,8 +18,8 @@ module Fakeit
18
18
  'uuid' => -> { SecureRandom.uuid },
19
19
  'guid' => -> { SecureRandom.uuid },
20
20
  'email' => -> { Faker::Internet.email },
21
- 'date' => -> { Faker::Date.backward(100).iso8601 },
22
- 'date-time' => -> { Faker::Time.backward(100).iso8601 }
21
+ 'date' => -> { Faker::Date.backward(days: 100).iso8601 },
22
+ 'date-time' => -> { Faker::Time.backward(days: 100).iso8601 }
23
23
  }.freeze
24
24
 
25
25
  def string_example(example_options)
@@ -72,7 +72,7 @@ module Fakeit
72
72
  end
73
73
 
74
74
  def string_with_length
75
- Faker::Internet.user_name(min_string_length..max_string_length)
75
+ Faker::Internet.username(specifier: min_string_length..max_string_length)
76
76
  end
77
77
 
78
78
  def min_string_length
@@ -88,7 +88,7 @@ module Fakeit
88
88
  end
89
89
 
90
90
  def unknown_format
91
- Fakeit::Logger.warn("Unknown string format: #{format}")
91
+ Fakeit::Logger.info("Unknown string format: #{format}")
92
92
  'Unknown string format'
93
93
  end
94
94
  end
@@ -50,7 +50,7 @@ module Fakeit
50
50
  if example_options[:use_static][property: example_options[:property]]
51
51
  options
52
52
  else
53
- options.sample(Faker::Number.between(1, any_of.size))
53
+ options.sample(Faker::Number.between(from: 1, to: any_of.size))
54
54
  end
55
55
  end
56
56
  end
@@ -1,3 +1,3 @@
1
1
  module Fakeit
2
- VERSION = '0.3.0'.freeze
2
+ VERSION = '0.3.1'.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.3.0
4
+ version: 0.3.1
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-08-27 00:00:00.000000000 Z
11
+ date: 2019-09-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -114,14 +114,14 @@ dependencies:
114
114
  requirements:
115
115
  - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: '1.9'
117
+ version: '2.2'
118
118
  type: :runtime
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: '1.9'
124
+ version: '2.2'
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: openapi_parser
127
127
  requirement: !ruby/object:Gem::Requirement
@@ -164,6 +164,20 @@ dependencies:
164
164
  - - "~>"
165
165
  - !ruby/object:Gem::Version
166
166
  version: '1.0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: rainbow
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - "~>"
172
+ - !ruby/object:Gem::Version
173
+ version: '3.0'
174
+ type: :runtime
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - "~>"
179
+ - !ruby/object:Gem::Version
180
+ version: '3.0'
167
181
  - !ruby/object:Gem::Dependency
168
182
  name: slop
169
183
  requirement: !ruby/object:Gem::Requirement