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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d779c1457f7f93ea1073c9e12d4e872c45718d2dc5b94d7e0fd675e01cff8381
4
- data.tar.gz: 0e30a9825268437d349da3c2120f7f7e1961201ded04465823f1521b04e0faaa
3
+ metadata.gz: 6626f2907a18758bbc7423c1e09d3ba84ca93a6aef074b379fdda0a10c69de04
4
+ data.tar.gz: 1989abffa16d6d7757c5bc97bdc0dfbdf30dfab585b2e72f7068ee4d3e333796
5
5
  SHA512:
6
- metadata.gz: 4396a0b861ab1fce0480c99e961854febf90e662fbacb9e8c555383b610540ac32aa38272bbc85a190243ac6a02434eb0d18e19c9d58ebb1eaca8f8e9bc3e7ac
7
- data.tar.gz: cdbc5287a647d831c3c178cb0a5824d226291f11c2799e5564647b4140822198dbccbe8e4fa4b9d01f9c6cc0fd34aeb7b71ab206c7b7a3e273b1f118c20fdfef
6
+ metadata.gz: 92b65ec5f3b8ee3c9c7cfc3a153f89f4b7b9452764215b81b6234568748b1520486645febcc0fd8b840c1c2d4ab3a529a357e3b6ec8c43e0948301781d5fa86f
7
+ data.tar.gz: 97f7999ef514ad1cb5e50b7d87237e5c00c4dc5968785ff5720887faff0f5d2ef777ebda047d3239d13bd38d8ba213395425be306ea3c4f96eeddc1a18abbea0
@@ -19,7 +19,7 @@ jobs:
19
19
  runs-on: ubuntu-latest
20
20
  strategy:
21
21
  matrix:
22
- ruby-version: ['3.1', '3.2', '3.3']
22
+ ruby-version: ['3.4', '4.0']
23
23
 
24
24
  steps:
25
25
  - uses: actions/checkout@v4
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- schema-test (0.3.0)
4
+ schema-test (0.4.0)
5
5
  json
6
6
  json_schemer
7
7
 
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
- {:version=>1,
177
- :schema=>
178
- {"$schema"=>"http://json-schema.org/draft-07/schema#",
179
- "$id"=>"http://mydomain/v1/user.json",
180
- "title"=>"user",
181
- "type"=>"object",
182
- "properties"=>
183
- {"id"=>{"type"=>"integer"},
184
- "name"=>{"type"=>"string"},
185
- "avatar_url"=>{"type"=>"string", "format"=>"uri"},
186
- "follower_count"=>{"type"=>"integer}},
187
- "required"=>["id", "name", "avatar_url", "follower_count"],
188
- "additionalProperties"=>false}}
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(/:version\s*=>\s*([^,}]+)/)
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})"
@@ -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 + ',')
@@ -1,3 +1,3 @@
1
1
  module SchemaTest
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
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
- collapser = SchemaTest::Collapser.new(contents)
116
- File.write(file, collapser.output)
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.3.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: 2026-07-22 00:00:00.000000000 Z
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: '0'
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: 3.5.22
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: []