json_test_data 0.0.1.beta
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/.travis.yml +11 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +78 -0
- data/LICENSE +21 -0
- data/README.md +19 -0
- data/Rakefile +10 -0
- data/features/data_types.feature +62 -0
- data/features/generate_data.feature +36 -0
- data/features/generate_empty_objects.feature +30 -0
- data/features/nested_objects_and_arrays.feature +111 -0
- data/features/step_definitions/json_test_data_steps.rb +11 -0
- data/features/support/env.rb +7 -0
- data/json_test_data.gemspec +28 -0
- data/lib/json_test_data/json_schema.rb +59 -0
- data/lib/json_test_data.rb +8 -0
- data/spec/json_test_data/json_schema_spec.rb +237 -0
- data/spec/spec_helper.rb +56 -0
- data/version.rb +3 -0
- metadata +170 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a47a978c6343d155715da552b3845284722983cb
|
4
|
+
data.tar.gz: 8ec1a469874daf382e7ddf1349345b087640a481
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b5feb4cf3a2a9b12169667e607e314de781b23d5f1076ddb9713e8d0ee4bc74663dfcfff0a25beb23f098ba240056ecf7e3079f5aaff9a5ff379959b68df3b89
|
7
|
+
data.tar.gz: 3af1c3371c865e8abb1018de75e04a6dafa8aa6f55e1c67cef99e9eb4a14c873cdda5daea0c5aead65cf99823032761883bc97f5fe7389c76e14f32672dc0518
|
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
json_test_data (0.0.1.beta)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
builder (3.2.2)
|
10
|
+
coderay (1.1.1)
|
11
|
+
coveralls (0.8.13)
|
12
|
+
json (~> 1.8)
|
13
|
+
simplecov (~> 0.11.0)
|
14
|
+
term-ansicolor (~> 1.3)
|
15
|
+
thor (~> 0.19.1)
|
16
|
+
tins (~> 1.6.0)
|
17
|
+
cucumber (2.3.3)
|
18
|
+
builder (>= 2.1.2)
|
19
|
+
cucumber-core (~> 1.4.0)
|
20
|
+
cucumber-wire (~> 0.0.1)
|
21
|
+
diff-lcs (>= 1.1.3)
|
22
|
+
gherkin (~> 3.2.0)
|
23
|
+
multi_json (>= 1.7.5, < 2.0)
|
24
|
+
multi_test (>= 0.1.2)
|
25
|
+
cucumber-core (1.4.0)
|
26
|
+
gherkin (~> 3.2.0)
|
27
|
+
cucumber-wire (0.0.1)
|
28
|
+
diff-lcs (1.2.5)
|
29
|
+
docile (1.1.5)
|
30
|
+
gherkin (3.2.0)
|
31
|
+
json (1.8.3)
|
32
|
+
method_source (0.8.2)
|
33
|
+
multi_json (1.11.2)
|
34
|
+
multi_test (0.1.2)
|
35
|
+
pry (0.10.3)
|
36
|
+
coderay (~> 1.1.0)
|
37
|
+
method_source (~> 0.8.1)
|
38
|
+
slop (~> 3.4)
|
39
|
+
rake (10.5.0)
|
40
|
+
rspec (3.4.0)
|
41
|
+
rspec-core (~> 3.4.0)
|
42
|
+
rspec-expectations (~> 3.4.0)
|
43
|
+
rspec-mocks (~> 3.4.0)
|
44
|
+
rspec-core (3.4.4)
|
45
|
+
rspec-support (~> 3.4.0)
|
46
|
+
rspec-expectations (3.4.0)
|
47
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
48
|
+
rspec-support (~> 3.4.0)
|
49
|
+
rspec-mocks (3.4.1)
|
50
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
51
|
+
rspec-support (~> 3.4.0)
|
52
|
+
rspec-support (3.4.1)
|
53
|
+
simplecov (0.11.2)
|
54
|
+
docile (~> 1.1.0)
|
55
|
+
json (~> 1.8)
|
56
|
+
simplecov-html (~> 0.10.0)
|
57
|
+
simplecov-html (0.10.0)
|
58
|
+
slop (3.6.0)
|
59
|
+
term-ansicolor (1.3.2)
|
60
|
+
tins (~> 1.0)
|
61
|
+
thor (0.19.1)
|
62
|
+
tins (1.6.0)
|
63
|
+
|
64
|
+
PLATFORMS
|
65
|
+
ruby
|
66
|
+
|
67
|
+
DEPENDENCIES
|
68
|
+
coveralls (~> 0.7)
|
69
|
+
cucumber (~> 2.1)
|
70
|
+
json (~> 1.7)
|
71
|
+
json_test_data!
|
72
|
+
pry (~> 0.10)
|
73
|
+
rake (~> 10.5)
|
74
|
+
rspec (~> 3.4)
|
75
|
+
simplecov (~> 0.11)
|
76
|
+
|
77
|
+
BUNDLED WITH
|
78
|
+
1.11.2
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Dana Scheider
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# JSON Test Data Generator
|
2
|
+
[![Gem Version](https://badge.fury.io/rb/json_test_data.svg)](https://badge.fury.io/rb/json_test_data) [![Build Status](https://travis-ci.org/danascheider/json_test_data.svg?branch=master)](https://travis-ci.org/danascheider/json_test_data) [![Code Climate](https://codeclimate.com/github/danascheider/json_test_data/badges/gpa.svg)](https://codeclimate.com/github/danascheider/json_test_data)
|
3
|
+
[![Coverage Status](https://coveralls.io/repos/github/danascheider/json_test_data/badge.svg?branch=master)](https://coveralls.io/github/danascheider/json_test_data?branch=master) [![Dependency Status](https://gemnasium.com/badges/github.com/danascheider/json_test_data.svg)](https://gemnasium.com/github.com/danascheider/json_test_data)
|
4
|
+
|
5
|
+
The JSON test data generator takes JSON schema as input and generates test data matching the specification. You can download it from RubyGems:
|
6
|
+
```ruby
|
7
|
+
gem install json_test_data
|
8
|
+
```
|
9
|
+
Alternatively, it can be included in your Gemfile:
|
10
|
+
```ruby
|
11
|
+
gem "json_test_data", "~> 0.0.1"
|
12
|
+
```
|
13
|
+
To use it, first require it, then generate the test data using:
|
14
|
+
```ruby
|
15
|
+
data = JsonTestData.generate!
|
16
|
+
```
|
17
|
+
|
18
|
+
## 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.
|
data/Rakefile
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
@wip
|
2
|
+
Feature: Handling data types
|
3
|
+
|
4
|
+
The data generated needs to have the correct properties or items, including
|
5
|
+
the data type specified
|
6
|
+
|
7
|
+
Scenario: Strings
|
8
|
+
Given the following JSON schema:
|
9
|
+
"""json
|
10
|
+
{
|
11
|
+
"$schema": "http://json-schema.org/draft-04/schema#",
|
12
|
+
"type": "object",
|
13
|
+
"properties": {
|
14
|
+
"name": {
|
15
|
+
"type": "string"
|
16
|
+
}
|
17
|
+
}
|
18
|
+
}
|
19
|
+
"""
|
20
|
+
When I run the JSON data generator
|
21
|
+
Then the JSON output should be:
|
22
|
+
"""json
|
23
|
+
{"name":"string"}
|
24
|
+
"""
|
25
|
+
|
26
|
+
Scenario: Numbers
|
27
|
+
Given the following JSON schema:
|
28
|
+
"""json
|
29
|
+
{
|
30
|
+
"$schema": "http://json-schema.org/draft-04/schema#",
|
31
|
+
"type": "object",
|
32
|
+
"properties": {
|
33
|
+
"id": {
|
34
|
+
"type": "number"
|
35
|
+
}
|
36
|
+
}
|
37
|
+
}
|
38
|
+
"""
|
39
|
+
When I run the JSON data generator
|
40
|
+
Then the JSON output should be:
|
41
|
+
"""json
|
42
|
+
{"id":1}
|
43
|
+
"""
|
44
|
+
|
45
|
+
Scenario: Booleans
|
46
|
+
Given the following JSON schema:
|
47
|
+
"""json
|
48
|
+
{
|
49
|
+
"$schema": "http://json-schema.org/draft-04/schema#",
|
50
|
+
"type": "object",
|
51
|
+
"properties": {
|
52
|
+
"admin": {
|
53
|
+
"type": "boolean"
|
54
|
+
}
|
55
|
+
}
|
56
|
+
}
|
57
|
+
"""
|
58
|
+
When I run the JSON data generator
|
59
|
+
Then the JSON output should be:
|
60
|
+
"""json
|
61
|
+
{"admin":true}
|
62
|
+
"""
|
@@ -0,0 +1,36 @@
|
|
1
|
+
Feature: Generate test data
|
2
|
+
Scenario: Simple object
|
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
|
+
}
|
12
|
+
}
|
13
|
+
}
|
14
|
+
"""
|
15
|
+
When I run the JSON data generator
|
16
|
+
Then the JSON output should be:
|
17
|
+
"""json
|
18
|
+
{"name":"string"}
|
19
|
+
"""
|
20
|
+
|
21
|
+
Scenario: Simple array
|
22
|
+
Given the following JSON schema:
|
23
|
+
"""json
|
24
|
+
{
|
25
|
+
"$schema": "http://json-schema.org/draft-04/schema#",
|
26
|
+
"type": "array",
|
27
|
+
"items": {
|
28
|
+
"type": "string"
|
29
|
+
}
|
30
|
+
}
|
31
|
+
"""
|
32
|
+
When I run the JSON data generator
|
33
|
+
Then the JSON output should be:
|
34
|
+
"""json
|
35
|
+
["string"]
|
36
|
+
"""
|
@@ -0,0 +1,30 @@
|
|
1
|
+
Feature: Generating empty objects
|
2
|
+
Scenario: Empty object
|
3
|
+
Given the following JSON schema:
|
4
|
+
"""json
|
5
|
+
{
|
6
|
+
"$schema": "http://json-schema.org/draft-04/schema#",
|
7
|
+
"type": "object",
|
8
|
+
"properties": {}
|
9
|
+
}
|
10
|
+
"""
|
11
|
+
When I run the JSON data generator
|
12
|
+
Then the JSON output should be:
|
13
|
+
"""json
|
14
|
+
{}
|
15
|
+
"""
|
16
|
+
|
17
|
+
Scenario: Empty array
|
18
|
+
Given the following JSON schema:
|
19
|
+
"""json
|
20
|
+
{
|
21
|
+
"$schema": "http://json-schema.org/draft-04/schema#",
|
22
|
+
"type": "array",
|
23
|
+
"items": {}
|
24
|
+
}
|
25
|
+
"""
|
26
|
+
When I run the JSON data generator
|
27
|
+
Then the JSON output should be:
|
28
|
+
"""json
|
29
|
+
[]
|
30
|
+
"""
|
@@ -0,0 +1,111 @@
|
|
1
|
+
@wip
|
2
|
+
Feature: Support nested objects and arrays
|
3
|
+
|
4
|
+
Scenario: Object in an array
|
5
|
+
Given the following JSON schema:
|
6
|
+
"""json
|
7
|
+
{
|
8
|
+
"$schema": "http://json-schema.org/draft-04/schema#",
|
9
|
+
"type": "array",
|
10
|
+
"items": {
|
11
|
+
"type": "object",
|
12
|
+
"properties": {
|
13
|
+
"name": {
|
14
|
+
"type": "string"
|
15
|
+
},
|
16
|
+
"id": {
|
17
|
+
"type": "integer"
|
18
|
+
},
|
19
|
+
"admin": {
|
20
|
+
"type": "boolean"
|
21
|
+
}
|
22
|
+
}
|
23
|
+
}
|
24
|
+
}
|
25
|
+
"""
|
26
|
+
When I run the JSON data generator
|
27
|
+
Then the JSON output should be:
|
28
|
+
"""json
|
29
|
+
[{"name":"string","id":1,"admin":true}]
|
30
|
+
"""
|
31
|
+
|
32
|
+
Scenario: Array in an object
|
33
|
+
Given the following JSON schema:
|
34
|
+
"""json
|
35
|
+
{
|
36
|
+
"$schema": "http://json-schema.org/draft-04/schema#",
|
37
|
+
"type": "object",
|
38
|
+
"properties": {
|
39
|
+
"users": {
|
40
|
+
"type": "array",
|
41
|
+
"items": {
|
42
|
+
"type": "string"
|
43
|
+
}
|
44
|
+
}
|
45
|
+
}
|
46
|
+
}
|
47
|
+
"""
|
48
|
+
When I run the JSON data generator
|
49
|
+
Then the JSON output should be:
|
50
|
+
"""json
|
51
|
+
{"users":["string"]}
|
52
|
+
"""
|
53
|
+
|
54
|
+
Scenario: Array in an array
|
55
|
+
Given the following JSON schema:
|
56
|
+
"""json
|
57
|
+
{
|
58
|
+
"$schema": "http://json-schema.org/draft-04/schema#",
|
59
|
+
"type": "array",
|
60
|
+
"items": {
|
61
|
+
"type": "array",
|
62
|
+
"items": {
|
63
|
+
"type": "string"
|
64
|
+
}
|
65
|
+
}
|
66
|
+
}
|
67
|
+
"""
|
68
|
+
When I run the JSON data generator
|
69
|
+
Then the JSON output should be:
|
70
|
+
"""json
|
71
|
+
[["string"]]
|
72
|
+
"""
|
73
|
+
|
74
|
+
Scenario: More complex nested object
|
75
|
+
Given the following JSON schema:
|
76
|
+
"""json
|
77
|
+
{
|
78
|
+
"$schema": "http://json-schema.org/draft-04/schema#",
|
79
|
+
"type": "array",
|
80
|
+
"items": {
|
81
|
+
"type": "object",
|
82
|
+
"properties": {
|
83
|
+
"name": {
|
84
|
+
"type": "string"
|
85
|
+
},
|
86
|
+
"dossier": {
|
87
|
+
"type": "object",
|
88
|
+
"properties": {
|
89
|
+
"height_in_feet": {
|
90
|
+
"type": "number"
|
91
|
+
},
|
92
|
+
"favorite_foods": {
|
93
|
+
"type": "array",
|
94
|
+
"items": {
|
95
|
+
"type": "string"
|
96
|
+
}
|
97
|
+
}
|
98
|
+
}
|
99
|
+
},
|
100
|
+
"admin": {
|
101
|
+
"type": "boolean"
|
102
|
+
}
|
103
|
+
}
|
104
|
+
}
|
105
|
+
}
|
106
|
+
"""
|
107
|
+
When I run the JSON data generator
|
108
|
+
Then the JSON output should be:
|
109
|
+
"""json
|
110
|
+
[{"name":"string","dossier":{"height_in_feet":1,"favorite_foods":["string"]},"admin":true}]
|
111
|
+
"""
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require_relative "./version"
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
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
|
+
s.required_ruby_version = ">= 2.1.0"
|
14
|
+
|
15
|
+
s.add_development_dependency 'cucumber', '~> 2.1'
|
16
|
+
s.add_development_dependency 'rspec', '~> 3.4'
|
17
|
+
s.add_development_dependency 'json', '~> 1.7'
|
18
|
+
s.add_development_dependency 'rake', '~> 10.5'
|
19
|
+
s.add_development_dependency 'simplecov', '~> 0.11'
|
20
|
+
s.add_development_dependency 'coveralls', '~> 0.7'
|
21
|
+
s.add_development_dependency 'pry', '~> 0.10'
|
22
|
+
|
23
|
+
s.rubygems_version = ">= 1.6.1"
|
24
|
+
s.files = `git ls-files`.split("\n").reject {|path| path =~ /\.gitignore$/ }
|
25
|
+
s.test_files = `git ls-files -- {spec,features}/*`.split("\n")
|
26
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
27
|
+
s.require_path = "lib"
|
28
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module JsonTestData
|
2
|
+
class JsonSchema
|
3
|
+
attr_accessor :schema
|
4
|
+
|
5
|
+
def initialize(schema)
|
6
|
+
@schema = JSON.parse(schema, symbolize_names: true)
|
7
|
+
end
|
8
|
+
|
9
|
+
def generate_example
|
10
|
+
@schema.fetch(:type) == "object" ? generate_object(schema).to_json : generate_array(schema).to_json
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
def object_of_type(type)
|
15
|
+
case type
|
16
|
+
when "number"
|
17
|
+
1
|
18
|
+
when "integer"
|
19
|
+
1
|
20
|
+
when "boolean"
|
21
|
+
true
|
22
|
+
when "string"
|
23
|
+
"string"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def generate_object(object)
|
28
|
+
obj = {}
|
29
|
+
|
30
|
+
object.fetch(:properties).each do |k, v|
|
31
|
+
obj[k] = nil unless v.has_key?(:type)
|
32
|
+
|
33
|
+
obj[k] = if v.fetch(:type) == "object"
|
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
|
40
|
+
end
|
41
|
+
|
42
|
+
obj
|
43
|
+
end
|
44
|
+
|
45
|
+
def generate_array(object)
|
46
|
+
return [] unless object.fetch(:items).has_key?(:type)
|
47
|
+
|
48
|
+
val = if object.fetch(:items).fetch(:type) == "object"
|
49
|
+
generate_object(object.fetch(:items))
|
50
|
+
elsif object.fetch(:items).fetch(:type) == "array"
|
51
|
+
generate_array(object.fetch(:items))
|
52
|
+
else
|
53
|
+
object_of_type(object.fetch(:items).fetch(:type))
|
54
|
+
end
|
55
|
+
|
56
|
+
[val].compact
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,237 @@
|
|
1
|
+
describe JsonTestData::JsonSchema do
|
2
|
+
describe "#initialize" do
|
3
|
+
|
4
|
+
let(:schema) do
|
5
|
+
{
|
6
|
+
:"$schema" => "http://json-schema.org/draft-04/schema#",
|
7
|
+
:type => "object",
|
8
|
+
:properties => {}
|
9
|
+
}.to_json
|
10
|
+
end
|
11
|
+
|
12
|
+
it "instantiates with a schema" do
|
13
|
+
json_schema = JsonTestData::JsonSchema.new(schema)
|
14
|
+
expect(json_schema.schema).to eql JSON.parse(schema, symbolize_names: true)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "#generate_example" do
|
19
|
+
describe "trivial examples" do
|
20
|
+
context "when schema describes an object" do
|
21
|
+
|
22
|
+
let(:schema) do
|
23
|
+
JsonTestData::JsonSchema.new(
|
24
|
+
{
|
25
|
+
:"$schema" => "http://json-schema.org/draft-04/schema#",
|
26
|
+
:type => "object",
|
27
|
+
:properties => {}
|
28
|
+
}.to_json
|
29
|
+
)
|
30
|
+
end
|
31
|
+
|
32
|
+
let(:output) do
|
33
|
+
{}.to_json
|
34
|
+
end
|
35
|
+
|
36
|
+
it "generates an object" do
|
37
|
+
expect(schema.generate_example).to eql output
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context "when schema describes an array" do
|
42
|
+
|
43
|
+
let(:schema) do
|
44
|
+
JsonTestData::JsonSchema.new(
|
45
|
+
{
|
46
|
+
:"$schema" => "http://json-schema.org/draft-04/schema#",
|
47
|
+
:type => "array",
|
48
|
+
:items => {}
|
49
|
+
}.to_json
|
50
|
+
)
|
51
|
+
end
|
52
|
+
|
53
|
+
let(:output) do
|
54
|
+
[].to_json
|
55
|
+
end
|
56
|
+
|
57
|
+
it "generates an object" do
|
58
|
+
expect(schema.generate_example).to eql output
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe "bigger examples" do
|
64
|
+
context "when schema describes an object" do
|
65
|
+
|
66
|
+
let(:schema) do
|
67
|
+
{
|
68
|
+
:"$schema" => "http://json-schema.org/draft-04/schema#",
|
69
|
+
:type => "object",
|
70
|
+
:properties => {
|
71
|
+
:name => {
|
72
|
+
:type => "string"
|
73
|
+
}
|
74
|
+
}
|
75
|
+
}.to_json
|
76
|
+
end
|
77
|
+
|
78
|
+
let(:output) do
|
79
|
+
{ "name" => "string" }.to_json
|
80
|
+
end
|
81
|
+
|
82
|
+
it "generates the right object" do
|
83
|
+
json_schema = JsonTestData::JsonSchema.new(schema)
|
84
|
+
expect(json_schema.generate_example).to eql output
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
context "when schema describes an array" do
|
89
|
+
let(:schema) do
|
90
|
+
{
|
91
|
+
:"$schema" => "http://json-schema.org/draft-04/schema#",
|
92
|
+
:type => "array",
|
93
|
+
:items => {
|
94
|
+
:type => "string"
|
95
|
+
}
|
96
|
+
}.to_json
|
97
|
+
end
|
98
|
+
|
99
|
+
let(:output) do
|
100
|
+
["string"].to_json
|
101
|
+
end
|
102
|
+
|
103
|
+
it "generates the right object" do
|
104
|
+
json_schema = JsonTestData::JsonSchema.new(schema)
|
105
|
+
expect(json_schema.generate_example).to eql output
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
describe "data type support" do
|
111
|
+
context "numbers" do
|
112
|
+
|
113
|
+
let(:schema) do
|
114
|
+
{
|
115
|
+
:"$schema" => "http://json-schema.org/draft-04/schema#",
|
116
|
+
:type => "object",
|
117
|
+
:properties => {
|
118
|
+
:id => {
|
119
|
+
:type => "number"
|
120
|
+
}
|
121
|
+
}
|
122
|
+
}.to_json
|
123
|
+
end
|
124
|
+
|
125
|
+
let(:output) do
|
126
|
+
{:id => 1}.to_json
|
127
|
+
end
|
128
|
+
|
129
|
+
it "uses the correct data type" do
|
130
|
+
json_schema = JsonTestData::JsonSchema.new(schema)
|
131
|
+
expect(json_schema.generate_example).to eql output
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
context "booleans" do
|
136
|
+
|
137
|
+
let(:schema) do
|
138
|
+
{
|
139
|
+
:"$schema" => "http://json-schema.org/draft-04/schema#",
|
140
|
+
:type => "object",
|
141
|
+
:properties => {
|
142
|
+
:admin => {
|
143
|
+
:type => "boolean"
|
144
|
+
}
|
145
|
+
}
|
146
|
+
}.to_json
|
147
|
+
end
|
148
|
+
|
149
|
+
let(:output) do
|
150
|
+
{:admin => true}.to_json
|
151
|
+
end
|
152
|
+
|
153
|
+
it "uses the correct data type" do
|
154
|
+
json_schema = JsonTestData::JsonSchema.new(schema)
|
155
|
+
expect(json_schema.generate_example).to eql output
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
context "nested objects" do
|
160
|
+
let(:schema) do
|
161
|
+
{
|
162
|
+
:"$schema" => "http://json-schema.org/draft-04/schema#",
|
163
|
+
:type => "array",
|
164
|
+
:items => {
|
165
|
+
:type => "object",
|
166
|
+
:properties => {
|
167
|
+
:id => {
|
168
|
+
:type => "number"
|
169
|
+
}
|
170
|
+
}
|
171
|
+
}
|
172
|
+
}.to_json
|
173
|
+
end
|
174
|
+
|
175
|
+
let(:output) do
|
176
|
+
[{:id => 1}].to_json
|
177
|
+
end
|
178
|
+
|
179
|
+
it "nests the object" do
|
180
|
+
json_schema = JsonTestData::JsonSchema.new(schema)
|
181
|
+
expect(json_schema.generate_example).to eql output
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
context "nested arrays" do
|
186
|
+
let(:schema) do
|
187
|
+
{
|
188
|
+
:"$schema" => "http://json-schema.org/draft-04/schema#",
|
189
|
+
:type => "object",
|
190
|
+
:properties => {
|
191
|
+
:users => {
|
192
|
+
:type => "array",
|
193
|
+
:items => {
|
194
|
+
:type => "string"
|
195
|
+
}
|
196
|
+
}
|
197
|
+
}
|
198
|
+
}.to_json
|
199
|
+
end
|
200
|
+
|
201
|
+
let(:output) do
|
202
|
+
{:users => ["string"]}.to_json
|
203
|
+
end
|
204
|
+
|
205
|
+
it "nests the object" do
|
206
|
+
json_schema = JsonTestData::JsonSchema.new(schema)
|
207
|
+
expect(json_schema.generate_example).to eql output
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
context "arrays in arrays" do
|
212
|
+
|
213
|
+
let(:schema) do
|
214
|
+
{
|
215
|
+
:"$schema" => "http://json-schema.org/draft-04/schema#",
|
216
|
+
:type => "array",
|
217
|
+
:items => {
|
218
|
+
:type => "array",
|
219
|
+
:items => {
|
220
|
+
:type => "string"
|
221
|
+
}
|
222
|
+
}
|
223
|
+
}.to_json
|
224
|
+
end
|
225
|
+
|
226
|
+
let(:output) do
|
227
|
+
[["string"]].to_json
|
228
|
+
end
|
229
|
+
|
230
|
+
it "returns a nested array" do
|
231
|
+
json_schema = JsonTestData::JsonSchema.new(schema)
|
232
|
+
expect(json_schema.generate_example).to eql output
|
233
|
+
end
|
234
|
+
end
|
235
|
+
end
|
236
|
+
end
|
237
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
require "coveralls"
|
2
|
+
|
3
|
+
Coveralls.wear!
|
4
|
+
|
5
|
+
require "pry"
|
6
|
+
|
7
|
+
require_relative "../lib/json_test_data"
|
8
|
+
require_relative "../lib/json_test_data/json_schema"
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
config.expect_with :rspec do |expectations|
|
12
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
13
|
+
end
|
14
|
+
|
15
|
+
config.mock_with :rspec do |mocks|
|
16
|
+
mocks.verify_partial_doubles = true
|
17
|
+
end
|
18
|
+
|
19
|
+
# These two settings work together to allow you to limit a spec run
|
20
|
+
# to individual examples or groups you care about by tagging them with
|
21
|
+
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
22
|
+
# get run.
|
23
|
+
config.filter_run :focus
|
24
|
+
config.run_all_when_everything_filtered = true
|
25
|
+
|
26
|
+
# This setting enables warnings. It's recommended, but in some cases may
|
27
|
+
# be too noisy due to issues in dependencies.
|
28
|
+
config.warnings = true
|
29
|
+
|
30
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
31
|
+
# file, and it's useful to allow more verbose output when running an
|
32
|
+
# individual spec file.
|
33
|
+
if config.files_to_run.one?
|
34
|
+
# Use the documentation formatter for detailed output,
|
35
|
+
# unless a formatter has already been configured
|
36
|
+
# (e.g. via a command-line flag).
|
37
|
+
config.default_formatter = 'doc'
|
38
|
+
end
|
39
|
+
|
40
|
+
# Print the 10 slowest examples and example groups at the
|
41
|
+
# end of the spec run, to help surface which specs are running
|
42
|
+
# particularly slow.
|
43
|
+
config.profile_examples = 10
|
44
|
+
|
45
|
+
# Run specs in random order to surface order dependencies. If you find an
|
46
|
+
# order dependency and want to debug it, you can fix the order by providing
|
47
|
+
# the seed, which is printed after each run.
|
48
|
+
# --seed 1234
|
49
|
+
config.order = :random
|
50
|
+
|
51
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
52
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
53
|
+
# test failures related to randomization by passing the same `--seed` value
|
54
|
+
# as the one that triggered the failure.
|
55
|
+
Kernel.srand config.seed
|
56
|
+
end
|
data/version.rb
ADDED
metadata
ADDED
@@ -0,0 +1,170 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: json_test_data
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1.beta
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dana Scheider
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-04-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: cucumber
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.1'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.4'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.4'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: json
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.7'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.7'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.5'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.5'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: simplecov
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.11'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.11'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: coveralls
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.7'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.7'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: pry
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0.10'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0.10'
|
111
|
+
description: Generate test data from JSON schema
|
112
|
+
email: dana.scheider@gmail.com
|
113
|
+
executables: []
|
114
|
+
extensions: []
|
115
|
+
extra_rdoc_files: []
|
116
|
+
files:
|
117
|
+
- ".rspec"
|
118
|
+
- ".travis.yml"
|
119
|
+
- Gemfile
|
120
|
+
- Gemfile.lock
|
121
|
+
- LICENSE
|
122
|
+
- README.md
|
123
|
+
- Rakefile
|
124
|
+
- features/data_types.feature
|
125
|
+
- features/generate_data.feature
|
126
|
+
- features/generate_empty_objects.feature
|
127
|
+
- features/nested_objects_and_arrays.feature
|
128
|
+
- features/step_definitions/json_test_data_steps.rb
|
129
|
+
- features/support/env.rb
|
130
|
+
- json_test_data.gemspec
|
131
|
+
- lib/json_test_data.rb
|
132
|
+
- lib/json_test_data/json_schema.rb
|
133
|
+
- spec/json_test_data/json_schema_spec.rb
|
134
|
+
- spec/spec_helper.rb
|
135
|
+
- version.rb
|
136
|
+
homepage:
|
137
|
+
licenses:
|
138
|
+
- MIT
|
139
|
+
metadata: {}
|
140
|
+
post_install_message:
|
141
|
+
rdoc_options:
|
142
|
+
- "--charset=UTF-8"
|
143
|
+
require_paths:
|
144
|
+
- lib
|
145
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
146
|
+
requirements:
|
147
|
+
- - ">="
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: 2.1.0
|
150
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
151
|
+
requirements:
|
152
|
+
- - ">"
|
153
|
+
- !ruby/object:Gem::Version
|
154
|
+
version: 1.3.1
|
155
|
+
requirements: []
|
156
|
+
rubyforge_project:
|
157
|
+
rubygems_version: 2.4.6
|
158
|
+
signing_key:
|
159
|
+
specification_version: 4
|
160
|
+
summary: rambo-0.0.1.beta
|
161
|
+
test_files:
|
162
|
+
- features/data_types.feature
|
163
|
+
- features/generate_data.feature
|
164
|
+
- features/generate_empty_objects.feature
|
165
|
+
- features/nested_objects_and_arrays.feature
|
166
|
+
- features/step_definitions/json_test_data_steps.rb
|
167
|
+
- features/support/env.rb
|
168
|
+
- spec/json_test_data/json_schema_spec.rb
|
169
|
+
- spec/spec_helper.rb
|
170
|
+
has_rdoc:
|