govuk-content-schema-test-helpers 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 37cb9ff6d739ab002abb15a4702b09751d08ef23
4
- data.tar.gz: 46330545b2f74e29b19f5ed1b1a4d52e0efd9164
3
+ metadata.gz: 011b735b77af91d6916c2bc5a2a44738c7b35fa3
4
+ data.tar.gz: a2604a0fc50abdc8a4354b77e5700d4ef7097cfd
5
5
  SHA512:
6
- metadata.gz: 7af81a120a7888fa0a45579c3c56ee44e161c6395b1d88bd43eecb026e32e6dbb93c42336f16fd080cff0fc006ca91c2e2e7f5086126cd0cbdb83df42fa1b496
7
- data.tar.gz: 501ff1b09512a293cf6646013c88e57ef0e3d1e73961ec12d52faa21e11e81d8a9dd254ca35c2647b1e278f21233a6843b4beb7e689987755a83f16118882faa
6
+ metadata.gz: 18187cd7620e0191b5f4b77a885c923352463bdfc80c859d51827a6e3befe722296a7063bb50a62ef57aafda482f6a52cc6432962e50968411bd084a40f692f6
7
+ data.tar.gz: aa600d91f64117aed5a63f2f31e082bdd8a8adcfec1d5ca8114b38bd859aee3cbeb221799b53b64692998ad6ab0bcc69063d2a6df1313dcb43bdfc95bc8ec85f
data/README.md CHANGED
@@ -124,10 +124,6 @@ Then in a test:
124
124
 
125
125
  ### Running the test suite
126
126
 
127
- The tests in this project rely upon [govuk-content-schemas](http://github.com/alphagov/govuk-content-schemas) on your file system. By default these should be in a sibling directory to your project. Alternatively, you can specify their location with the `GOVUK_CONTENT_SCHEMAS_PATH` environment variable.
128
-
129
- Assuming you already have govuk-content-schemas cloned:
130
-
131
127
  ```
132
128
  bundle exec rake
133
129
  ```
@@ -1,9 +1,13 @@
1
1
  module GovukContentSchemaTestHelpers
2
2
  module Util
3
3
  def self.govuk_content_schemas_path
4
- relative_path = ENV['GOVUK_CONTENT_SCHEMAS_PATH'] || '../govuk-content-schemas'
5
- project_root = GovukContentSchemaTestHelpers.configuration.project_root
6
- File.absolute_path(relative_path, project_root)
4
+ if ENV.fetch('GOVUK_CONTENT_SCHEMAS_PATH', '').start_with?("/")
5
+ ENV['GOVUK_CONTENT_SCHEMAS_PATH']
6
+ else
7
+ relative_path = ENV['GOVUK_CONTENT_SCHEMAS_PATH'] || '../govuk-content-schemas'
8
+ project_root = GovukContentSchemaTestHelpers.configuration.project_root
9
+ File.absolute_path(relative_path, project_root)
10
+ end
7
11
  end
8
12
 
9
13
  def self.check_govuk_content_schemas_path!
@@ -2,9 +2,11 @@ require 'json-schema'
2
2
 
3
3
  module GovukContentSchemaTestHelpers
4
4
  class Validator
5
+ # Return the first schema path that exists on the filesystem
5
6
  def self.schema_path(schema_name)
6
- schema_type = GovukContentSchemaTestHelpers.configuration.schema_type
7
- File.join(Util.govuk_content_schemas_path, "/formats/#{schema_name}/#{schema_type}/schema.json").to_s
7
+ paths = candidate_schema_paths(schema_name)
8
+ paths.detect { |path| File.exists?(path) } ||
9
+ raise(ImproperlyConfiguredError, "Schema file not found at any of: #{paths.join(', ')}.")
8
10
  end
9
11
 
10
12
  # schema_name should be a string, such as 'finder'
@@ -12,9 +14,6 @@ module GovukContentSchemaTestHelpers
12
14
  def initialize(schema_name, document)
13
15
  Util.check_govuk_content_schemas_path!
14
16
  @schema_path = GovukContentSchemaTestHelpers::Validator.schema_path(schema_name)
15
- if !File.exists?(@schema_path)
16
- raise ImproperlyConfiguredError, "Schema file not found: #{@schema_path}."
17
- end
18
17
  @document = document
19
18
  end
20
19
 
@@ -25,5 +24,20 @@ module GovukContentSchemaTestHelpers
25
24
  def errors
26
25
  @errors ||= JSON::Validator.fully_validate(@schema_path, @document)
27
26
  end
27
+
28
+ private
29
+ def self.construct_schema_path(prefix, schema_name)
30
+ File.join(
31
+ Util.govuk_content_schemas_path,
32
+ prefix,
33
+ schema_name,
34
+ GovukContentSchemaTestHelpers.configuration.schema_type,
35
+ "schema.json"
36
+ )
37
+ end
38
+
39
+ def self.candidate_schema_paths(schema_name)
40
+ ["dist/formats", "formats"].map { |prefix| construct_schema_path(prefix, schema_name) }
41
+ end
28
42
  end
29
43
  end
@@ -1,3 +1,3 @@
1
1
  module GovukContentSchemaTestHelpers
2
- VERSION = '1.2.0'
2
+ VERSION = '1.3.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: govuk-content-schema-test-helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jamie Cobbett