diff --git a/govuk_schemas.gemspec b/govuk_schemas.gemspec index f774c41..20b961b 100644 --- a/govuk_schemas.gemspec +++ b/govuk_schemas.gemspec @@ -25,6 +25,7 @@ Gem::Specification.new do |spec| spec.add_development_dependency "rake", "~> 10.0" spec.add_development_dependency "rspec", "~> 3.4" spec.add_development_dependency "rubocop-govuk", "~> 3.8" + spec.add_development_dependency "timecop", "~> 0.9" spec.add_development_dependency "yard", "~> 0.8" spec.required_ruby_version = ">= 2.6" diff --git a/spec/lib/random_example_spec.rb b/spec/lib/random_example_spec.rb index afb031d..051de24 100644 --- a/spec/lib/random_example_spec.rb +++ b/spec/lib/random_example_spec.rb @@ -1,3 +1,4 @@ +require "timecop" require "spec_helper" RSpec.describe GovukSchemas::RandomExample do @@ -27,12 +28,14 @@ it "returns the same output if a seed is detected" do schema = GovukSchemas::Schema.random_schema(schema_type: "frontend") - srand(777) # these srand calls would be in the upstream application - first_payload = GovukSchemas::RandomExample.new(schema: schema).payload - srand(777) - second_payload = GovukSchemas::RandomExample.new(schema: schema).payload - - expect(first_payload).to eql(second_payload) + # freeze time to avoid inconsistent `public_updated_at` values between runs + Timecop.freeze do + srand(777) # these srand calls would be in the upstream application + first_payload = GovukSchemas::RandomExample.new(schema: schema).payload + srand(777) + second_payload = GovukSchemas::RandomExample.new(schema: schema).payload + expect(first_payload).to eql(second_payload) + end end it "can customise the payload" do