Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update minimum required Ruby version #98

Merged
merged 6 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ jobs:
strategy:
fail-fast: false
matrix:
# Due to https://github.com/actions/runner/issues/849, we have to use quotes for '3.0'
ruby: ['3.0', 3.1, 3.2]
ruby: [3.1, 3.2, 3.3]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0.5
3.1.4
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Unreleased

* Drop support for Ruby 3.0. The minimum required Ruby version is now 3.1.4.
* Add support for Ruby 3.3.

# 4.7.0

* Update `json-schema` dependency.
Expand Down
2 changes: 1 addition & 1 deletion govuk_schemas.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "rspec", "~> 3.4"
spec.add_development_dependency "rubocop-govuk", "4.14.0"

spec.required_ruby_version = ">= 3.0"
spec.required_ruby_version = ">= 3.1.4"
end
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
Loading