json_test_data 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/features/array_constraints.feature +19 -0
- data/features/data_types.feature +1 -2
- data/features/generate_data.feature +2 -2
- data/features/generate_empty_objects.feature +2 -2
- data/features/nested_objects_and_arrays.feature +4 -5
- data/features/numeric_constraints.feature +103 -0
- data/features/string_constraints.feature +40 -0
- data/lib/json_test_data/data_structures/helpers/number_helper.rb +29 -0
- data/lib/json_test_data/data_structures/number.rb +25 -0
- data/lib/json_test_data/data_structures/string.rb +10 -0
- data/lib/json_test_data/json_schema.rb +34 -23
- data/spec/json_test_data/data_structures/number_spec.rb +98 -0
- data/spec/json_test_data/data_structures/string_spec.rb +41 -0
- data/spec/json_test_data/json_schema_spec.rb +23 -9
- data/spec/matchers/number_matchers.rb +25 -0
- data/spec/spec_helper.rb +3 -0
- data/version.rb +1 -1
- metadata +18 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c078a6dd18c986157977531ebe53160ea6fa183
|
4
|
+
data.tar.gz: 7a8f4a79a68f25e98e96bc5da42b8efe051dd4fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 57ea05eca83d6adc75abad3ff3a7c2ee9d7c9271b1ade8c9043ee81f354506cd6db1e91230bb3853c1be38b44e900fe3f2c5885a5c1c8848b7fec19ddfd1ecb5
|
7
|
+
data.tar.gz: 121f3e65f8f1e1656f893abd0f36628c3dc80bb91018385fc06181912d1893c551403791d93adc009470db9a792d3a7d2ce1d69bc9f81f2089c98f4e2023a622
|
data/Gemfile.lock
CHANGED
@@ -0,0 +1,19 @@
|
|
1
|
+
Feature: Array constraints
|
2
|
+
Scenario: Minimum number of items
|
3
|
+
Given the following JSON schema:
|
4
|
+
"""json
|
5
|
+
{
|
6
|
+
"$schema": "http://json-schema.org/draft-04/schema#",
|
7
|
+
"type": "array",
|
8
|
+
"minItems": 4,
|
9
|
+
"items": {
|
10
|
+
"type": "string",
|
11
|
+
"minLength": 3
|
12
|
+
}
|
13
|
+
}
|
14
|
+
"""
|
15
|
+
When I run the JSON data generator
|
16
|
+
Then the JSON output should be:
|
17
|
+
"""json
|
18
|
+
["aaa","aaa","aaa","aaa"]
|
19
|
+
"""
|
data/features/data_types.feature
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
@wip
|
2
1
|
Feature: Handling data types
|
3
2
|
|
4
3
|
The data generated needs to have the correct properties or items, including
|
@@ -20,7 +19,7 @@ Feature: Handling data types
|
|
20
19
|
When I run the JSON data generator
|
21
20
|
Then the JSON output should be:
|
22
21
|
"""json
|
23
|
-
{"name":"
|
22
|
+
{"name":"a"}
|
24
23
|
"""
|
25
24
|
|
26
25
|
Scenario: Numbers
|
@@ -15,7 +15,7 @@ Feature: Generate test data
|
|
15
15
|
When I run the JSON data generator
|
16
16
|
Then the JSON output should be:
|
17
17
|
"""json
|
18
|
-
{"name":"
|
18
|
+
{"name":"a"}
|
19
19
|
"""
|
20
20
|
|
21
21
|
Scenario: Simple array
|
@@ -32,5 +32,5 @@ Feature: Generate test data
|
|
32
32
|
When I run the JSON data generator
|
33
33
|
Then the JSON output should be:
|
34
34
|
"""json
|
35
|
-
["
|
35
|
+
["a"]
|
36
36
|
"""
|
@@ -14,7 +14,7 @@ Feature: Generating empty objects
|
|
14
14
|
{}
|
15
15
|
"""
|
16
16
|
|
17
|
-
Scenario:
|
17
|
+
Scenario: Array with null
|
18
18
|
Given the following JSON schema:
|
19
19
|
"""json
|
20
20
|
{
|
@@ -26,5 +26,5 @@ Feature: Generating empty objects
|
|
26
26
|
When I run the JSON data generator
|
27
27
|
Then the JSON output should be:
|
28
28
|
"""json
|
29
|
-
[]
|
29
|
+
[null]
|
30
30
|
"""
|
@@ -1,4 +1,3 @@
|
|
1
|
-
@wip
|
2
1
|
Feature: Support nested objects and arrays
|
3
2
|
|
4
3
|
Scenario: Object in an array
|
@@ -26,7 +25,7 @@ Feature: Support nested objects and arrays
|
|
26
25
|
When I run the JSON data generator
|
27
26
|
Then the JSON output should be:
|
28
27
|
"""json
|
29
|
-
[{"name":"
|
28
|
+
[{"name":"a","id":1,"admin":true}]
|
30
29
|
"""
|
31
30
|
|
32
31
|
Scenario: Array in an object
|
@@ -48,7 +47,7 @@ Feature: Support nested objects and arrays
|
|
48
47
|
When I run the JSON data generator
|
49
48
|
Then the JSON output should be:
|
50
49
|
"""json
|
51
|
-
{"users":["
|
50
|
+
{"users":["a"]}
|
52
51
|
"""
|
53
52
|
|
54
53
|
Scenario: Array in an array
|
@@ -68,7 +67,7 @@ Feature: Support nested objects and arrays
|
|
68
67
|
When I run the JSON data generator
|
69
68
|
Then the JSON output should be:
|
70
69
|
"""json
|
71
|
-
[["
|
70
|
+
[["a"]]
|
72
71
|
"""
|
73
72
|
|
74
73
|
Scenario: More complex nested object
|
@@ -107,5 +106,5 @@ Feature: Support nested objects and arrays
|
|
107
106
|
When I run the JSON data generator
|
108
107
|
Then the JSON output should be:
|
109
108
|
"""json
|
110
|
-
[{"name":"
|
109
|
+
[{"name":"a","dossier":{"height_in_feet":1,"favorite_foods":["a"]},"admin":true}]
|
111
110
|
"""
|
@@ -0,0 +1,103 @@
|
|
1
|
+
Feature: Numeric constraints
|
2
|
+
Scenario: Number must be divisible by some factor
|
3
|
+
Given the following JSON schema:
|
4
|
+
"""json
|
5
|
+
{
|
6
|
+
"$schema": "http://json-schema.org/draft-04/schema#",
|
7
|
+
"type": "object",
|
8
|
+
"properties": {
|
9
|
+
"widgets": {
|
10
|
+
"type": "integer",
|
11
|
+
"multipleOf": 2
|
12
|
+
}
|
13
|
+
}
|
14
|
+
}
|
15
|
+
"""
|
16
|
+
When I run the JSON data generator
|
17
|
+
Then the JSON output should be:
|
18
|
+
"""json
|
19
|
+
{"widgets":2}
|
20
|
+
"""
|
21
|
+
|
22
|
+
Scenario: Number has a maximum value
|
23
|
+
Given the following JSON schema:
|
24
|
+
"""json
|
25
|
+
{
|
26
|
+
"$schema": "http://json-schema.org/draft-04/schema#",
|
27
|
+
"type": "object",
|
28
|
+
"properties": {
|
29
|
+
"proportion": {
|
30
|
+
"type": "number",
|
31
|
+
"maximum": 0.25
|
32
|
+
}
|
33
|
+
}
|
34
|
+
}
|
35
|
+
"""
|
36
|
+
When I run the JSON data generator
|
37
|
+
Then the JSON output should be:
|
38
|
+
"""json
|
39
|
+
{"proportion":0.0}
|
40
|
+
"""
|
41
|
+
|
42
|
+
Scenario: Number has a minimum value
|
43
|
+
Given the following JSON schema:
|
44
|
+
"""json
|
45
|
+
{
|
46
|
+
"$schema": "http://json-schema.org/draft-04/schema#",
|
47
|
+
"type": "object",
|
48
|
+
"properties": {
|
49
|
+
"quantity": {
|
50
|
+
"type": "integer",
|
51
|
+
"minimum": 2
|
52
|
+
}
|
53
|
+
}
|
54
|
+
}
|
55
|
+
"""
|
56
|
+
When I run the JSON data generator
|
57
|
+
Then the JSON output should be:
|
58
|
+
"""json
|
59
|
+
{"quantity":3}
|
60
|
+
"""
|
61
|
+
|
62
|
+
Scenario: Maximum and minimum
|
63
|
+
Given the following JSON schema:
|
64
|
+
"""json
|
65
|
+
{
|
66
|
+
"$schema": "http://json-schema.org/draft-04/schema#",
|
67
|
+
"type": "object",
|
68
|
+
"properties": {
|
69
|
+
"proportion": {
|
70
|
+
"type": "number",
|
71
|
+
"maximum": 1,
|
72
|
+
"minimum": 0,
|
73
|
+
"exclusiveMinimum": true
|
74
|
+
}
|
75
|
+
}
|
76
|
+
}
|
77
|
+
"""
|
78
|
+
When I run the JSON data generator
|
79
|
+
Then the JSON output should be:
|
80
|
+
"""json
|
81
|
+
{"proportion":0.5}
|
82
|
+
"""
|
83
|
+
|
84
|
+
Scenario: Multiple with minimum
|
85
|
+
Given the following JSON schema:
|
86
|
+
"""json
|
87
|
+
{
|
88
|
+
"$schema": "http://json-schema.org/draft-04/schema#",
|
89
|
+
"type": "object",
|
90
|
+
"properties": {
|
91
|
+
"wheels": {
|
92
|
+
"type": "number",
|
93
|
+
"multipleOf": 4,
|
94
|
+
"minimum": 5
|
95
|
+
}
|
96
|
+
}
|
97
|
+
}
|
98
|
+
"""
|
99
|
+
When I run the JSON data generator
|
100
|
+
Then the JSON output should be:
|
101
|
+
"""json
|
102
|
+
{"wheels":8}
|
103
|
+
"""
|
@@ -0,0 +1,40 @@
|
|
1
|
+
Feature: String constraints
|
2
|
+
Scenario: Maximum length is short
|
3
|
+
Given the following JSON schema:
|
4
|
+
"""json
|
5
|
+
{
|
6
|
+
"$schema": "http://json-schema.org/draft-04/schema#",
|
7
|
+
"type": "object",
|
8
|
+
"properties": {
|
9
|
+
"name": {
|
10
|
+
"type": "string",
|
11
|
+
"maxLength": 2
|
12
|
+
}
|
13
|
+
}
|
14
|
+
}
|
15
|
+
"""
|
16
|
+
When I run the JSON data generator
|
17
|
+
Then the JSON output should be:
|
18
|
+
"""json
|
19
|
+
{"name":"aa"}
|
20
|
+
"""
|
21
|
+
|
22
|
+
Scenario: Minimum length is long
|
23
|
+
Given the following JSON schema:
|
24
|
+
"""json
|
25
|
+
{
|
26
|
+
"$schema": "http://json-schema.org/draft-04/schema#",
|
27
|
+
"type": "object",
|
28
|
+
"properties": {
|
29
|
+
"name": {
|
30
|
+
"type": "string",
|
31
|
+
"minLength": 8
|
32
|
+
}
|
33
|
+
}
|
34
|
+
}
|
35
|
+
"""
|
36
|
+
When I run the JSON data generator
|
37
|
+
Then the JSON output should be:
|
38
|
+
"""json
|
39
|
+
{"name":"aaaaaaaa"}
|
40
|
+
"""
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module JsonTestData
|
2
|
+
module NumberHelper
|
3
|
+
def adjust_for_maximum(number:, maximum: nil, step_size: nil)
|
4
|
+
return number unless (maximum && number >= maximum)
|
5
|
+
|
6
|
+
num = !!step_size ? number - step_size : maximum - 1
|
7
|
+
adjust_for_maximum(number: num, maximum: maximum, step_size: step_size)
|
8
|
+
end
|
9
|
+
|
10
|
+
def adjust_for_minimum(number:, minimum:, step_size: nil)
|
11
|
+
return number unless minimum && minimum >= number
|
12
|
+
|
13
|
+
num = !!step_size ? number + step_size : minimum + 1
|
14
|
+
adjust_for_minimum(number: num, minimum: minimum, step_size: step_size)
|
15
|
+
end
|
16
|
+
|
17
|
+
def between(min:, max:, integer: false)
|
18
|
+
return integer ? mean(min, max).to_i : mean(min, max)
|
19
|
+
end
|
20
|
+
|
21
|
+
def mean(*numbers)
|
22
|
+
numbers.inject(:+).to_f.quo(numbers.length)
|
23
|
+
end
|
24
|
+
|
25
|
+
def infinity
|
26
|
+
Math.atanh(1)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require_relative "./helpers/number_helper"
|
2
|
+
|
3
|
+
module JsonTestData
|
4
|
+
class Number
|
5
|
+
extend NumberHelper
|
6
|
+
|
7
|
+
class << self
|
8
|
+
def create(schema)
|
9
|
+
factor = schema.fetch(:multipleOf, nil)
|
10
|
+
minimum, maximum = schema.fetch(:minimum, nil), schema.fetch(:maximum, nil)
|
11
|
+
|
12
|
+
num = if maximum && minimum
|
13
|
+
between(min: minimum, max: maximum, integer: schema.fetch(:type) == "")
|
14
|
+
else
|
15
|
+
factor || 1
|
16
|
+
end
|
17
|
+
|
18
|
+
step_size = schema.fetch(:type) == "integer" ? 1 : 0.5
|
19
|
+
|
20
|
+
num = adjust_for_maximum(number: num, maximum: maximum, step_size: factor || step_size)
|
21
|
+
adjust_for_minimum(number: num, minimum: minimum, step_size: factor || step_size)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -1,3 +1,6 @@
|
|
1
|
+
require_relative "./data_structures/string"
|
2
|
+
require_relative "./data_structures/number"
|
3
|
+
|
1
4
|
module JsonTestData
|
2
5
|
class JsonSchema
|
3
6
|
attr_accessor :schema
|
@@ -7,53 +10,61 @@ module JsonTestData
|
|
7
10
|
end
|
8
11
|
|
9
12
|
def generate_example
|
10
|
-
|
13
|
+
generate(schema).to_json
|
11
14
|
end
|
12
15
|
|
13
16
|
private
|
14
|
-
def
|
15
|
-
case type
|
17
|
+
def generate_data(obj)
|
18
|
+
case obj.fetch(:type)
|
16
19
|
when "number"
|
17
|
-
|
20
|
+
JsonTestData::Number.create(obj)
|
18
21
|
when "integer"
|
19
|
-
|
22
|
+
JsonTestData::Number.create(obj)
|
20
23
|
when "boolean"
|
21
24
|
true
|
22
25
|
when "string"
|
23
|
-
|
26
|
+
JsonTestData::String.create(obj)
|
24
27
|
end
|
25
28
|
end
|
26
29
|
|
30
|
+
def generate(obj)
|
31
|
+
if is_object?(obj)
|
32
|
+
generate_object(obj)
|
33
|
+
elsif is_array?(obj)
|
34
|
+
generate_array(obj)
|
35
|
+
else
|
36
|
+
generate_data(obj)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def is_object?(property)
|
41
|
+
property.fetch(:type, nil) == "object"
|
42
|
+
end
|
43
|
+
|
44
|
+
def is_array?(property)
|
45
|
+
property.fetch(:type, nil) == "array"
|
46
|
+
end
|
47
|
+
|
27
48
|
def generate_object(object)
|
28
49
|
obj = {}
|
29
50
|
|
30
51
|
object.fetch(:properties).each do |k, v|
|
31
52
|
obj[k] = nil unless v.has_key?(:type)
|
32
53
|
|
33
|
-
obj[k] =
|
34
|
-
generate_object(v)
|
35
|
-
elsif v.fetch(:type) == "array"
|
36
|
-
generate_array(v)
|
37
|
-
else
|
38
|
-
object_of_type(v.fetch(:type))
|
39
|
-
end
|
54
|
+
obj[k] = generate(v)
|
40
55
|
end
|
41
56
|
|
42
57
|
obj
|
43
58
|
end
|
44
59
|
|
45
60
|
def generate_array(object)
|
46
|
-
|
61
|
+
object.fetch(:minItems, nil) || object[:minItems] = 1
|
47
62
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
object_of_type(object.fetch(:items).fetch(:type))
|
54
|
-
end
|
55
|
-
|
56
|
-
[val].compact
|
63
|
+
if object.fetch(:items, nil) && object.fetch(:items).has_key?(:type)
|
64
|
+
Array.new(object.fetch(:minItems), generate(object.fetch(:items))).compact
|
65
|
+
else
|
66
|
+
Array.new(object.fetch(:minItems))
|
67
|
+
end
|
57
68
|
end
|
58
69
|
end
|
59
70
|
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
describe JsonTestData::Number do
|
2
|
+
describe ".create" do
|
3
|
+
context "normal" do
|
4
|
+
let(:object) do
|
5
|
+
{
|
6
|
+
type: "number"
|
7
|
+
}
|
8
|
+
end
|
9
|
+
|
10
|
+
it "returns 1" do
|
11
|
+
expect(described_class.create(object)).to eql 1
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context "multipleOf constraint" do
|
16
|
+
let(:factor) { 2 }
|
17
|
+
let(:object) do
|
18
|
+
{
|
19
|
+
type: "number",
|
20
|
+
multipleOf: factor
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
it "returns a multiple of the given number" do
|
25
|
+
expect(described_class.create(object)).to be_a_multiple_of(factor)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context "maximum constraint" do
|
30
|
+
let(:maximum) { 0.5 }
|
31
|
+
let(:object) do
|
32
|
+
{
|
33
|
+
type: "number",
|
34
|
+
maximum: maximum
|
35
|
+
}
|
36
|
+
end
|
37
|
+
|
38
|
+
it "returns a value less than the maximum" do
|
39
|
+
expect(described_class.create(object)).to be_less_than_or_equal_to(maximum)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context "minimum constraint" do
|
44
|
+
let(:minimum) { 2 }
|
45
|
+
let(:object) do
|
46
|
+
{
|
47
|
+
type: "number",
|
48
|
+
minimum: minimum
|
49
|
+
}
|
50
|
+
end
|
51
|
+
|
52
|
+
it "returns a value greater than the minimum" do
|
53
|
+
expect(described_class.create(object)).to be_greater_than_or_equal_to(minimum)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context "multiple constraints" do
|
58
|
+
context "maximum and minimum" do
|
59
|
+
let(:maximum) { 1 }
|
60
|
+
let(:minimum) { 0 }
|
61
|
+
let(:object) do
|
62
|
+
{
|
63
|
+
type: "number",
|
64
|
+
minimum: minimum,
|
65
|
+
maximum: maximum,
|
66
|
+
exclusiveMinimum: true
|
67
|
+
}
|
68
|
+
end
|
69
|
+
|
70
|
+
it "returns a value between the maximum and the minimum" do
|
71
|
+
aggregate_failures do
|
72
|
+
expect(described_class.create(object)).to be_greater_than(minimum)
|
73
|
+
expect(described_class.create(object)).to be_less_than_or_equal_to(maximum)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
context "minimum and multiple" do
|
79
|
+
let(:factor) { 2 }
|
80
|
+
let(:minimum) { 3 }
|
81
|
+
let(:object) do
|
82
|
+
{
|
83
|
+
type: "number",
|
84
|
+
multipleOf: factor,
|
85
|
+
minimum: minimum
|
86
|
+
}
|
87
|
+
end
|
88
|
+
|
89
|
+
it "returns the next lowest multiple" do
|
90
|
+
aggregate_failures do
|
91
|
+
expect(described_class.create(object)).to be_a_multiple_of(factor)
|
92
|
+
expect(described_class.create(object)).to be_greater_than(minimum)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
describe JsonTestData::String do
|
2
|
+
describe ".create" do
|
3
|
+
context "normal" do
|
4
|
+
let(:object) do
|
5
|
+
{
|
6
|
+
type: "string"
|
7
|
+
}
|
8
|
+
end
|
9
|
+
|
10
|
+
it "returns 'a'" do
|
11
|
+
expect(described_class.create(object)).to eq "a"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context "with maximum length" do
|
16
|
+
let(:object) do
|
17
|
+
{
|
18
|
+
type: "string",
|
19
|
+
maxLength: 2
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
it "returns 'aa'" do
|
24
|
+
expect(described_class.create(object)).to eq "aa"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context "with minimum length" do
|
29
|
+
let(:object) do
|
30
|
+
{
|
31
|
+
type: "string",
|
32
|
+
minLength: 8
|
33
|
+
}
|
34
|
+
end
|
35
|
+
|
36
|
+
it "returns 'aaaaaaaa'" do
|
37
|
+
expect(described_class.create(object)).to eq "aaaaaaaa"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -18,7 +18,6 @@ describe JsonTestData::JsonSchema do
|
|
18
18
|
describe "#generate_example" do
|
19
19
|
describe "trivial examples" do
|
20
20
|
context "when schema describes an object" do
|
21
|
-
|
22
21
|
let(:schema) do
|
23
22
|
JsonTestData::JsonSchema.new(
|
24
23
|
{
|
@@ -39,7 +38,6 @@ describe JsonTestData::JsonSchema do
|
|
39
38
|
end
|
40
39
|
|
41
40
|
context "when schema describes an array" do
|
42
|
-
|
43
41
|
let(:schema) do
|
44
42
|
JsonTestData::JsonSchema.new(
|
45
43
|
{
|
@@ -51,10 +49,10 @@ describe JsonTestData::JsonSchema do
|
|
51
49
|
end
|
52
50
|
|
53
51
|
let(:output) do
|
54
|
-
[].to_json
|
52
|
+
[nil].to_json
|
55
53
|
end
|
56
54
|
|
57
|
-
it "generates an
|
55
|
+
it "generates an array" do
|
58
56
|
expect(schema.generate_example).to eql output
|
59
57
|
end
|
60
58
|
end
|
@@ -76,7 +74,7 @@ describe JsonTestData::JsonSchema do
|
|
76
74
|
end
|
77
75
|
|
78
76
|
let(:output) do
|
79
|
-
{
|
77
|
+
{ :name => "a" }.to_json
|
80
78
|
end
|
81
79
|
|
82
80
|
it "generates the right object" do
|
@@ -97,7 +95,7 @@ describe JsonTestData::JsonSchema do
|
|
97
95
|
end
|
98
96
|
|
99
97
|
let(:output) do
|
100
|
-
["
|
98
|
+
["a"].to_json
|
101
99
|
end
|
102
100
|
|
103
101
|
it "generates the right object" do
|
@@ -199,7 +197,7 @@ describe JsonTestData::JsonSchema do
|
|
199
197
|
end
|
200
198
|
|
201
199
|
let(:output) do
|
202
|
-
{:users => ["
|
200
|
+
{:users => ["a"]}.to_json
|
203
201
|
end
|
204
202
|
|
205
203
|
it "nests the object" do
|
@@ -209,7 +207,6 @@ describe JsonTestData::JsonSchema do
|
|
209
207
|
end
|
210
208
|
|
211
209
|
context "arrays in arrays" do
|
212
|
-
|
213
210
|
let(:schema) do
|
214
211
|
{
|
215
212
|
:"$schema" => "http://json-schema.org/draft-04/schema#",
|
@@ -224,7 +221,7 @@ describe JsonTestData::JsonSchema do
|
|
224
221
|
end
|
225
222
|
|
226
223
|
let(:output) do
|
227
|
-
[["
|
224
|
+
[["a"]].to_json
|
228
225
|
end
|
229
226
|
|
230
227
|
it "returns a nested array" do
|
@@ -233,5 +230,22 @@ describe JsonTestData::JsonSchema do
|
|
233
230
|
end
|
234
231
|
end
|
235
232
|
end
|
233
|
+
|
234
|
+
describe "arrays with constraints" do
|
235
|
+
context "array with minimum number of items" do
|
236
|
+
let(:schema) do
|
237
|
+
{
|
238
|
+
:"$schema" => "http://json-schema.org/draft-04/schema#",
|
239
|
+
:type => "array",
|
240
|
+
:minItems => 3
|
241
|
+
}.to_json
|
242
|
+
end
|
243
|
+
|
244
|
+
it "returns an array of the correct length" do
|
245
|
+
json_schema = JsonTestData::JsonSchema.new(schema)
|
246
|
+
expect(json_schema.generate_example).to eql [nil, nil, nil].to_json
|
247
|
+
end
|
248
|
+
end
|
249
|
+
end
|
236
250
|
end
|
237
251
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require "rspec/expectations"
|
2
|
+
|
3
|
+
RSpec::Matchers.define :be_a_multiple_of do |expected|
|
4
|
+
match do |actual|
|
5
|
+
actual % expected == 0
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
RSpec::Matchers.define :be_greater_than do |expected|
|
10
|
+
match do |actual|
|
11
|
+
actual > expected
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
RSpec::Matchers.define :be_less_than_or_equal_to do |expected|
|
16
|
+
match do |actual|
|
17
|
+
actual <= expected
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
RSpec::Matchers.define :be_greater_than_or_equal_to do |expected|
|
22
|
+
match do |actual|
|
23
|
+
actual >= expected
|
24
|
+
end
|
25
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -6,6 +6,9 @@ require "pry"
|
|
6
6
|
|
7
7
|
require_relative "../lib/json_test_data"
|
8
8
|
require_relative "../lib/json_test_data/json_schema"
|
9
|
+
require_relative "../lib/json_test_data/data_structures/string"
|
10
|
+
require_relative "../lib/json_test_data/data_structures/number"
|
11
|
+
require_relative "./matchers/number_matchers"
|
9
12
|
|
10
13
|
RSpec.configure do |config|
|
11
14
|
config.expect_with :rspec do |expectations|
|
data/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: json_test_data
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dana Scheider
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-04-
|
11
|
+
date: 2016-04-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cucumber
|
@@ -121,16 +121,25 @@ files:
|
|
121
121
|
- LICENSE
|
122
122
|
- README.md
|
123
123
|
- Rakefile
|
124
|
+
- features/array_constraints.feature
|
124
125
|
- features/data_types.feature
|
125
126
|
- features/generate_data.feature
|
126
127
|
- features/generate_empty_objects.feature
|
127
128
|
- features/nested_objects_and_arrays.feature
|
129
|
+
- features/numeric_constraints.feature
|
128
130
|
- features/step_definitions/json_test_data_steps.rb
|
131
|
+
- features/string_constraints.feature
|
129
132
|
- features/support/env.rb
|
130
133
|
- json_test_data.gemspec
|
131
134
|
- lib/json_test_data.rb
|
135
|
+
- lib/json_test_data/data_structures/helpers/number_helper.rb
|
136
|
+
- lib/json_test_data/data_structures/number.rb
|
137
|
+
- lib/json_test_data/data_structures/string.rb
|
132
138
|
- lib/json_test_data/json_schema.rb
|
139
|
+
- spec/json_test_data/data_structures/number_spec.rb
|
140
|
+
- spec/json_test_data/data_structures/string_spec.rb
|
133
141
|
- spec/json_test_data/json_schema_spec.rb
|
142
|
+
- spec/matchers/number_matchers.rb
|
134
143
|
- spec/spec_helper.rb
|
135
144
|
- version.rb
|
136
145
|
homepage:
|
@@ -157,14 +166,20 @@ rubyforge_project:
|
|
157
166
|
rubygems_version: 2.4.6
|
158
167
|
signing_key:
|
159
168
|
specification_version: 4
|
160
|
-
summary: rambo-0.0
|
169
|
+
summary: rambo-0.1.0
|
161
170
|
test_files:
|
171
|
+
- features/array_constraints.feature
|
162
172
|
- features/data_types.feature
|
163
173
|
- features/generate_data.feature
|
164
174
|
- features/generate_empty_objects.feature
|
165
175
|
- features/nested_objects_and_arrays.feature
|
176
|
+
- features/numeric_constraints.feature
|
166
177
|
- features/step_definitions/json_test_data_steps.rb
|
178
|
+
- features/string_constraints.feature
|
167
179
|
- features/support/env.rb
|
180
|
+
- spec/json_test_data/data_structures/number_spec.rb
|
181
|
+
- spec/json_test_data/data_structures/string_spec.rb
|
168
182
|
- spec/json_test_data/json_schema_spec.rb
|
183
|
+
- spec/matchers/number_matchers.rb
|
169
184
|
- spec/spec_helper.rb
|
170
185
|
has_rdoc:
|