json_test_data 0.1.0 → 0.3.0.beta
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +3 -1
- data/README.md +3 -1
- data/features/array_constraints.feature +2 -2
- data/features/data_types.feature +1 -4
- data/features/generate_data.feature +5 -5
- data/features/nested_objects_and_arrays.feature +9 -12
- data/features/object_constraints.feature +28 -0
- data/features/step_definitions/json_test_data_steps.rb +14 -0
- data/features/string_constraints.feature +2 -8
- data/json_test_data.gemspec +10 -8
- data/lib/json_test_data/data_structures/string.rb +5 -1
- data/lib/json_test_data/json_schema.rb +13 -4
- data/spec/json_test_data/data_structures/string_spec.rb +10 -6
- data/spec/json_test_data/json_schema_spec.rb +8 -8
- data/version.rb +1 -1
- metadata +22 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 85db2f952ca98ddbca0f39241f90ea5669ef7bac
|
4
|
+
data.tar.gz: 3cefe7526dc7b105bb76b743a84248332f776cee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3a3b9d10f9a62e8b49c79e5c4db3a91e4b4ee1394ad5ae9414659c2daa974a381b56540f8f3da032ffa6ce2d838dccca20c741ffb1d798440ddb432ba40bca2d
|
7
|
+
data.tar.gz: 4dbbfa3e6edca85a32844bc0c516a06c8c1ad4ea693fac7a207e3d3a984ccb26d5cc92a1c1e0f30d7b5d3a876ea073fa153900cca22b437c44a24d947f61f0a2
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
json_test_data (0.0.
|
4
|
+
json_test_data (0.2.0.beta)
|
5
|
+
regxing (~> 0.1.0.beta)
|
5
6
|
|
6
7
|
GEM
|
7
8
|
remote: https://rubygems.org/
|
@@ -37,6 +38,7 @@ GEM
|
|
37
38
|
method_source (~> 0.8.1)
|
38
39
|
slop (~> 3.4)
|
39
40
|
rake (10.5.0)
|
41
|
+
regxing (0.1.0.beta)
|
40
42
|
rspec (3.4.0)
|
41
43
|
rspec-core (~> 3.4.0)
|
42
44
|
rspec-expectations (~> 3.4.0)
|
data/README.md
CHANGED
@@ -15,5 +15,7 @@ To use it, first require it, then generate the test data using:
|
|
15
15
|
data = JsonTestData.generate!
|
16
16
|
```
|
17
17
|
|
18
|
+
The input that you put into it must be valid [JSON schema](http://json-schema.org). The top-level object must have a `:type` key indicating the type of object to be generated ("object", "array", "string", etc.).
|
19
|
+
|
18
20
|
## Contribute
|
19
|
-
The JSON Test Data Generator is in its infancy and contributions are much appreciated. Please include passing tests with all pull requests, and file an issue report indicating what you'd like to work on. I'm also happy to get issue reports that do not come with pull requests, but can't guarantee I'll actually write whatever it is you want JSON Test Data to do.
|
21
|
+
The JSON Test Data Generator is in its infancy and contributions are much appreciated. Please include passing tests with all pull requests, and file an issue report indicating what you'd like to work on. I'm also happy to get issue reports that do not come with pull requests, but can't guarantee I'll actually write whatever it is you want JSON Test Data to do. I strongly encourage pull requests adding documentation!
|
@@ -7,7 +7,7 @@ Feature: Array constraints
|
|
7
7
|
"type": "array",
|
8
8
|
"minItems": 4,
|
9
9
|
"items": {
|
10
|
-
"type": "
|
10
|
+
"type": "number",
|
11
11
|
"minLength": 3
|
12
12
|
}
|
13
13
|
}
|
@@ -15,5 +15,5 @@ Feature: Array constraints
|
|
15
15
|
When I run the JSON data generator
|
16
16
|
Then the JSON output should be:
|
17
17
|
"""json
|
18
|
-
[
|
18
|
+
[1,1,1,1]
|
19
19
|
"""
|
data/features/data_types.feature
CHANGED
@@ -17,10 +17,7 @@ Feature: Handling data types
|
|
17
17
|
}
|
18
18
|
"""
|
19
19
|
When I run the JSON data generator
|
20
|
-
Then the JSON output should be
|
21
|
-
"""json
|
22
|
-
{"name":"a"}
|
23
|
-
"""
|
20
|
+
Then the "name" property of the JSON output should be a String
|
24
21
|
|
25
22
|
Scenario: Numbers
|
26
23
|
Given the following JSON schema:
|
@@ -6,8 +6,8 @@ Feature: Generate test data
|
|
6
6
|
"$schema": "http://json-schema.org/draft-04/schema#",
|
7
7
|
"type": "object",
|
8
8
|
"properties": {
|
9
|
-
"
|
10
|
-
"type": "
|
9
|
+
"id": {
|
10
|
+
"type": "number"
|
11
11
|
}
|
12
12
|
}
|
13
13
|
}
|
@@ -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
|
-
{"
|
18
|
+
{"id":1}
|
19
19
|
"""
|
20
20
|
|
21
21
|
Scenario: Simple array
|
@@ -25,12 +25,12 @@ Feature: Generate test data
|
|
25
25
|
"$schema": "http://json-schema.org/draft-04/schema#",
|
26
26
|
"type": "array",
|
27
27
|
"items": {
|
28
|
-
"type": "
|
28
|
+
"type": "number"
|
29
29
|
}
|
30
30
|
}
|
31
31
|
"""
|
32
32
|
When I run the JSON data generator
|
33
33
|
Then the JSON output should be:
|
34
34
|
"""json
|
35
|
-
[
|
35
|
+
[1]
|
36
36
|
"""
|
@@ -9,9 +9,6 @@ Feature: Support nested objects and arrays
|
|
9
9
|
"items": {
|
10
10
|
"type": "object",
|
11
11
|
"properties": {
|
12
|
-
"name": {
|
13
|
-
"type": "string"
|
14
|
-
},
|
15
12
|
"id": {
|
16
13
|
"type": "integer"
|
17
14
|
},
|
@@ -25,7 +22,7 @@ Feature: Support nested objects and arrays
|
|
25
22
|
When I run the JSON data generator
|
26
23
|
Then the JSON output should be:
|
27
24
|
"""json
|
28
|
-
[{"
|
25
|
+
[{"id":1,"admin":true}]
|
29
26
|
"""
|
30
27
|
|
31
28
|
Scenario: Array in an object
|
@@ -38,7 +35,7 @@ Feature: Support nested objects and arrays
|
|
38
35
|
"users": {
|
39
36
|
"type": "array",
|
40
37
|
"items": {
|
41
|
-
"type": "
|
38
|
+
"type": "number"
|
42
39
|
}
|
43
40
|
}
|
44
41
|
}
|
@@ -47,7 +44,7 @@ Feature: Support nested objects and arrays
|
|
47
44
|
When I run the JSON data generator
|
48
45
|
Then the JSON output should be:
|
49
46
|
"""json
|
50
|
-
{"users":[
|
47
|
+
{"users":[1]}
|
51
48
|
"""
|
52
49
|
|
53
50
|
Scenario: Array in an array
|
@@ -59,7 +56,7 @@ Feature: Support nested objects and arrays
|
|
59
56
|
"items": {
|
60
57
|
"type": "array",
|
61
58
|
"items": {
|
62
|
-
"type": "
|
59
|
+
"type": "number"
|
63
60
|
}
|
64
61
|
}
|
65
62
|
}
|
@@ -67,7 +64,7 @@ Feature: Support nested objects and arrays
|
|
67
64
|
When I run the JSON data generator
|
68
65
|
Then the JSON output should be:
|
69
66
|
"""json
|
70
|
-
[[
|
67
|
+
[[1]]
|
71
68
|
"""
|
72
69
|
|
73
70
|
Scenario: More complex nested object
|
@@ -79,8 +76,8 @@ Feature: Support nested objects and arrays
|
|
79
76
|
"items": {
|
80
77
|
"type": "object",
|
81
78
|
"properties": {
|
82
|
-
"
|
83
|
-
"type": "
|
79
|
+
"id": {
|
80
|
+
"type": "number"
|
84
81
|
},
|
85
82
|
"dossier": {
|
86
83
|
"type": "object",
|
@@ -91,7 +88,7 @@ Feature: Support nested objects and arrays
|
|
91
88
|
"favorite_foods": {
|
92
89
|
"type": "array",
|
93
90
|
"items": {
|
94
|
-
"type": "
|
91
|
+
"type": "number"
|
95
92
|
}
|
96
93
|
}
|
97
94
|
}
|
@@ -106,5 +103,5 @@ Feature: Support nested objects and arrays
|
|
106
103
|
When I run the JSON data generator
|
107
104
|
Then the JSON output should be:
|
108
105
|
"""json
|
109
|
-
[{"
|
106
|
+
[{"id":1,"dossier":{"height_in_feet":1,"favorite_foods":[1]},"admin":true}]
|
110
107
|
"""
|
@@ -0,0 +1,28 @@
|
|
1
|
+
Feature: Object constraints
|
2
|
+
Scenario: Object has no specified properties
|
3
|
+
Given the following JSON schema:
|
4
|
+
"""json
|
5
|
+
{
|
6
|
+
"$schema": "http://json-schema.org/draft-04/schema#",
|
7
|
+
"type": "object"
|
8
|
+
}
|
9
|
+
"""
|
10
|
+
When I run the JSON data generator
|
11
|
+
Then the JSON output should be:
|
12
|
+
"""json
|
13
|
+
{}
|
14
|
+
"""
|
15
|
+
|
16
|
+
Scenario: Minimum number of properties
|
17
|
+
Given the following JSON schema:
|
18
|
+
"""json
|
19
|
+
{
|
20
|
+
"$schema": "http://json-schema.org/draft-04/schema#",
|
21
|
+
"type": "object",
|
22
|
+
"minProperties": 3,
|
23
|
+
"properties": {
|
24
|
+
}
|
25
|
+
}
|
26
|
+
"""
|
27
|
+
When I run the JSON data generator
|
28
|
+
Then JSON output should have 3 properties
|
@@ -9,3 +9,17 @@ end
|
|
9
9
|
Then(/^the JSON output should be:$/) do |json|
|
10
10
|
expect(@output).to eq json
|
11
11
|
end
|
12
|
+
|
13
|
+
Then(/^the "([^" ]*)" property of the JSON output should be a ([^ ]*)$/) do |prop, type|
|
14
|
+
klass = Class.const_get(type)
|
15
|
+
expect(JSON.parse(@output).fetch(prop).class).to eql klass
|
16
|
+
end
|
17
|
+
|
18
|
+
Then(/^the "([^"]*)" property of the JSON output should be a string of length (\d+)$/) do |prop, length|
|
19
|
+
expect(JSON.parse(@output).fetch(prop).class).to eql String
|
20
|
+
expect(JSON.parse(@output).fetch(prop).length).to eql length.to_i
|
21
|
+
end
|
22
|
+
|
23
|
+
Then(/^JSON output should have (\d+) properties$/) do |number|
|
24
|
+
expect(JSON.parse(@output).length).to eql number.to_i
|
25
|
+
end
|
@@ -14,10 +14,7 @@ Feature: String constraints
|
|
14
14
|
}
|
15
15
|
"""
|
16
16
|
When I run the JSON data generator
|
17
|
-
Then the JSON output should be
|
18
|
-
"""json
|
19
|
-
{"name":"aa"}
|
20
|
-
"""
|
17
|
+
Then the "name" property of the JSON output should be a string of length 2
|
21
18
|
|
22
19
|
Scenario: Minimum length is long
|
23
20
|
Given the following JSON schema:
|
@@ -34,7 +31,4 @@ Feature: String constraints
|
|
34
31
|
}
|
35
32
|
"""
|
36
33
|
When I run the JSON data generator
|
37
|
-
Then the JSON output should be
|
38
|
-
"""json
|
39
|
-
{"name":"aaaaaaaa"}
|
40
|
-
"""
|
34
|
+
Then the "name" property of the JSON output should be a string of length 8
|
data/json_test_data.gemspec
CHANGED
@@ -2,16 +2,18 @@
|
|
2
2
|
require_relative "./version"
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
|
-
s.name
|
6
|
-
s.version
|
7
|
-
s.authors
|
8
|
-
s.description
|
9
|
-
s.summary
|
10
|
-
s.email
|
11
|
-
s.license
|
12
|
-
s.platform
|
5
|
+
s.name = "json_test_data"
|
6
|
+
s.version = JsonTestData::VERSION
|
7
|
+
s.authors = ["Dana Scheider"]
|
8
|
+
s.description = "Generate test data from JSON schema"
|
9
|
+
s.summary = "rambo-#{s.version}"
|
10
|
+
s.email = 'dana.scheider@gmail.com'
|
11
|
+
s.license = 'MIT'
|
12
|
+
s.platform = Gem::Platform::RUBY
|
13
13
|
s.required_ruby_version = ">= 2.1.0"
|
14
14
|
|
15
|
+
s.add_dependency 'regxing', '~> 0.1.0.beta'
|
16
|
+
|
15
17
|
s.add_development_dependency 'cucumber', '~> 2.1'
|
16
18
|
s.add_development_dependency 'rspec', '~> 3.4'
|
17
19
|
s.add_development_dependency 'json', '~> 1.7'
|
@@ -1,9 +1,13 @@
|
|
1
|
+
require "regxing"
|
2
|
+
|
1
3
|
module JsonTestData
|
2
4
|
class String
|
5
|
+
extend RegXing
|
6
|
+
|
3
7
|
class << self
|
4
8
|
def create(schema)
|
5
9
|
len = schema.fetch(:maxLength, nil) || schema.fetch(:minLength, nil) || 1
|
6
|
-
|
10
|
+
Generator.new(/.{#{len}}/).generate!
|
7
11
|
end
|
8
12
|
end
|
9
13
|
end
|
@@ -48,13 +48,22 @@ module JsonTestData
|
|
48
48
|
def generate_object(object)
|
49
49
|
obj = {}
|
50
50
|
|
51
|
-
object.
|
52
|
-
|
51
|
+
if object.has_key?(:properties)
|
52
|
+
object.fetch(:properties).each do |k, v|
|
53
|
+
obj[k] = nil unless v.has_key?(:type)
|
53
54
|
|
54
|
-
|
55
|
+
obj[k] = generate(v)
|
56
|
+
end
|
55
57
|
end
|
56
58
|
|
57
|
-
obj
|
59
|
+
if object.has_key?(:minProperties) && obj.length < object.fetch(:minProperties, 0)
|
60
|
+
(object.fetch(:minProperties) - obj.length).times do
|
61
|
+
key = JsonTestData::String.create({type: "string"})
|
62
|
+
obj[key] = nil
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
obj.size == 0 ? {} : obj
|
58
67
|
end
|
59
68
|
|
60
69
|
def generate_array(object)
|
@@ -7,8 +7,12 @@ describe JsonTestData::String do
|
|
7
7
|
}
|
8
8
|
end
|
9
9
|
|
10
|
-
it "returns
|
11
|
-
expect(described_class.create(object)).to
|
10
|
+
it "returns a string" do
|
11
|
+
expect(described_class.create(object)).to be_a String
|
12
|
+
end
|
13
|
+
|
14
|
+
it "returns a single character" do
|
15
|
+
expect(described_class.create(object).length).to eq 1
|
12
16
|
end
|
13
17
|
end
|
14
18
|
|
@@ -20,8 +24,8 @@ describe JsonTestData::String do
|
|
20
24
|
}
|
21
25
|
end
|
22
26
|
|
23
|
-
it "returns
|
24
|
-
expect(described_class.create(object)).to eq
|
27
|
+
it "returns a string 2 characters long" do
|
28
|
+
expect(described_class.create(object).length).to eq 2
|
25
29
|
end
|
26
30
|
end
|
27
31
|
|
@@ -33,8 +37,8 @@ describe JsonTestData::String do
|
|
33
37
|
}
|
34
38
|
end
|
35
39
|
|
36
|
-
it "returns
|
37
|
-
expect(described_class.create(object)).to eq
|
40
|
+
it "returns an 8-character string" do
|
41
|
+
expect(described_class.create(object).length).to eq 8
|
38
42
|
end
|
39
43
|
end
|
40
44
|
end
|
@@ -67,14 +67,14 @@ describe JsonTestData::JsonSchema do
|
|
67
67
|
:type => "object",
|
68
68
|
:properties => {
|
69
69
|
:name => {
|
70
|
-
:type => "
|
70
|
+
:type => "number"
|
71
71
|
}
|
72
72
|
}
|
73
73
|
}.to_json
|
74
74
|
end
|
75
75
|
|
76
76
|
let(:output) do
|
77
|
-
{ :name =>
|
77
|
+
{ :name => 1 }.to_json
|
78
78
|
end
|
79
79
|
|
80
80
|
it "generates the right object" do
|
@@ -89,13 +89,13 @@ describe JsonTestData::JsonSchema do
|
|
89
89
|
:"$schema" => "http://json-schema.org/draft-04/schema#",
|
90
90
|
:type => "array",
|
91
91
|
:items => {
|
92
|
-
:type => "
|
92
|
+
:type => "number"
|
93
93
|
}
|
94
94
|
}.to_json
|
95
95
|
end
|
96
96
|
|
97
97
|
let(:output) do
|
98
|
-
[
|
98
|
+
[1].to_json
|
99
99
|
end
|
100
100
|
|
101
101
|
it "generates the right object" do
|
@@ -189,7 +189,7 @@ describe JsonTestData::JsonSchema do
|
|
189
189
|
:users => {
|
190
190
|
:type => "array",
|
191
191
|
:items => {
|
192
|
-
:type => "
|
192
|
+
:type => "number"
|
193
193
|
}
|
194
194
|
}
|
195
195
|
}
|
@@ -197,7 +197,7 @@ describe JsonTestData::JsonSchema do
|
|
197
197
|
end
|
198
198
|
|
199
199
|
let(:output) do
|
200
|
-
{:users => [
|
200
|
+
{:users => [1]}.to_json
|
201
201
|
end
|
202
202
|
|
203
203
|
it "nests the object" do
|
@@ -214,14 +214,14 @@ describe JsonTestData::JsonSchema do
|
|
214
214
|
:items => {
|
215
215
|
:type => "array",
|
216
216
|
:items => {
|
217
|
-
:type => "
|
217
|
+
:type => "number"
|
218
218
|
}
|
219
219
|
}
|
220
220
|
}.to_json
|
221
221
|
end
|
222
222
|
|
223
223
|
let(:output) do
|
224
|
-
[[
|
224
|
+
[[1]].to_json
|
225
225
|
end
|
226
226
|
|
227
227
|
it "returns a nested array" do
|
data/version.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: json_test_data
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0.beta
|
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-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: regxing
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.1.0.beta
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.1.0.beta
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: cucumber
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -127,6 +141,7 @@ files:
|
|
127
141
|
- features/generate_empty_objects.feature
|
128
142
|
- features/nested_objects_and_arrays.feature
|
129
143
|
- features/numeric_constraints.feature
|
144
|
+
- features/object_constraints.feature
|
130
145
|
- features/step_definitions/json_test_data_steps.rb
|
131
146
|
- features/string_constraints.feature
|
132
147
|
- features/support/env.rb
|
@@ -158,15 +173,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
158
173
|
version: 2.1.0
|
159
174
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
160
175
|
requirements:
|
161
|
-
- - "
|
176
|
+
- - ">"
|
162
177
|
- !ruby/object:Gem::Version
|
163
|
-
version:
|
178
|
+
version: 1.3.1
|
164
179
|
requirements: []
|
165
180
|
rubyforge_project:
|
166
|
-
rubygems_version: 2.
|
181
|
+
rubygems_version: 2.5.1
|
167
182
|
signing_key:
|
168
183
|
specification_version: 4
|
169
|
-
summary: rambo-0.
|
184
|
+
summary: rambo-0.3.0.beta
|
170
185
|
test_files:
|
171
186
|
- features/array_constraints.feature
|
172
187
|
- features/data_types.feature
|
@@ -174,6 +189,7 @@ test_files:
|
|
174
189
|
- features/generate_empty_objects.feature
|
175
190
|
- features/nested_objects_and_arrays.feature
|
176
191
|
- features/numeric_constraints.feature
|
192
|
+
- features/object_constraints.feature
|
177
193
|
- features/step_definitions/json_test_data_steps.rb
|
178
194
|
- features/string_constraints.feature
|
179
195
|
- features/support/env.rb
|
@@ -182,4 +198,3 @@ test_files:
|
|
182
198
|
- spec/json_test_data/json_schema_spec.rb
|
183
199
|
- spec/matchers/number_matchers.rb
|
184
200
|
- spec/spec_helper.rb
|
185
|
-
has_rdoc:
|