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
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-02-06 00:09:02 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-02-06 00:09:02 +0300
commit76623c12c136f43f24c3966ed4b469e2c0b434b7 (patch)
tree7c5ec884c25e03e4fea131a4d112a9d0ccfd59b8 /spec/support
parentb042382bbf5a4977c5b5c6b0a9a33f4e8ca8d16d (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/support')
-rw-r--r--spec/support/caching.rb29
-rw-r--r--spec/support/factory_bot.rb9
-rw-r--r--spec/support/matchers/match_asset_path.rb19
-rw-r--r--spec/support/migration.rb31
-rw-r--r--spec/support/pages.rb19
-rw-r--r--spec/support/redis.rb33
-rw-r--r--spec/support/sidekiq.rb16
7 files changed, 140 insertions, 16 deletions
diff --git a/spec/support/caching.rb b/spec/support/caching.rb
new file mode 100644
index 00000000000..ecbe65f7e97
--- /dev/null
+++ b/spec/support/caching.rb
@@ -0,0 +1,29 @@
+# frozen_string_literal: true
+
+RSpec.configure do |config|
+ config.around(:each, :use_clean_rails_memory_store_caching) do |example|
+ caching_store = Rails.cache
+ Rails.cache = ActiveSupport::Cache::MemoryStore.new
+
+ example.run
+
+ Rails.cache = caching_store
+ end
+
+ config.around(:each, :use_clean_rails_memory_store_fragment_caching) do |example|
+ caching_store = ActionController::Base.cache_store
+ ActionController::Base.cache_store = ActiveSupport::Cache::MemoryStore.new
+ ActionController::Base.perform_caching = true
+
+ example.run
+
+ ActionController::Base.perform_caching = false
+ ActionController::Base.cache_store = caching_store
+ end
+
+ config.around(:each, :use_sql_query_cache) do |example|
+ ActiveRecord::Base.cache do
+ example.run
+ end
+ end
+end
diff --git a/spec/support/factory_bot.rb b/spec/support/factory_bot.rb
new file mode 100644
index 00000000000..a86161bfded
--- /dev/null
+++ b/spec/support/factory_bot.rb
@@ -0,0 +1,9 @@
+# frozen_string_literal: true
+
+FactoryBot::SyntaxRunner.class_eval do
+ include RSpec::Mocks::ExampleMethods
+end
+
+# Use FactoryBot 4.x behavior:
+# https://github.com/thoughtbot/factory_bot/blob/master/GETTING_STARTED.md#associations
+FactoryBot.use_parent_strategy = false
diff --git a/spec/support/matchers/match_asset_path.rb b/spec/support/matchers/match_asset_path.rb
new file mode 100644
index 00000000000..130b1ab02a3
--- /dev/null
+++ b/spec/support/matchers/match_asset_path.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+# add simpler way to match asset paths containing digest strings
+RSpec::Matchers.define :match_asset_path do |expected|
+ match do |actual|
+ path = Regexp.escape(expected)
+ extname = Regexp.escape(File.extname(expected))
+ digest_regex = Regexp.new(path.sub(extname, "(?:-\\h+)?#{extname}") << '$')
+ digest_regex =~ actual
+ end
+
+ failure_message do |actual|
+ "expected that #{actual} would include an asset path for #{expected}"
+ end
+
+ failure_message_when_negated do |actual|
+ "expected that #{actual} would not include an asset path for #{expected}"
+ end
+end
diff --git a/spec/support/migration.rb b/spec/support/migration.rb
new file mode 100644
index 00000000000..3c359af886d
--- /dev/null
+++ b/spec/support/migration.rb
@@ -0,0 +1,31 @@
+# frozen_string_literal: true
+
+RSpec.configure do |config|
+ # The :each scope runs "inside" the example, so this hook ensures the DB is in the
+ # correct state before any examples' before hooks are called. This prevents a
+ # problem where `ScheduleIssuesClosedAtTypeChange` (or any migration that depends
+ # on background migrations being run inline during test setup) can be broken by
+ # altering Sidekiq behavior in an unrelated spec like so:
+ #
+ # around do |example|
+ # Sidekiq::Testing.fake! do
+ # example.run
+ # end
+ # end
+ config.before(:context, :migration) do
+ schema_migrate_down!
+ end
+
+ # Each example may call `migrate!`, so we must ensure we are migrated down every time
+ config.before(:each, :migration) do
+ use_fake_application_settings
+
+ schema_migrate_down!
+ end
+
+ config.after(:context, :migration) do
+ schema_migrate_up!
+
+ Gitlab::CurrentSettings.clear_in_memory_application_settings!
+ end
+end
diff --git a/spec/support/pages.rb b/spec/support/pages.rb
new file mode 100644
index 00000000000..ad73d5b9ef5
--- /dev/null
+++ b/spec/support/pages.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+RSpec.configure do |config|
+ config.before(:each, :http_pages_enabled) do |_|
+ allow(Gitlab.config.pages).to receive(:external_http).and_return(['1.1.1.1:80'])
+ end
+
+ config.before(:each, :https_pages_enabled) do |_|
+ allow(Gitlab.config.pages).to receive(:external_https).and_return(['1.1.1.1:443'])
+ end
+
+ config.before(:each, :http_pages_disabled) do |_|
+ allow(Gitlab.config.pages).to receive(:external_http).and_return(false)
+ end
+
+ config.before(:each, :https_pages_disabled) do |_|
+ allow(Gitlab.config.pages).to receive(:external_https).and_return(false)
+ end
+end
diff --git a/spec/support/redis.rb b/spec/support/redis.rb
new file mode 100644
index 00000000000..8539f202602
--- /dev/null
+++ b/spec/support/redis.rb
@@ -0,0 +1,33 @@
+# frozen_string_literal: true
+
+RSpec.configure do |config|
+ config.after(:each, :redis) do
+ Sidekiq.redis do |connection|
+ connection.redis.flushdb
+ end
+ end
+
+ config.around(:each, :clean_gitlab_redis_cache) do |example|
+ redis_cache_cleanup!
+
+ example.run
+
+ redis_cache_cleanup!
+ end
+
+ config.around(:each, :clean_gitlab_redis_shared_state) do |example|
+ redis_shared_state_cleanup!
+
+ example.run
+
+ redis_shared_state_cleanup!
+ end
+
+ config.around(:each, :clean_gitlab_redis_queues) do |example|
+ redis_queues_cleanup!
+
+ example.run
+
+ redis_queues_cleanup!
+ end
+end
diff --git a/spec/support/sidekiq.rb b/spec/support/sidekiq.rb
index a6d6d5fc6e1..9fa8df39019 100644
--- a/spec/support/sidekiq.rb
+++ b/spec/support/sidekiq.rb
@@ -1,30 +1,14 @@
# frozen_string_literal: true
RSpec.configure do |config|
- config.around(:each, :sidekiq) do |example|
- Sidekiq::Worker.clear_all
- example.run
- Sidekiq::Worker.clear_all
- end
-
- config.after(:each, :sidekiq, :redis) do
- Sidekiq.redis do |connection|
- connection.redis.flushdb
- end
- end
-
# As we'll review the examples with this tag, we should either:
# - fix the example to not require Sidekiq inline mode (and remove this tag)
# - explicitly keep the inline mode and change the tag for `:sidekiq_inline` instead
config.around(:example, :sidekiq_might_not_need_inline) do |example|
- Sidekiq::Worker.clear_all
Sidekiq::Testing.inline! { example.run }
- Sidekiq::Worker.clear_all
end
config.around(:example, :sidekiq_inline) do |example|
- Sidekiq::Worker.clear_all
Sidekiq::Testing.inline! { example.run }
- Sidekiq::Worker.clear_all
end
end