fakeit 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -0
- data/Gemfile.lock +1 -1
- data/README.md +6 -1
- data/fakeit.gemspec +2 -0
- data/lib/fakeit/openapi/example/array_example.rb +33 -2
- data/lib/fakeit/openapi/example/integer_example.rb +17 -1
- data/lib/fakeit/openapi/example/number_example.rb +13 -1
- data/lib/fakeit/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ff6943cf3f6ef0d7cfd9b8801616cc00ce82bd49adb243719ba78c412797bfbc
|
4
|
+
data.tar.gz: edce957ddafc77236af8ffd4b956009c6cf5e9a1de3947ebdbf9ada1247896e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 61a754086fbfa0735dbdca38180533e0226e20b6f427d92a1961bfd4f2784c19da84f1fcd51de906ec911fa56b949159c6b2f2af556c8aeb48724a6916a303b8
|
7
|
+
data.tar.gz: ebf54a1f98ef56275e65139a61a12d12eee120f62a2e3b0ac981ab503ac07ebf2defbf9f27bbd327f4330257ca3088de9e2a08338b06a1519ec71c1255bb929f
|
data/.rubocop.yml
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
# Fakeit
|
2
2
|
|
3
|
-
[![CircleCI](https://
|
3
|
+
[![CircleCI](https://img.shields.io/circleci/build/github/JustinFeng/fakeit.svg)](https://circleci.com/gh/JustinFeng/fakeit)
|
4
|
+
[![Code Climate maintainability](https://img.shields.io/codeclimate/maintainability/JustinFeng/fakeit.svg)](https://codeclimate.com/github/JustinFeng/fakeit)
|
5
|
+
[![Gem](https://img.shields.io/gem/v/fakeit.svg)](https://rubygems.org/gems/fakeit)
|
6
|
+
[![Gem](https://img.shields.io/gem/dt/fakeit.svg)](https://rubygems.org/gems/fakeit)
|
7
|
+
[![Docker Pulls](https://img.shields.io/docker/pulls/realfengjia/fakeit.svg)](https://hub.docker.com/r/realfengjia/fakeit)
|
8
|
+
[![GitHub](https://img.shields.io/github/license/JustinFeng/fakeit.svg)](https://opensource.org/licenses/MIT)
|
4
9
|
|
5
10
|
Create mock server from Openapi specification
|
6
11
|
|
data/fakeit.gemspec
CHANGED
@@ -22,6 +22,8 @@ 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'
|
26
|
+
|
25
27
|
spec.add_development_dependency 'bundler', '~> 2.0'
|
26
28
|
spec.add_development_dependency 'byebug', '~> 11.0'
|
27
29
|
spec.add_development_dependency 'rack-test', '~> 1.1'
|
@@ -4,9 +4,40 @@ module Fakeit
|
|
4
4
|
MAX_SIZE = 50
|
5
5
|
|
6
6
|
def array_example(use_example)
|
7
|
-
|
8
|
-
|
7
|
+
size = retries = uniqueItems ? min_array : Faker::Number.between(min_array, max_array)
|
8
|
+
|
9
|
+
generate_items(size, retries, use_example)
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def generate_items(size, retries, use_example)
|
15
|
+
result = []
|
16
|
+
|
17
|
+
loop do
|
18
|
+
item = items.to_example(use_example)
|
19
|
+
|
20
|
+
if need_retry?(item, result, retries)
|
21
|
+
retries -= 1
|
22
|
+
next
|
23
|
+
end
|
24
|
+
|
25
|
+
break if (result << item).size >= size
|
9
26
|
end
|
27
|
+
|
28
|
+
result
|
29
|
+
end
|
30
|
+
|
31
|
+
def need_retry?(item, result, retries)
|
32
|
+
uniqueItems && result.include?(item) && retries.positive?
|
33
|
+
end
|
34
|
+
|
35
|
+
def min_array
|
36
|
+
minItems || 1
|
37
|
+
end
|
38
|
+
|
39
|
+
def max_array
|
40
|
+
maxItems || MAX_SIZE
|
10
41
|
end
|
11
42
|
end
|
12
43
|
end
|
@@ -7,12 +7,28 @@ module Fakeit
|
|
7
7
|
if enum
|
8
8
|
enum.to_a.sample
|
9
9
|
else
|
10
|
-
Faker::Number.between(
|
10
|
+
Faker::Number.between(int_rand_begin, int_rand_end) * int_multiple
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
14
|
private
|
15
15
|
|
16
|
+
def int_rand_begin
|
17
|
+
min_int / int_multiple + int_rand_begin_adjust
|
18
|
+
end
|
19
|
+
|
20
|
+
def int_rand_end
|
21
|
+
max_int / int_multiple
|
22
|
+
end
|
23
|
+
|
24
|
+
def int_rand_begin_adjust
|
25
|
+
(min_int % int_multiple).zero? ? 0 : 1
|
26
|
+
end
|
27
|
+
|
28
|
+
def int_multiple
|
29
|
+
multipleOf || 1
|
30
|
+
end
|
31
|
+
|
16
32
|
def min_int
|
17
33
|
if minimum
|
18
34
|
exclusiveMinimum ? minimum + 1 : minimum
|
@@ -4,11 +4,23 @@ module Fakeit
|
|
4
4
|
BIG_NUM = 2**32
|
5
5
|
|
6
6
|
def number_example
|
7
|
-
Faker::Number.between(
|
7
|
+
(Faker::Number.between(num_rand_begin, num_rand_end) * num_multiple).round(2)
|
8
8
|
end
|
9
9
|
|
10
10
|
private
|
11
11
|
|
12
|
+
def num_rand_begin
|
13
|
+
multipleOf ? (min_num / multipleOf).ceil : min_num
|
14
|
+
end
|
15
|
+
|
16
|
+
def num_rand_end
|
17
|
+
multipleOf ? (max_num / multipleOf).floor : max_num
|
18
|
+
end
|
19
|
+
|
20
|
+
def num_multiple
|
21
|
+
multipleOf || 1
|
22
|
+
end
|
23
|
+
|
12
24
|
def min_num
|
13
25
|
(minimum || 0).to_f.ceil(2)
|
14
26
|
end
|
data/lib/fakeit/version.rb
CHANGED
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.
|
4
|
+
version: 0.1.3
|
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-
|
11
|
+
date: 2019-06-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -214,7 +214,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
214
214
|
requirements:
|
215
215
|
- - ">="
|
216
216
|
- !ruby/object:Gem::Version
|
217
|
-
version:
|
217
|
+
version: 2.6.0
|
218
218
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
219
219
|
requirements:
|
220
220
|
- - ">="
|