From 99611dcc06d7e4f658505a389ffa939e8d756e23 Mon Sep 17 00:00:00 2001 From: Callum Knights Date: Mon, 19 Feb 2024 13:45:33 +0000 Subject: [PATCH] Fix linting errors --- lib/govuk_schemas/random_example.rb | 4 ++-- lib/govuk_schemas/schema.rb | 2 +- spec/lib/random_example_spec.rb | 12 ++++++------ spec/lib/random_schema_generator_spec.rb | 16 ++++++++-------- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/lib/govuk_schemas/random_example.rb b/lib/govuk_schemas/random_example.rb index 9791ccc..1131217 100644 --- a/lib/govuk_schemas/random_example.rb +++ b/lib/govuk_schemas/random_example.rb @@ -33,7 +33,7 @@ class RandomExample # @return [GovukSchemas::RandomExample] def initialize(schema:, seed: nil) @schema = schema - @random_generator = RandomSchemaGenerator.new(schema: schema, seed: seed) + @random_generator = RandomSchemaGenerator.new(schema:, seed:) end # Returns a new `GovukSchemas::RandomExample` object. @@ -58,7 +58,7 @@ def initialize(schema:, seed: nil) # the new payload. The new payload is then validated. (optional) def self.for_schema(schema_key_value, &block) schema = GovukSchemas::Schema.find(schema_key_value) - GovukSchemas::RandomExample.new(schema: schema).payload(&block) + GovukSchemas::RandomExample.new(schema:).payload(&block) end # Return a content item merged with a hash and with the excluded fields removed. diff --git a/lib/govuk_schemas/schema.rb b/lib/govuk_schemas/schema.rb index fe7109d..22ccd62 100644 --- a/lib/govuk_schemas/schema.rb +++ b/lib/govuk_schemas/schema.rb @@ -31,7 +31,7 @@ def self.all(schema_type: "*") # @param schema_type [String] The type: frontend, publisher, notification or links # @return [Hash] a JSON schema as a hash def self.random_schema(schema_type:) - all(schema_type: schema_type).values.sample + all(schema_type:).values.sample end # Return all schema names diff --git a/spec/lib/random_example_spec.rb b/spec/lib/random_example_spec.rb index d636b8f..48e4316 100644 --- a/spec/lib/random_example_spec.rb +++ b/spec/lib/random_example_spec.rb @@ -21,21 +21,21 @@ GovukSchemas::Schema.all.each do |file_path, schema| it "generates valid content for schema #{file_path}" do # This will raise an informative error if an invalid schema is generated. - GovukSchemas::RandomExample.new(schema: schema).payload + GovukSchemas::RandomExample.new(schema:).payload end end it "returns the same output if a seed is detected" do schema = GovukSchemas::Schema.random_schema(schema_type: "frontend") - first_payload = GovukSchemas::RandomExample.new(schema: schema, seed: 777).payload - second_payload = GovukSchemas::RandomExample.new(schema: schema, seed: 777).payload + first_payload = GovukSchemas::RandomExample.new(schema:, seed: 777).payload + second_payload = GovukSchemas::RandomExample.new(schema:, seed: 777).payload expect(first_payload).to eql(second_payload) end it "can customise the payload" do schema = GovukSchemas::Schema.random_schema(schema_type: "frontend") - example = GovukSchemas::RandomExample.new(schema: schema).payload do |hash| + example = GovukSchemas::RandomExample.new(schema:).payload do |hash| hash.merge("base_path" => "/some-base-path") end @@ -46,7 +46,7 @@ schema = GovukSchemas::Schema.random_schema(schema_type: "frontend") expect { - GovukSchemas::RandomExample.new(schema: schema).payload do |hash| + GovukSchemas::RandomExample.new(schema:).payload do |hash| hash["base_path"] = "/some-base-path" end }.to raise_error(GovukSchemas::InvalidContentGenerated) @@ -56,7 +56,7 @@ schema = GovukSchemas::Schema.random_schema(schema_type: "frontend") expect { - GovukSchemas::RandomExample.new(schema: schema).payload do |hash| + GovukSchemas::RandomExample.new(schema:).payload do |hash| hash.merge("base_path" => nil) end }.to raise_error(GovukSchemas::InvalidContentGenerated) diff --git a/spec/lib/random_schema_generator_spec.rb b/spec/lib/random_schema_generator_spec.rb index f49d373..52e9809 100644 --- a/spec/lib/random_schema_generator_spec.rb +++ b/spec/lib/random_schema_generator_spec.rb @@ -12,8 +12,8 @@ }, }, } - generator1 = GovukSchemas::RandomSchemaGenerator.new(schema: schema) - generator2 = GovukSchemas::RandomSchemaGenerator.new(schema: schema) + generator1 = GovukSchemas::RandomSchemaGenerator.new(schema:) + generator2 = GovukSchemas::RandomSchemaGenerator.new(schema:) expect(generator1.payload).not_to eq(generator2.payload) end @@ -31,7 +31,7 @@ }, } - generator = GovukSchemas::RandomSchemaGenerator.new(schema: schema) + generator = GovukSchemas::RandomSchemaGenerator.new(schema:) expect(generator.payload.keys).to include("my_field") end @@ -52,7 +52,7 @@ }, } - generator = GovukSchemas::RandomSchemaGenerator.new(schema: schema) + generator = GovukSchemas::RandomSchemaGenerator.new(schema:) expect(generator.payload.keys).to include("my_field") end @@ -77,7 +77,7 @@ }, } - generator = GovukSchemas::RandomSchemaGenerator.new(schema: schema) + generator = GovukSchemas::RandomSchemaGenerator.new(schema:) expect(generator.payload.keys).to include("my_field") end @@ -105,7 +105,7 @@ ], } - generator = GovukSchemas::RandomSchemaGenerator.new(schema: schema) + generator = GovukSchemas::RandomSchemaGenerator.new(schema:) expect(generator.payload["my_enum"]).to eq("a") expect(generator.payload.keys).to include("my_field") @@ -121,7 +121,7 @@ "maxItems" => 5, } - generator = GovukSchemas::RandomSchemaGenerator.new(schema: schema) + generator = GovukSchemas::RandomSchemaGenerator.new(schema:) # These stubs are to ensure determinism in the random array value # generation. @@ -143,7 +143,7 @@ "maxItems" => 3, } - generator = GovukSchemas::RandomSchemaGenerator.new(schema: schema) + generator = GovukSchemas::RandomSchemaGenerator.new(schema:) expect { generator.payload } .to raise_error "Failed to create a unique array item after 300 attempts"