schema-test 0.3.0 → 0.4.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/.github/workflows/tests.yml +1 -1
- data/Gemfile.lock +1 -1
- data/README.md +16 -15
- data/lib/schema_test/collapser.rb +5 -1
- data/lib/schema_test/rewriter.rb +1 -1
- data/lib/schema_test/version.rb +1 -1
- data/lib/schema_test.rb +8 -2
- data/schema-test.gemspec +2 -0
- metadata +4 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6626f2907a18758bbc7423c1e09d3ba84ca93a6aef074b379fdda0a10c69de04
|
|
4
|
+
data.tar.gz: 1989abffa16d6d7757c5bc97bdc0dfbdf30dfab585b2e72f7068ee4d3e333796
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 92b65ec5f3b8ee3c9c7cfc3a153f89f4b7b9452764215b81b6234568748b1520486645febcc0fd8b840c1c2d4ab3a529a357e3b6ec8c43e0948301781d5fa86f
|
|
7
|
+
data.tar.gz: 97f7999ef514ad1cb5e50b7d87237e5c00c4dc5968785ff5720887faff0f5d2ef777ebda047d3239d13bd38d8ba213395425be306ea3c4f96eeddc1a18abbea0
|
data/.github/workflows/tests.yml
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
|
@@ -171,21 +171,22 @@ test 'JSON returned matches schema' do
|
|
|
171
171
|
get :show, params: { id: user.id }
|
|
172
172
|
|
|
173
173
|
json = JSON.parse(response.body)
|
|
174
|
-
assert_valid_json_for_schema( # EXPANDED
|
|
175
|
-
json,
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
"
|
|
181
|
-
"
|
|
182
|
-
"
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
"
|
|
186
|
-
"
|
|
187
|
-
|
|
188
|
-
"
|
|
174
|
+
assert_valid_json_for_schema( # EXPANDED from test/schemas/user.rb:1
|
|
175
|
+
json,
|
|
176
|
+
:user,
|
|
177
|
+
{version: 1,
|
|
178
|
+
schema:
|
|
179
|
+
{"$schema" => "http://json-schema.org/draft-07/schema#",
|
|
180
|
+
"$id" => "http://mydomain/v1/user.json",
|
|
181
|
+
"title" => "user",
|
|
182
|
+
"type" => "object",
|
|
183
|
+
"properties" =>
|
|
184
|
+
{"id" => {"type" => "integer"},
|
|
185
|
+
"name" => {"type" => "string"},
|
|
186
|
+
"avatar_url" => {"type" => "string", "format" => "uri"},
|
|
187
|
+
"follower_count" => {"type" => "integer"}},
|
|
188
|
+
"required" => ["id", "name", "avatar_url", "follower_count"],
|
|
189
|
+
"additionalProperties" => false}}
|
|
189
190
|
) # END EXPANDED
|
|
190
191
|
end
|
|
191
192
|
```
|
|
@@ -36,7 +36,11 @@ module SchemaTest
|
|
|
36
36
|
# Extract name and version from the content
|
|
37
37
|
joined = content_lines.map(&:strip).join(' ')
|
|
38
38
|
name = joined.match(/:(\w+),/)[1]
|
|
39
|
-
version_match = joined.match(
|
|
39
|
+
version_match = joined.match(/\bversion:\s*([^,}]+)/)
|
|
40
|
+
unless version_match
|
|
41
|
+
raise SchemaTest::Error, "Could not find `version:` in the expanded assertion at line #{i + 1}. " \
|
|
42
|
+
"Blocks expanded before Ruby 3.4 use `:version=>`; run the tests once to re-expand them, then collapse again."
|
|
43
|
+
end
|
|
40
44
|
version = version_match[1].strip
|
|
41
45
|
|
|
42
46
|
result << "#{indent}#{method_name}(#{json_var}, :#{name}, version: #{version})"
|
data/lib/schema_test/rewriter.rb
CHANGED
|
@@ -39,7 +39,7 @@ module SchemaTest
|
|
|
39
39
|
(end_index - start_index + 1).times { |i| lines.delete_at(start_index) }
|
|
40
40
|
|
|
41
41
|
output = StringIO.new
|
|
42
|
-
PP.pp([name, version: version, schema: expected_schema], output)
|
|
42
|
+
PP.pp([name, version: version, schema: expected_schema], output, 79)
|
|
43
43
|
output.rewind
|
|
44
44
|
expanded_schema_lines = output.read.strip.gsub(/\A\[/, '').gsub(/\]\z/, '').split("\n")
|
|
45
45
|
expanded_schema_lines.unshift(json_variable_name + ',')
|
data/lib/schema_test/version.rb
CHANGED
data/lib/schema_test.rb
CHANGED
|
@@ -109,12 +109,18 @@ module SchemaTest
|
|
|
109
109
|
[path]
|
|
110
110
|
end
|
|
111
111
|
end
|
|
112
|
+
collapsed = {}
|
|
113
|
+
errors = []
|
|
112
114
|
files.each do |file|
|
|
113
115
|
contents = File.read(file)
|
|
114
116
|
next unless contents.include?(OPENING_COMMENT)
|
|
115
|
-
|
|
116
|
-
|
|
117
|
+
collapsed[file] = SchemaTest::Collapser.new(contents).output
|
|
118
|
+
rescue SchemaTest::Error => e
|
|
119
|
+
errors << "#{file}: #{e.message}"
|
|
117
120
|
end
|
|
121
|
+
raise SchemaTest::Error, errors.join("\n") if errors.any?
|
|
122
|
+
|
|
123
|
+
collapsed.each { |file, output| File.write(file, output) }
|
|
118
124
|
end
|
|
119
125
|
|
|
120
126
|
# Validate some JSON data against a schema or schema definition
|
data/schema-test.gemspec
CHANGED
|
@@ -13,6 +13,8 @@ Gem::Specification.new do |spec|
|
|
|
13
13
|
spec.homepage = "https://github.com/lazyatom/schema-test"
|
|
14
14
|
spec.license = "MIT"
|
|
15
15
|
|
|
16
|
+
spec.required_ruby_version = ">= 3.4"
|
|
17
|
+
|
|
16
18
|
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
|
17
19
|
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
|
18
20
|
if spec.respond_to?(:metadata)
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: schema-test
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- James Adam
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: exe
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: json
|
|
@@ -133,7 +132,6 @@ metadata:
|
|
|
133
132
|
homepage_uri: https://github.com/lazyatom/schema-test
|
|
134
133
|
source_code_uri: https://github.com/lazyatom/schema-test
|
|
135
134
|
changelog_uri: https://github.com/lazyatom/schema-test
|
|
136
|
-
post_install_message:
|
|
137
135
|
rdoc_options: []
|
|
138
136
|
require_paths:
|
|
139
137
|
- lib
|
|
@@ -141,15 +139,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
141
139
|
requirements:
|
|
142
140
|
- - ">="
|
|
143
141
|
- !ruby/object:Gem::Version
|
|
144
|
-
version: '
|
|
142
|
+
version: '3.4'
|
|
145
143
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
146
144
|
requirements:
|
|
147
145
|
- - ">="
|
|
148
146
|
- !ruby/object:Gem::Version
|
|
149
147
|
version: '0'
|
|
150
148
|
requirements: []
|
|
151
|
-
rubygems_version:
|
|
152
|
-
signing_key:
|
|
149
|
+
rubygems_version: 4.0.20
|
|
153
150
|
specification_version: 4
|
|
154
151
|
summary: API testing against declarative schemas
|
|
155
152
|
test_files: []
|