Skip to content

Commit

Permalink
Fix linting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
callumknights committed Feb 19, 2024
1 parent 2c14c58 commit 99611dc
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions lib/govuk_schemas/random_example.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion lib/govuk_schemas/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions spec/lib/random_example_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand All @@ -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)
Expand Down
16 changes: 8 additions & 8 deletions spec/lib/random_schema_generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -31,7 +31,7 @@
},
}

generator = GovukSchemas::RandomSchemaGenerator.new(schema: schema)
generator = GovukSchemas::RandomSchemaGenerator.new(schema:)

expect(generator.payload.keys).to include("my_field")
end
Expand All @@ -52,7 +52,7 @@
},
}

generator = GovukSchemas::RandomSchemaGenerator.new(schema: schema)
generator = GovukSchemas::RandomSchemaGenerator.new(schema:)

expect(generator.payload.keys).to include("my_field")
end
Expand All @@ -77,7 +77,7 @@
},
}

generator = GovukSchemas::RandomSchemaGenerator.new(schema: schema)
generator = GovukSchemas::RandomSchemaGenerator.new(schema:)

expect(generator.payload.keys).to include("my_field")
end
Expand Down Expand Up @@ -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")
Expand All @@ -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.
Expand All @@ -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"
Expand Down

0 comments on commit 99611dc

Please sign in to comment.