govuk-content-schema-test-helpers 1.0.2 → 1.1.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
  SHA1:
3
- metadata.gz: 86714c339ce34aef53a446ed95e78eadf64244b1
4
- data.tar.gz: 62f4df66147eb83d8eea6f65a8e72bdcae0a6ef7
3
+ metadata.gz: a67072ac7856ffad37516d5260a262d4df89f4f7
4
+ data.tar.gz: 154ca00506f3cdf9516904de41f7e2f7fab8bdf1
5
5
  SHA512:
6
- metadata.gz: effa83b91f2b77d16df3a9d4eaebabf7eb3b41f1da5ec2d6a20d50e0e362cf6c15313ea7dc353178744265730f07ead1bc5eccdb2746065fed43d1ea34ef9708
7
- data.tar.gz: 1c82c0f72755f5350afd4d38edc510fd92a481b49cb217eb284a37cd4d0001a8c985a9527220183b31db3ac6286d5a984ee673d0879f1c45a59f9f21ad73e165
6
+ metadata.gz: 7f5b0a0f56380d258d247d574c6a69333a6f88611df0682010cf5f044cd1ed86e3b596ac57db77c6977219446fdec2e3e744440413c08854f1f19318d2e5c82c
7
+ data.tar.gz: 1df29e2bbb33772e624b5ecede8a97c80766e17b41956b3384fc6fa8c1c011a2e7a925a619f4f5791f625d5bbeabf32ec3c8307abf82f38c898cb1df42e56627
data/README.md CHANGED
@@ -41,6 +41,42 @@ If you are not using Rails, you'll need to set `project_root` differently. Assum
41
41
  # => '{ "some": "json" }'
42
42
  ```
43
43
 
44
+ #### Loading all examples for a given format
45
+
46
+
47
+ ```ruby
48
+ GovukContentSchemaTestHelpers::Examples.new.get_all_for_format('case_study')
49
+ # => ['{ "first": "example"}', '{ "second": "example" }']
50
+ ```
51
+
52
+ This would be useful for checking your app can handle all examples and any that come into existence later:
53
+
54
+ ```ruby
55
+ def supported_formats
56
+ %w{
57
+ case_study
58
+ coming_soon
59
+ }
60
+ end
61
+
62
+ def all_examples_for_supported_formats
63
+ GovukContentSchemaTestHelpers::Examples.new.get_all_for_formats(supported_formats)
64
+ end
65
+
66
+ # In an ActionDispatch::IntegrationTest, for example:
67
+ test 'that we can handle every example of the formats we support'
68
+ all_examples_for_supported_formats.each do |example|
69
+ content_item = JSON.parse(example)
70
+ content_store_has_item(content_item['base_path'], content_item)
71
+
72
+ get content_item['base_path']
73
+ assert_response 200
74
+ assert_select 'title', content_item['title']
75
+ end
76
+ end
77
+ ```
78
+
79
+
44
80
  #### RSpec matcher
45
81
 
46
82
  To use the built-in RSpec matcher, add this to spec_helper.rb:
@@ -4,22 +4,35 @@ module GovukContentSchemaTestHelpers
4
4
  Util.check_govuk_content_schemas_path!
5
5
  end
6
6
 
7
- def get(schema_name, example_name)
8
- path = example_path(schema_name, example_name)
7
+ def get(format, example_name)
8
+ path = example_path(format, example_name)
9
9
  check_example_file_exists!(path)
10
10
  File.read(path)
11
11
  end
12
12
 
13
+ def get_all_for_format(schema_name)
14
+ glob_path = example_path(schema_name, '*')
15
+ Dir.glob(glob_path).map do |path|
16
+ File.read(path)
17
+ end
18
+ end
19
+
20
+ def get_all_for_formats(schema_names)
21
+ schema_names.inject([]) do |memo, schema_name|
22
+ memo + get_all_for_format(schema_name)
23
+ end
24
+ end
25
+
13
26
  def check_example_file_exists!(path)
14
27
  if !File.exists?(path)
15
- raise ImproperlyConfiguredError, "Schema file not found: #{path}."
28
+ raise ImproperlyConfiguredError, "Example file not found: #{path}."
16
29
  end
17
30
  end
18
31
 
19
32
  private
20
- def example_path(schema_name, example_name)
33
+ def example_path(format, example_name)
21
34
  schema_type = GovukContentSchemaTestHelpers.configuration.schema_type
22
- File.join(Util.govuk_content_schemas_path, "/formats/#{schema_name}/#{schema_type}/examples/#{example_name}.json").to_s
35
+ File.join(Util.govuk_content_schemas_path, "/formats/#{format}/#{schema_type}/examples/#{example_name}.json").to_s
23
36
  end
24
37
  end
25
38
  end
@@ -1,3 +1,3 @@
1
1
  module GovukContentSchemaTestHelpers
2
- VERSION = '1.0.2'
2
+ VERSION = '1.1.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.0.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jamie Cobbett