Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/gems
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-07-06 12:07:41 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-07-06 12:07:41 +0300
commitd2485dbfedc4759eba5243e0d155e34494c4429b (patch)
tree0cdd51c58aef728db2e3c7e9de09976e85c062bb /gems
parentd111e00680d2b3e46a7ee37af5499407c4a93a22 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'gems')
-rw-r--r--gems/gitlab-rspec/.rubocop.yml12
-rw-r--r--gems/gitlab-rspec/Gemfile.lock1
-rw-r--r--gems/gitlab-rspec/gitlab-rspec.gemspec1
-rw-r--r--gems/gitlab-rspec/lib/gitlab/rspec/all.rb4
-rw-r--r--gems/gitlab-rspec/lib/gitlab/rspec/configurations/time_travel.rb32
-rw-r--r--gems/gitlab-rspec/spec/gitlab/rspec/time_travel_spec.rb28
6 files changed, 78 insertions, 0 deletions
diff --git a/gems/gitlab-rspec/.rubocop.yml b/gems/gitlab-rspec/.rubocop.yml
index 8c670b439d3..a2bdc5735c4 100644
--- a/gems/gitlab-rspec/.rubocop.yml
+++ b/gems/gitlab-rspec/.rubocop.yml
@@ -1,2 +1,14 @@
inherit_from:
- ../config/rubocop.yml
+
+RSpec/InstanceVariable:
+ Exclude:
+ - spec/**/*.rb
+
+Gitlab/ChangeTimezone:
+ Exclude:
+ - spec/gitlab/rspec/time_travel_spec.rb
+
+# FIXME
+Gitlab/RSpec/AvoidSetup:
+ Enabled: false
diff --git a/gems/gitlab-rspec/Gemfile.lock b/gems/gitlab-rspec/Gemfile.lock
index 56c4b01e764..dcdb4dd009e 100644
--- a/gems/gitlab-rspec/Gemfile.lock
+++ b/gems/gitlab-rspec/Gemfile.lock
@@ -2,6 +2,7 @@ PATH
remote: .
specs:
gitlab-rspec (0.1.0)
+ activesupport (>= 6.1, < 7.1)
rspec (~> 3.0)
GEM
diff --git a/gems/gitlab-rspec/gitlab-rspec.gemspec b/gems/gitlab-rspec/gitlab-rspec.gemspec
index 60bc84fbe36..c2c5b6c60b7 100644
--- a/gems/gitlab-rspec/gitlab-rspec.gemspec
+++ b/gems/gitlab-rspec/gitlab-rspec.gemspec
@@ -18,6 +18,7 @@ Gem::Specification.new do |spec|
spec.files = Dir["lib/**/*.rb"]
spec.require_paths = ["lib"]
+ spec.add_runtime_dependency "activesupport", ">= 6.1", "< 7.1"
spec.add_runtime_dependency "rspec", "~> 3.0"
spec.add_development_dependency "factory_bot_rails", "~> 6.2.0"
diff --git a/gems/gitlab-rspec/lib/gitlab/rspec/all.rb b/gems/gitlab-rspec/lib/gitlab/rspec/all.rb
index 47beb70d23e..091d2ba0287 100644
--- a/gems/gitlab-rspec/lib/gitlab/rspec/all.rb
+++ b/gems/gitlab-rspec/lib/gitlab/rspec/all.rb
@@ -2,3 +2,7 @@
require_relative "../rspec"
require_relative "stub_env"
+
+require_relative "configurations/time_travel"
+
+Gitlab::Rspec::Configurations::TimeTravel.configure!
diff --git a/gems/gitlab-rspec/lib/gitlab/rspec/configurations/time_travel.rb b/gems/gitlab-rspec/lib/gitlab/rspec/configurations/time_travel.rb
new file mode 100644
index 00000000000..b30aa1cde0d
--- /dev/null
+++ b/gems/gitlab-rspec/lib/gitlab/rspec/configurations/time_travel.rb
@@ -0,0 +1,32 @@
+# frozen_string_literal: true
+
+require 'active_support/all'
+require 'active_support/testing/time_helpers'
+
+module Gitlab
+ module Rspec
+ module Configurations
+ class TimeTravel
+ def self.configure!
+ RSpec.configure do |config|
+ config.include ActiveSupport::Testing::TimeHelpers
+
+ config.around(:example, :freeze_time) do |example|
+ freeze_time { example.run }
+ end
+
+ config.around(:example, :time_travel_to) do |example|
+ date_or_time = example.metadata[:time_travel_to]
+
+ unless date_or_time.respond_to?(:to_time) && date_or_time.to_time.present?
+ raise 'The time_travel_to RSpec metadata must have a Date or Time value.'
+ end
+
+ travel_to(date_or_time) { example.run }
+ end
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/gems/gitlab-rspec/spec/gitlab/rspec/time_travel_spec.rb b/gems/gitlab-rspec/spec/gitlab/rspec/time_travel_spec.rb
new file mode 100644
index 00000000000..79804a99f70
--- /dev/null
+++ b/gems/gitlab-rspec/spec/gitlab/rspec/time_travel_spec.rb
@@ -0,0 +1,28 @@
+# frozen_string_literal: true
+
+RSpec.describe 'time travel' do
+ before(:all) do
+ @original_time_zone = Time.zone
+ Time.zone = 'Eastern Time (US & Canada)'
+ end
+
+ after(:all) do
+ Time.zone = @original_time_zone
+ end
+
+ describe ':freeze_time' do
+ it 'freezes time around a spec example', :freeze_time do
+ expect { sleep 0.1 }.not_to change { Time.now.to_f }
+ end
+ end
+
+ describe ':time_travel_to' do
+ it 'time-travels to the specified date', time_travel_to: '2020-01-01' do
+ expect(Date.current).to eq(Date.new(2020, 1, 1))
+ end
+
+ it 'time-travels to the specified date & time', time_travel_to: '2020-02-02 10:30:45 -0700' do
+ expect(Time.current).to eq(Time.new(2020, 2, 2, 17, 30, 45, '+00:00'))
+ end
+ end
+end