json_test_data 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/Gemfile +2 -0
- data/Gemfile.lock +12 -4
- data/ISSUE_TEMPLATE.md +45 -0
- data/README.md +1 -1
- data/features/string_constraints.feature +21 -0
- data/json_test_data.gemspec +1 -1
- data/lib/json_test_data/data_structures/number.rb +8 -3
- data/lib/json_test_data/data_structures/string.rb +3 -3
- data/lib/json_test_data/json_schema.rb +1 -1
- data/spec/json_test_data/data_structures/number_spec.rb +14 -0
- data/spec/json_test_data/data_structures/string_spec.rb +15 -0
- data/spec/matchers/array_matchers.rb +7 -0
- data/spec/spec_helper.rb +1 -0
- data/version.rb +1 -1
- metadata +8 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9b86fdfb10c18e8084d78373027dde9f12496835
|
4
|
+
data.tar.gz: 86d998ef02cb7fd786d8940d5fe076066ae90d77
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ba51ec9788cdb8d85ad7d18333858c1a6a8458c88fb7a2985376de15b7dcc02f98060fd925cf4aaeac1c370bf88546df728783a207adff0660db742702f179e
|
7
|
+
data.tar.gz: 99b1056605ed53221ad7a273c9ab41ad60e58b780a75248cf9265882f12e0cd8b1d37b84bb29c3d5b79c02a928f69010a6d0c72587f39f5114363d9a66e343e0
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
json_test_data (0.
|
5
|
-
regxing (~> 0.1.0
|
4
|
+
json_test_data (0.8.0)
|
5
|
+
regxing (~> 0.1.0)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
10
|
addressable (2.3.8)
|
11
11
|
builder (3.2.2)
|
12
|
+
coderay (1.1.1)
|
12
13
|
coveralls (0.8.13)
|
13
14
|
json (~> 1.8)
|
14
15
|
simplecov (~> 0.11.0)
|
@@ -30,10 +31,15 @@ GEM
|
|
30
31
|
docile (1.1.5)
|
31
32
|
gherkin (3.2.0)
|
32
33
|
json (1.8.3)
|
33
|
-
json-schema (2.6.
|
34
|
+
json-schema (2.6.2)
|
34
35
|
addressable (~> 2.3.8)
|
35
|
-
|
36
|
+
method_source (0.8.2)
|
37
|
+
multi_json (1.12.1)
|
36
38
|
multi_test (0.1.2)
|
39
|
+
pry (0.10.3)
|
40
|
+
coderay (~> 1.1.0)
|
41
|
+
method_source (~> 0.8.1)
|
42
|
+
slop (~> 3.4)
|
37
43
|
rake (11.1.2)
|
38
44
|
regxing (0.1.0)
|
39
45
|
rspec (3.4.0)
|
@@ -54,6 +60,7 @@ GEM
|
|
54
60
|
json (~> 1.8)
|
55
61
|
simplecov-html (~> 0.10.0)
|
56
62
|
simplecov-html (0.10.0)
|
63
|
+
slop (3.6.0)
|
57
64
|
term-ansicolor (1.3.2)
|
58
65
|
tins (~> 1.0)
|
59
66
|
thor (0.19.1)
|
@@ -68,6 +75,7 @@ DEPENDENCIES
|
|
68
75
|
json (~> 1.7)
|
69
76
|
json-schema (~> 2.6)
|
70
77
|
json_test_data!
|
78
|
+
pry
|
71
79
|
rake (~> 11.0)
|
72
80
|
rspec (~> 3.4)
|
73
81
|
|
data/ISSUE_TEMPLATE.md
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
## Summary
|
2
|
+
|
3
|
+
<!-- This sections are meant as guidance for you. If some doesn't fit, skip them. In general: Please provide as much information as you can to help us solving your problem -->
|
4
|
+
|
5
|
+
<!--- Provide a general summary of the issue in the Title above -->
|
6
|
+
|
7
|
+
## Expected Behavior
|
8
|
+
|
9
|
+
<!--- If you're describing a bug, tell us what should happen -->
|
10
|
+
<!--- If you're suggesting a change/improvement, tell us how it should work -->
|
11
|
+
|
12
|
+
## Current Behavior
|
13
|
+
|
14
|
+
<!--- If describing a bug, tell us what happens instead of the expected behavior -->
|
15
|
+
<!--- If suggesting a change/improvement, explain the difference from current behavior -->
|
16
|
+
|
17
|
+
<!--- If you have got some output place it in the code block below. Otherwise remove it. -->
|
18
|
+
~~~
|
19
|
+
~~~
|
20
|
+
|
21
|
+
## Possible Solution
|
22
|
+
|
23
|
+
<!--- Not obligatory, but suggest a fix/reason for the bug, -->
|
24
|
+
<!--- or ideas how to implement the addition or change -->
|
25
|
+
|
26
|
+
## Steps to Reproduce (for bugs)
|
27
|
+
|
28
|
+
<!--- Provide a link to a live example, or an unambiguous set of steps to -->
|
29
|
+
<!--- reproduce this bug. Include code to reproduce, if relevant -->
|
30
|
+
1.
|
31
|
+
2.
|
32
|
+
3.
|
33
|
+
4.
|
34
|
+
|
35
|
+
## Context
|
36
|
+
|
37
|
+
<!--- How has this issue affected you? What are you trying to accomplish? -->
|
38
|
+
<!--- Providing context helps us come up with a solution that is most useful in the real world -->
|
39
|
+
|
40
|
+
## Your Environment
|
41
|
+
|
42
|
+
<!--- Include as many relevant details about the environment you experienced the bug in -->
|
43
|
+
* Version used:
|
44
|
+
* Operating System and version:
|
45
|
+
* Link to your project:
|
data/README.md
CHANGED
@@ -32,3 +32,24 @@ Feature: String constraints
|
|
32
32
|
"""
|
33
33
|
When I run the JSON data generator
|
34
34
|
Then the output should match the schema
|
35
|
+
|
36
|
+
Scenario: Possible values given
|
37
|
+
Given the following JSON schema:
|
38
|
+
"""json
|
39
|
+
{
|
40
|
+
"$schema": "http://json-schema.org/draft-04/schema#",
|
41
|
+
"type": "object",
|
42
|
+
"properties": {
|
43
|
+
"name": {
|
44
|
+
"type": "string",
|
45
|
+
"enum": [
|
46
|
+
"foo",
|
47
|
+
"bar",
|
48
|
+
"baz"
|
49
|
+
]
|
50
|
+
}
|
51
|
+
}
|
52
|
+
}
|
53
|
+
"""
|
54
|
+
When I run the JSON data generator
|
55
|
+
Then the output should match the schema
|
data/json_test_data.gemspec
CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |s|
|
|
12
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
|
15
|
+
s.add_dependency "regxing", "~> 0.1.0"
|
16
16
|
|
17
17
|
s.add_development_dependency "cucumber", "~> 2.1"
|
18
18
|
s.add_development_dependency "rspec", "~> 3.4"
|
@@ -6,6 +6,8 @@ module JsonTestData
|
|
6
6
|
|
7
7
|
class << self
|
8
8
|
def create(schema)
|
9
|
+
return schema.fetch(:enum).sample if schema.fetch(:enum, nil)
|
10
|
+
|
9
11
|
factor = schema.fetch(:multipleOf, nil)
|
10
12
|
minimum, maximum = schema.fetch(:minimum, nil), schema.fetch(:maximum, nil)
|
11
13
|
|
@@ -57,12 +59,15 @@ module JsonTestData
|
|
57
59
|
type == :integer && !@value.is_a?(Integer)
|
58
60
|
end
|
59
61
|
|
62
|
+
def adjust_by!(step_size)
|
63
|
+
@value -= step_size if value_too_high?
|
64
|
+
@value += step_size if value_too_low?
|
65
|
+
end
|
66
|
+
|
60
67
|
def adjust!
|
61
68
|
while !value_divisible_by_factor? || value_too_low? || value_too_high? || should_be_int_but_isnt?
|
62
69
|
adjust_for_divisibility!
|
63
|
-
|
64
|
-
@value -= step_size if value_too_high?
|
65
|
-
@value += step_size if value_too_low?
|
70
|
+
adjust_by!(step_size)
|
66
71
|
end
|
67
72
|
|
68
73
|
@value ||= 1
|
@@ -1,11 +1,11 @@
|
|
1
1
|
module JsonTestData
|
2
2
|
class String
|
3
|
-
extend RegXing
|
4
|
-
|
5
3
|
class << self
|
6
4
|
def create(schema)
|
5
|
+
return schema.fetch(:enum).sample if schema.fetch(:enum, nil)
|
6
|
+
|
7
7
|
len = schema.fetch(:maxLength, nil) || schema.fetch(:minLength, nil) || 1
|
8
|
-
Generator.new(/.{#{len}}/).generate!
|
8
|
+
RegXing::Generator.new(/.{#{len}}/).generate!
|
9
9
|
end
|
10
10
|
end
|
11
11
|
end
|
@@ -70,7 +70,7 @@ module JsonTestData
|
|
70
70
|
object.fetch(:minItems, nil) || object[:minItems] = 1
|
71
71
|
|
72
72
|
if object.fetch(:items, nil) && object.fetch(:items).has_key?(:type)
|
73
|
-
Array.new(object.fetch(:minItems)).map {
|
73
|
+
Array.new(object.fetch(:minItems)).map { generate(object.fetch(:items)) }
|
74
74
|
else
|
75
75
|
Array.new(object.fetch(:minItems))
|
76
76
|
end
|
@@ -54,6 +54,20 @@ describe JsonTestData::Number do
|
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
|
+
context "enum constraint" do
|
58
|
+
let(:enum) { [ 5, 10, 15, 20, 25 ] }
|
59
|
+
let(:object) do
|
60
|
+
{
|
61
|
+
type: "number",
|
62
|
+
enum: enum
|
63
|
+
}
|
64
|
+
end
|
65
|
+
|
66
|
+
it "chooses from the given array" do
|
67
|
+
expect(described_class.create(object)).to be_in enum
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
57
71
|
context "multiple constraints" do
|
58
72
|
context "maximum and minimum" do
|
59
73
|
let(:maximum) { 1 }
|
@@ -41,5 +41,20 @@ describe JsonTestData::String do
|
|
41
41
|
expect(described_class.create(object).length).to eq 8
|
42
42
|
end
|
43
43
|
end
|
44
|
+
|
45
|
+
context "with enum" do
|
46
|
+
let(:enum) { ["foo", "bar", "baz"] }
|
47
|
+
|
48
|
+
let(:object) do
|
49
|
+
{
|
50
|
+
type: "string",
|
51
|
+
enum: enum
|
52
|
+
}
|
53
|
+
end
|
54
|
+
|
55
|
+
it "returns a string from the list" do
|
56
|
+
expect(described_class.create(object)).to be_in enum
|
57
|
+
end
|
58
|
+
end
|
44
59
|
end
|
45
60
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -8,6 +8,7 @@ require_relative "../lib/json_test_data/data_structures/string"
|
|
8
8
|
require_relative "../lib/json_test_data/data_structures/number"
|
9
9
|
require_relative "./matchers/number_matchers"
|
10
10
|
require_relative "./matchers/json_schema_matchers"
|
11
|
+
require_relative "./matchers/array_matchers"
|
11
12
|
|
12
13
|
RSpec.configure do |config|
|
13
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.
|
4
|
+
version: 0.8.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-
|
11
|
+
date: 2016-05-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: regxing
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.1.0
|
19
|
+
version: 0.1.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.1.0
|
26
|
+
version: 0.1.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: cucumber
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -120,6 +120,7 @@ files:
|
|
120
120
|
- ".travis.yml"
|
121
121
|
- Gemfile
|
122
122
|
- Gemfile.lock
|
123
|
+
- ISSUE_TEMPLATE.md
|
123
124
|
- LICENSE
|
124
125
|
- README.md
|
125
126
|
- Rakefile
|
@@ -143,6 +144,7 @@ files:
|
|
143
144
|
- spec/json_test_data/data_structures/number_spec.rb
|
144
145
|
- spec/json_test_data/data_structures/string_spec.rb
|
145
146
|
- spec/json_test_data/json_schema_spec.rb
|
147
|
+
- spec/matchers/array_matchers.rb
|
146
148
|
- spec/matchers/json_schema_matchers.rb
|
147
149
|
- spec/matchers/number_matchers.rb
|
148
150
|
- spec/spec_helper.rb
|
@@ -171,7 +173,7 @@ rubyforge_project:
|
|
171
173
|
rubygems_version: 2.5.1
|
172
174
|
signing_key:
|
173
175
|
specification_version: 4
|
174
|
-
summary: json_test_data-0.
|
176
|
+
summary: json_test_data-0.8.0
|
175
177
|
test_files:
|
176
178
|
- features/array_constraints.feature
|
177
179
|
- features/data_types.feature
|
@@ -187,6 +189,7 @@ test_files:
|
|
187
189
|
- spec/json_test_data/data_structures/number_spec.rb
|
188
190
|
- spec/json_test_data/data_structures/string_spec.rb
|
189
191
|
- spec/json_test_data/json_schema_spec.rb
|
192
|
+
- spec/matchers/array_matchers.rb
|
190
193
|
- spec/matchers/json_schema_matchers.rb
|
191
194
|
- spec/matchers/number_matchers.rb
|
192
195
|
- spec/spec_helper.rb
|