diff options
author | Bundlerbot <bot@bundler.io> | 2019-08-20 06:50:17 +0000 |
---|---|---|
committer | Bundlerbot <bot@bundler.io> | 2019-08-20 06:50:17 +0000 |
commit | 870a43d4319c54f70540fb4f5c19ea784aa83b54 (patch) | |
tree | f0bb32acf91e21ecf81e96f57f4661ce1a3954ef | |
parent | 84b9238affcc6196aa0164fd48a8c77d537702d6 (diff) | |
parent | 578ec96c9ca1b16b2cf230dad539ab38d54004ba (diff) | |
download | bundler-870a43d4319c54f70540fb4f5c19ea784aa83b54.tar.gz |
Merge #7310
7310: Freeze time to avoid failures at midnight r=deivid-rodriguez a=kazu9su
### What was the end-user problem that led to this PR?
The problem was it will potentially fail if tests are executed around midnight
### What was your diagnosis of the problem?
My diagnosis was it should freeze time when executing spec
### What is your fix for the problem, implemented in this PR?
My fix is mocking `Time.now` when executing `Bundler::BuildMetadata` specs
### Why did you choose this fix out of the possible options?
I chose this fix because it doesn't have effects on other specs.
Co-authored-by: lolwut <lol@wut.com>
-rw-r--r-- | spec/bundler/build_metadata_spec.rb | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/spec/bundler/build_metadata_spec.rb b/spec/bundler/build_metadata_spec.rb index a28e25511a..afa2d1716f 100644 --- a/spec/bundler/build_metadata_spec.rb +++ b/spec/bundler/build_metadata_spec.rb @@ -4,9 +4,14 @@ require "bundler" require "bundler/build_metadata" RSpec.describe Bundler::BuildMetadata do + before do + allow(Time).to receive(:now).and_return(Time.at(0)) + Bundler::BuildMetadata.instance_variable_set(:@built_at, nil) + end + describe "#built_at" do it "returns %Y-%m-%d formatted time" do - expect(Bundler::BuildMetadata.built_at).to eq Time.now.strftime("%Y-%m-%d") + expect(Bundler::BuildMetadata.built_at).to eq "1970-01-01" end end @@ -36,7 +41,7 @@ RSpec.describe Bundler::BuildMetadata do subject { Bundler::BuildMetadata.to_h } it "returns a hash includes Built At, Git SHA and Released Version" do - expect(subject["Built At"]).to eq Time.now.strftime("%Y-%m-%d") + expect(subject["Built At"]).to eq "1970-01-01" expect(subject["Git SHA"]).to be_instance_of(String) expect(subject["Released Version"]).to be_falsey end |