fakeit 0.1.3 → 0.1.4

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: ff6943cf3f6ef0d7cfd9b8801616cc00ce82bd49adb243719ba78c412797bfbc
4
- data.tar.gz: edce957ddafc77236af8ffd4b956009c6cf5e9a1de3947ebdbf9ada1247896e4
3
+ metadata.gz: 344bca7970fbe31a7642706c26b1d1560089042cc5f85096a997b1b5b61ab602
4
+ data.tar.gz: 825a8206331071f7f6d6dfd221f8c7c6a751d07e5df27992d75b6678cf164d8b
5
5
  SHA512:
6
- metadata.gz: 61a754086fbfa0735dbdca38180533e0226e20b6f427d92a1961bfd4f2784c19da84f1fcd51de906ec911fa56b949159c6b2f2af556c8aeb48724a6916a303b8
7
- data.tar.gz: ebf54a1f98ef56275e65139a61a12d12eee120f62a2e3b0ac981ab503ac07ebf2defbf9f27bbd327f4330257ca3088de9e2a08338b06a1519ec71c1255bb929f
6
+ metadata.gz: 377bbe9ba6b54822f8be4c46364cf91acd29c86c3f28024bdf4912dc3afb1b4b31530b8fa3322cebc667d2799cbf4ed78c0dc8fb3804346db04e2b8a95148051
7
+ data.tar.gz: 3eb452a5580253f94d0d7197d65e38e65d60632ec75d86e4add2ea974334fc08db46a5520d4f318c71459496e0f5c4c7dbf04c1993d7192ff86fbd8857a6ea38
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fakeit (0.1.3)
4
+ fakeit (0.1.4)
5
5
  faker (~> 1.9)
6
6
  openapi_parser (= 0.3.0)
7
7
  rack (~> 2.0)
data/README.md CHANGED
@@ -44,6 +44,9 @@ Command line options:
44
44
  -v, --version
45
45
  -h, --help
46
46
 
47
+ **Notes:**
48
+ * Random response generation can not handle recursive schema reference. If you do need it in your spec file, please provide `example` property for the recursive part of schema and specify `--use-example` option.
49
+
47
50
  ## Development
48
51
 
49
52
  After checking out the repo, run `bundle install` to install dependencies. Then, run `rake` to run the tests.
@@ -0,0 +1,12 @@
1
+ module OpenAPIParser
2
+ module Findable
3
+ def purge_object_cache
4
+ return if @purged
5
+
6
+ @find_object_cache = {}
7
+ @purged = true
8
+
9
+ _openapi_all_child_objects.values.each(&:purge_object_cache)
10
+ end
11
+ end
12
+ end
@@ -1,31 +1,25 @@
1
1
  module Fakeit
2
2
  module Openapi
3
3
  module Example
4
- MAX_SIZE = 50
4
+ MAX_SIZE = 3
5
5
 
6
6
  def array_example(use_example)
7
7
  size = retries = uniqueItems ? min_array : Faker::Number.between(min_array, max_array)
8
-
9
- generate_items(size, retries, use_example)
8
+ [].tap { |result| generate_items(size, retries, use_example, result) }
10
9
  end
11
10
 
12
11
  private
13
12
 
14
- def generate_items(size, retries, use_example)
15
- result = []
16
-
13
+ def generate_items(size, retries, use_example, result)
17
14
  loop do
18
15
  item = items.to_example(use_example)
19
16
 
20
17
  if need_retry?(item, result, retries)
21
18
  retries -= 1
22
- next
19
+ elsif (result << item).size >= size
20
+ break
23
21
  end
24
-
25
- break if (result << item).size >= size
26
22
  end
27
-
28
- result
29
23
  end
30
24
 
31
25
  def need_retry?(item, result, retries)
@@ -4,6 +4,7 @@ module Fakeit
4
4
  FORMAT_HANDLERS = {
5
5
  'uri' => -> { Faker::Internet.url },
6
6
  'uuid' => -> { SecureRandom.uuid },
7
+ 'guid' => -> { SecureRandom.uuid },
7
8
  'email' => -> { Faker::Internet.email },
8
9
  'date' => -> { Faker::Date.backward(100).iso8601 },
9
10
  'date-time' => -> { Faker::Time.backward(100).iso8601 }
@@ -13,13 +14,17 @@ module Fakeit
13
14
  if enum then enum.to_a.sample
14
15
  elsif pattern then Faker::Base.regexify(pattern)
15
16
  elsif format then string_format
16
- elsif minLength || maxLength then string_with_length
17
+ elsif length_constraint then string_with_length
17
18
  else Faker::Book.title
18
19
  end
19
20
  end
20
21
 
21
22
  private
22
23
 
24
+ def length_constraint
25
+ minLength || maxLength
26
+ end
27
+
23
28
  def string_with_length
24
29
  Faker::Internet.user_name(min_string_length..max_string_length)
25
30
  end
@@ -14,8 +14,8 @@ module Fakeit
14
14
  def headers
15
15
  response_headers
16
16
  &.map { |k, v| [k, v.schema.to_example(@options.use_example)] }
17
- &.tap { |headers| headers.push(['Content-Type', response_content_type]) if response_content_type }
18
17
  .to_h
18
+ .tap { |headers| headers['Content-Type'] = response_content_type if response_content_type }
19
19
  end
20
20
 
21
21
  def body
@@ -1,3 +1,3 @@
1
1
  module Fakeit
2
- VERSION = '0.1.3'.freeze
2
+ VERSION = '0.1.4'.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.1.3
4
+ version: 0.1.4
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-06-16 00:00:00.000000000 Z
11
+ date: 2019-06-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -186,6 +186,7 @@ files:
186
186
  - lib/fakeit.rb
187
187
  - lib/fakeit/app/app.rb
188
188
  - lib/fakeit/app/options.rb
189
+ - lib/fakeit/core_extensions/findable.rb
189
190
  - lib/fakeit/core_extensions/schema.rb
190
191
  - lib/fakeit/logger.rb
191
192
  - lib/fakeit/middleware/recorder.rb