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:
-rw-r--r--.rubocop_manual_todo.yml25
-rw-r--r--app/views/projects/_import_project_pane.html.haml2
-rw-r--r--app/views/projects/_new_project_fields.html.haml4
-rw-r--r--changelogs/unreleased/gl-button-new-project.yml5
-rw-r--r--doc/integration/elasticsearch.md150
-rw-r--r--doc/user/application_security/container_scanning/index.md19
-rw-r--r--doc/user/markdown.md1
-rw-r--r--spec/rubocop/cop/destroy_all_spec.rb39
-rw-r--r--spec/rubocop/cop/include_sidekiq_worker_spec.rb30
-rw-r--r--spec/rubocop/cop/performance/ar_count_each_spec.rb4
-rw-r--r--spec/rubocop/cop/performance/ar_exists_and_present_blank_spec.rb8
-rw-r--r--spec/rubocop/cop/performance/readlines_each_spec.rb23
-rw-r--r--spec/rubocop/cop/project_path_helper_spec.rb29
-rw-r--r--spec/rubocop/cop/rspec/any_instance_of_spec.rb40
-rw-r--r--spec/rubocop/cop/rspec/be_success_matcher_spec.rb27
-rw-r--r--spec/rubocop/cop/rspec/env_assignment_spec.rb33
-rw-r--r--spec/rubocop/cop/rspec/expect_gitlab_tracking_spec.rb27
-rw-r--r--spec/rubocop/cop/rspec/factories_in_migration_specs_spec.rb4
-rw-r--r--spec/rubocop/cop/rspec/factory_bot/inline_association_spec.rb30
-rw-r--r--spec/rubocop/cop/rspec/have_gitlab_http_status_spec.rb51
-rw-r--r--spec/rubocop/cop/rspec/htt_party_basic_auth_spec.rb18
-rw-r--r--spec/rubocop/cop/rspec/modify_sidekiq_middleware_spec.rb39
-rw-r--r--spec/rubocop/cop/rspec/timecop_freeze_spec.rb47
-rw-r--r--spec/rubocop/cop/rspec/timecop_travel_spec.rb47
-rw-r--r--spec/rubocop/cop/rspec/top_level_describe_path_spec.rb2
-rw-r--r--spec/rubocop/cop/safe_params_spec.rb3
-rw-r--r--spec/rubocop/cop/scalability/bulk_perform_with_context_spec.rb24
-rw-r--r--spec/rubocop/cop/scalability/cron_worker_context_spec.rb7
-rw-r--r--spec/rubocop/cop/scalability/file_uploads_spec.rb2
-rw-r--r--spec/rubocop/cop/scalability/idempotent_worker_spec.rb11
30 files changed, 226 insertions, 525 deletions
diff --git a/.rubocop_manual_todo.yml b/.rubocop_manual_todo.yml
index 131b56f8132..a66e1da24ec 100644
--- a/.rubocop_manual_todo.yml
+++ b/.rubocop_manual_todo.yml
@@ -28,31 +28,8 @@ FactoryBot/InlineAssociation:
- 'spec/factories/uploads.rb'
- 'spec/factories/wiki_pages.rb'
-InternalAffairs/DeprecateCopHelper:
+InternalAffairs/DeprecateCopHelper: # issue to resolve: https://gitlab.com/gitlab-org/gitlab/-/issues/276734
Exclude:
- - 'spec/rubocop/cop/scalability/bulk_perform_with_context_spec.rb'
- - 'spec/rubocop/cop/scalability/idempotent_worker_spec.rb'
- - 'spec/rubocop/cop/scalability/cron_worker_context_spec.rb'
- - 'spec/rubocop/cop/scalability/file_uploads_spec.rb'
- - 'spec/rubocop/cop/destroy_all_spec.rb'
- - 'spec/rubocop/cop/safe_params_spec.rb'
- - 'spec/rubocop/cop/include_sidekiq_worker_spec.rb'
- - 'spec/rubocop/cop/rspec/factories_in_migration_specs_spec.rb'
- - 'spec/rubocop/cop/rspec/timecop_freeze_spec.rb'
- - 'spec/rubocop/cop/rspec/any_instance_of_spec.rb'
- - 'spec/rubocop/cop/rspec/factory_bot/inline_association_spec.rb'
- - 'spec/rubocop/cop/rspec/top_level_describe_path_spec.rb'
- - 'spec/rubocop/cop/rspec/be_success_matcher_spec.rb'
- - 'spec/rubocop/cop/rspec/htt_party_basic_auth_spec.rb'
- - 'spec/rubocop/cop/rspec/modify_sidekiq_middleware_spec.rb'
- - 'spec/rubocop/cop/rspec/expect_gitlab_tracking_spec.rb'
- - 'spec/rubocop/cop/rspec/have_gitlab_http_status_spec.rb'
- - 'spec/rubocop/cop/rspec/timecop_travel_spec.rb'
- - 'spec/rubocop/cop/rspec/env_assignment_spec.rb'
- - 'spec/rubocop/cop/performance/ar_exists_and_present_blank_spec.rb'
- - 'spec/rubocop/cop/performance/ar_count_each_spec.rb'
- - 'spec/rubocop/cop/performance/readlines_each_spec.rb'
- - 'spec/rubocop/cop/project_path_helper_spec.rb'
- 'spec/rubocop/cop/migration/safer_boolean_column_spec.rb'
- 'spec/rubocop/cop/migration/remove_index_spec.rb'
- 'spec/rubocop/cop/migration/add_index_spec.rb'
diff --git a/app/views/projects/_import_project_pane.html.haml b/app/views/projects/_import_project_pane.html.haml
index 27d75591d3e..e6ded3ad912 100644
--- a/app/views/projects/_import_project_pane.html.haml
+++ b/app/views/projects/_import_project_pane.html.haml
@@ -8,7 +8,7 @@
.import-buttons
- if gitlab_project_import_enabled?
.import_gitlab_project.has-tooltip{ data: { container: 'body' } }
- = link_to new_import_gitlab_project_path, class: 'gl-button btn-default btn btn_import_gitlab_project project-submit', **tracking_attrs(track_label, 'click_button', 'gitlab_export') do
+ = link_to new_import_gitlab_project_path, class: 'gl-button btn-default btn btn_import_gitlab_project', **tracking_attrs(track_label, 'click_button', 'gitlab_export') do
.gl-button-icon
= sprite_icon('tanuki')
= _("GitLab export")
diff --git a/app/views/projects/_new_project_fields.html.haml b/app/views/projects/_new_project_fields.html.haml
index 2fe5ce2d5b7..41992ee5ea9 100644
--- a/app/views/projects/_new_project_fields.html.haml
+++ b/app/views/projects/_new_project_fields.html.haml
@@ -62,5 +62,5 @@
.option-description
= s_('ProjectsNew|Allows you to immediately clone this project’s repository. Skip this if you plan to push up an existing repository.')
-= f.submit _('Create project'), class: "btn btn-success project-submit", data: { track_label: "#{track_label}", track_event: "click_button", track_property: "create_project", track_value: "" }
-= link_to _('Cancel'), dashboard_projects_path, class: 'btn btn-cancel', data: { track_label: "#{track_label}", track_event: "click_button", track_property: "cancel", track_value: "" }
+= f.submit _('Create project'), class: "btn gl-button btn-success", data: { track_label: "#{track_label}", track_event: "click_button", track_property: "create_project", track_value: "" }
+= link_to _('Cancel'), dashboard_projects_path, class: 'btn gl-button btn-default btn-cancel', data: { track_label: "#{track_label}", track_event: "click_button", track_property: "cancel", track_value: "" }
diff --git a/changelogs/unreleased/gl-button-new-project.yml b/changelogs/unreleased/gl-button-new-project.yml
new file mode 100644
index 00000000000..3903f462ff0
--- /dev/null
+++ b/changelogs/unreleased/gl-button-new-project.yml
@@ -0,0 +1,5 @@
+---
+title: Apply new GitLab UI for buttons in create project page
+merge_request: 53454
+author: Yogi (@yo)
+type: other
diff --git a/doc/integration/elasticsearch.md b/doc/integration/elasticsearch.md
index 6e27d535b63..e540bc7d424 100644
--- a/doc/integration/elasticsearch.md
+++ b/doc/integration/elasticsearch.md
@@ -88,7 +88,7 @@ updated automatically.
Since Elasticsearch can read and use indices created in the previous major version, you don't need to change anything in the GitLab configuration when upgrading Elasticsearch.
-The only thing worth noting is that if you have created your current index before GitLab 13.0, you might want to [reclaim the production index name](#reclaiming-the-gitlab-production-index-name) or reindex from scratch (which will implicitly create an alias). The latter might be faster depending on the GitLab instance size. Once you do that, you'll be able to perform zero-downtime reindexing and you will benefit from any future features that will make use of the alias.
+The only thing worth noting is that if you have created your current index before GitLab 13.0, you might want to reindex from scratch (which will implicitly create an alias) in order to use some features, for example [Zero downtime reindexing](#zero-downtime-reindexing). Once you do that, you'll be able to perform zero-downtime reindexing and will benefit from any future features that make use of the alias.
## Elasticsearch repository indexer
@@ -300,139 +300,12 @@ To disable the Elasticsearch integration:
## Zero downtime reindexing
-The idea behind this reindexing method is to leverage Elasticsearch index alias
-feature to atomically swap between two indices. We'll refer to each index as
-`primary` (online and used by GitLab for read/writes) and `secondary`
-(offline, for reindexing purpose).
-
-Instead of connecting directly to the `primary` index, we'll setup an index
-alias such as we can change the underlying index at will.
-
-NOTE:
-Any index attached to the production alias is deemed a `primary` and will be
-used by the GitLab Advanced Search integration.
-
-### Pause the indexing
-
-In the **Admin Area > Settings > Advanced Search** section, select the
-**Pause Elasticsearch Indexing** setting, and then save your change.
-With this, all updates that should happen on your Elasticsearch index will be
-buffered and caught up after resuming.
-
-The indexing will also be automatically paused when the [**Trigger cluster reindexing**](#trigger-the-reindex-via-the-advanced-search-administration) button is used, and resumes when the reindexing completes or aborts.
-
-### Setup
-
-NOTE:
-If your index was created with GitLab 13.0 or greater, you can directly
-[trigger the reindex](#trigger-the-reindex-via-the-advanced-search-administration).
-
-This process involves several shell commands and curl invocations, so a good
-initial setup will help for later:
-
-```shell
-# You can find this value under Admin Area > Settings > Advanced Search > URL
-export CLUSTER_URL="http://localhost:9200"
-export PRIMARY_INDEX="gitlab-production"
-export SECONDARY_INDEX="gitlab-production-$(date +%s)"
-```
-
-### Reclaiming the `gitlab-production` index name
-
-WARNING:
-It is highly recommended that you take a snapshot of your cluster to ensure
-there is a recovery path if anything goes wrong.
-
-Due to a technical limitation, there will be a slight downtime because of the
-fact that we need to reclaim the current `primary` index to be used as the alias.
-
-To reclaim the `gitlab-production` index name, you need to first create a `secondary` index and then trigger the re-index from `primary`.
-
-#### Creating a secondary index
-
-To create a secondary index, run the following Rake task. The `SKIP_ALIAS`
-environment variable will disable the automatic creation of the Elasticsearch
-alias, which would conflict with the existing index under `$PRIMARY_INDEX`, and will
-not create a separate Issue index:
-
-```shell
-# Omnibus installation
-sudo SKIP_ALIAS=1 gitlab-rake "gitlab:elastic:create_empty_index[$SECONDARY_INDEX]"
-
-# Source installation
-SKIP_ALIAS=1 bundle exec rake "gitlab:elastic:create_empty_index[$SECONDARY_INDEX]"
-```
-
-The index should be created successfully, with the latest index options and
-mappings.
-
-#### Trigger the re-index from `primary`
-
-To trigger the re-index from `primary` index:
-
-1. Use the Elasticsearch [Reindex API](https://www.elastic.co/guide/en/elasticsearch/reference/7.6/docs-reindex.html):
-
- ```shell
- curl --request POST \
- --header 'Content-Type: application/json' \
- --data "{ \"source\": { \"index\": \"$PRIMARY_INDEX\" }, \"dest\": { \"index\": \"$SECONDARY_INDEX\" } }" \
- "$CLUSTER_URL/_reindex?slices=auto&wait_for_completion=false"
- ```
-
- There will be an output like:
-
- ```plaintext
- {"task":"3qw_Tr0YQLq7PF16Xek8YA:1012"}
- ```
-
- Note the `task` value, as it will be useful to follow the reindex progress.
-
-1. Wait for the reindex process to complete by checking the `completed` value.
- Using the `task` value form the previous step:
-
- ```shell
- export TASK_ID=3qw_Tr0YQLq7PF16Xek8YA:1012
- curl "$CLUSTER_URL/_tasks/$TASK_ID?pretty"
- ```
-
- The output will be like:
-
- ```plaintext
- {"completed":false, …}
- ```
-
- After the returned value is `true`, continue to the next step.
-
-1. Ensure that the secondary index has data in it. You can use the
- Elasticsearch API to look for the index size and compare our two indices:
-
- ```shell
- curl $CLUSTER_URL/$PRIMARY_INDEX/_count => 123123
- curl $CLUSTER_URL/$SECONDARY_INDEX/_count => 123123
- ```
-
- NOTE:
- Comparing the document count is more accurate than using the index size, as improvements to the storage might cause the new index to be smaller than the original one.
-
-1. After you are confident your `secondary` index is valid, you can process to
- the creation of the alias.
-
- ```shell
- # Delete the original index
- curl --request DELETE $CLUSTER_URL/$PRIMARY_INDEX
-
- # Create the alias and add the `secondary` index to it
- curl --request POST \
- --header 'Content-Type: application/json' \
- --data "{\"actions\":[{\"add\":{\"index\":\"$SECONDARY_INDEX\",\"alias\":\"$PRIMARY_INDEX\"}}]}}" \
- $CLUSTER_URL/_aliases
- ```
-
- The reindexing is now completed. Your GitLab instance is now ready to use the [automated in-cluster reindexing](#trigger-the-reindex-via-the-advanced-search-administration) feature for future reindexing.
-
-1. Resume the indexing
-
- Under **Admin Area > Settings > Advanced Search**, uncheck the **Pause Elasticsearch Indexing** setting and save.
+The idea behind this reindexing method is to leverage the [Elasticsearch reindex API](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html)
+and Elasticsearch index alias feature to perform the operation. We set up an index alias which connects to a
+`primary` index which is used by GitLab for reads/writes. When reindexing process starts, we temporarily pause
+the writes to the `primary` index. Then, we create another index and invoke the Reindex API which migrates the
+index data onto the new index. Once the reindexing job is complete, we switch to the new index by connecting the
+index alias to it which becomes the new `primary` index. At the end, we unpause the writes and normal operation resumes.
### Trigger the reindex via the Advanced Search administration
@@ -538,17 +411,14 @@ The following are some available Rake tasks:
| [`sudo gitlab-rake gitlab:elastic:index_projects`](https://gitlab.com/gitlab-org/gitlab/blob/master/ee/lib/tasks/gitlab/elastic.rake) | Iterates over all projects and queues Sidekiq jobs to index them in the background. |
| [`sudo gitlab-rake gitlab:elastic:index_projects_status`](https://gitlab.com/gitlab-org/gitlab/blob/master/ee/lib/tasks/gitlab/elastic.rake) | Determines the overall status of the indexing. It is done by counting the total number of indexed projects, dividing by a count of the total number of projects, then multiplying by 100. |
| [`sudo gitlab-rake gitlab:elastic:clear_index_status`](https://gitlab.com/gitlab-org/gitlab/blob/master/ee/lib/tasks/gitlab/elastic.rake) | Deletes all instances of IndexStatus for all projects. Note that this command will result in a complete wipe of the index, and it should be used with caution. |
-| [`sudo gitlab-rake gitlab:elastic:create_empty_index[<TARGET_NAME>]`](https://gitlab.com/gitlab-org/gitlab/blob/master/ee/lib/tasks/gitlab/elastic.rake) | Generates empty indexes (the default index and a separate issues index) and assigns an alias for each on the Elasticsearch side only if it doesn't already exist. |
-| [`sudo gitlab-rake gitlab:elastic:delete_index[<TARGET_NAME>]`](https://gitlab.com/gitlab-org/gitlab/blob/master/ee/lib/tasks/gitlab/elastic.rake) | Removes the GitLab indexes and aliases (if they exist) on the Elasticsearch instance. |
-| [`sudo gitlab-rake gitlab:elastic:recreate_index[<TARGET_NAME>]`](https://gitlab.com/gitlab-org/gitlab/blob/master/ee/lib/tasks/gitlab/elastic.rake) | Wrapper task for `gitlab:elastic:delete_index[<TARGET_NAME>]` and `gitlab:elastic:create_empty_index[<TARGET_NAME>]`. |
+| [`sudo gitlab-rake gitlab:elastic:create_empty_index`](https://gitlab.com/gitlab-org/gitlab/blob/master/ee/lib/tasks/gitlab/elastic.rake) | Generates empty indexes (the default index and a separate issues index) and assigns an alias for each on the Elasticsearch side only if it doesn't already exist. |
+| [`sudo gitlab-rake gitlab:elastic:delete_index`](https://gitlab.com/gitlab-org/gitlab/blob/master/ee/lib/tasks/gitlab/elastic.rake) | Removes the GitLab indexes and aliases (if they exist) on the Elasticsearch instance. |
+| [`sudo gitlab-rake gitlab:elastic:recreate_index`](https://gitlab.com/gitlab-org/gitlab/blob/master/ee/lib/tasks/gitlab/elastic.rake) | Wrapper task for `gitlab:elastic:delete_index` and `gitlab:elastic:create_empty_index`. |
| [`sudo gitlab-rake gitlab:elastic:index_snippets`](https://gitlab.com/gitlab-org/gitlab/blob/master/ee/lib/tasks/gitlab/elastic.rake) | Performs an Elasticsearch import that indexes the snippets data. |
| [`sudo gitlab-rake gitlab:elastic:projects_not_indexed`](https://gitlab.com/gitlab-org/gitlab/blob/master/ee/lib/tasks/gitlab/elastic.rake) | Displays which projects are not indexed. |
| [`sudo gitlab-rake gitlab:elastic:reindex_cluster`](https://gitlab.com/gitlab-org/gitlab/blob/master/ee/lib/tasks/gitlab/elastic.rake) | Schedules a zero-downtime cluster reindexing task. This feature should be used with an index that was created after GitLab 13.0. |
| [`sudo gitlab-rake gitlab:elastic:mark_reindex_failed`](https://gitlab.com/gitlab-org/gitlab/blob/master/ee/lib/tasks/gitlab/elastic.rake)`] | Mark the most recent re-index job as failed. |
-NOTE:
-The `TARGET_NAME` parameter is optional and will use the default index/alias name from the current `RAILS_ENV` if not set.
-
### Environment variables
In addition to the Rake tasks, there are some environment variables that can be used to modify the process:
diff --git a/doc/user/application_security/container_scanning/index.md b/doc/user/application_security/container_scanning/index.md
index 5541044fdae..66cabf7d15a 100644
--- a/doc/user/application_security/container_scanning/index.md
+++ b/doc/user/application_security/container_scanning/index.md
@@ -177,7 +177,7 @@ scanning by using the following environment variables:
| Environment Variable | Default | Description |
| ------------------------------ | ------------- | ----------- |
-| `ADDITIONAL_CA_CERT_BUNDLE` | `""` | Bundle of CA certs that you want to trust. |
+| `ADDITIONAL_CA_CERT_BUNDLE` | `""` | Bundle of CA certs that you want to trust. See [Using a custom SSL CA certificate authority](#using-a-custom-ssl-ca-certificate-authority) for more details. |
| `CLAIR_DB_CONNECTION_STRING` | `postgresql://postgres:password@clair-vulnerabilities-db:5432/postgres?sslmode=disable&statement_timeout=60000` | This variable represents the [connection string](https://www.postgresql.org/docs/9.3/libpq-connect.html#AEN39692) to the [PostgreSQL server hosting the vulnerabilities definitions](https://hub.docker.com/r/arminc/clair-db) database and **shouldn't be changed** unless you're running the image locally as described in the [Running the standalone container scanning tool](#running-the-standalone-container-scanning-tool) section. The host value for the connection string must match the [alias](https://gitlab.com/gitlab-org/gitlab/-/blob/898c5da43504eba87b749625da50098d345b60d6/lib/gitlab/ci/templates/Security/Container-Scanning.gitlab-ci.yml#L23) value of the `Container-Scanning.gitlab-ci.yml` template file, which defaults to `clair-vulnerabilities-db`. |
| `CLAIR_DB_IMAGE` | `arminc/clair-db:latest` | The Docker image name and tag for the [PostgreSQL server hosting the vulnerabilities definitions](https://hub.docker.com/r/arminc/clair-db). It can be useful to override this value with a specific version, for example, to provide a consistent set of vulnerabilities for integration testing purposes, or to refer to a locally hosted vulnerabilities database for an on-premise offline installation. |
| `CLAIR_DB_IMAGE_TAG` | `latest` | (**DEPRECATED - use `CLAIR_DB_IMAGE` instead**) The Docker image tag for the [PostgreSQL server hosting the vulnerabilities definitions](https://hub.docker.com/r/arminc/clair-db). It can be useful to override this value with a specific version, for example, to provide a consistent set of vulnerabilities for integration testing purposes. |
@@ -217,6 +217,23 @@ GitLab 13.0 and later doesn't support [`only` and `except`](../../../ci/yaml/REA
When overriding the template, you must use [`rules`](../../../ci/yaml/README.md#rules)
instead.
+## Using a custom SSL CA certificate authority
+
+You can use the `ADDITIONAL_CA_CERT_BUNDLE` environment variable to configure a custom SSL CA certificate authority, which is used to verify the peer when fetching Docker images from a registry which uses HTTPS. The `ADDITIONAL_CA_CERT_BUNDLE` value should contain the [text representation of the X.509 PEM public-key certificate](https://tools.ietf.org/html/rfc7468#section-5.1). For example, to configure this value in the `.gitlab-ci.yml` file, use the following:
+
+```yaml
+container_scanning:
+ variables:
+ ADDITIONAL_CA_CERT_BUNDLE: |
+ -----BEGIN CERTIFICATE-----
+ MIIGqTCCBJGgAwIBAgIQI7AVxxVwg2kch4d56XNdDjANBgkqhkiG9w0BAQsFADCB
+ ...
+ jWgmPqF3vUbZE0EyScetPJquRFRKIesyJuBFMAs=
+ -----END CERTIFICATE-----
+```
+
+The `ADDITIONAL_CA_CERT_BUNDLE` value can also be configured as a [custom variable in the UI](../../../ci/variables/README.md#create-a-custom-variable-in-the-ui), either as a `file`, which requires the path to the certificate, or as a variable, which requires the text representation of the certificate.
+
### Vulnerability allowlisting
To allowlist specific vulnerabilities, follow these steps:
diff --git a/doc/user/markdown.md b/doc/user/markdown.md
index d49d0a26da8..ff796409ada 100644
--- a/doc/user/markdown.md
+++ b/doc/user/markdown.md
@@ -444,7 +444,6 @@ GFM recognizes the following:
| snippet | `$123` | `namespace/project$123` | `project$123` |
| epic **(ULTIMATE)** | `&123` | `group1/subgroup&123` | |
| vulnerability **(ULTIMATE)** (1)| `[vulnerability:123]` | `[vulnerability:namespace/project/123]` | `[vulnerability:project/123]` |
-| feature flag | `[feature_flag:123]` | `[feature_flag:namespace/project/123]` | `[feature_flag:project/123]` |
| label by ID | `~123` | `namespace/project~123` | `project~123` |
| one-word label by name | `~bug` | `namespace/project~bug` | `project~bug` |
| multi-word label by name | `~"feature request"` | `namespace/project~"feature request"` | `project~"feature request"` |
diff --git a/spec/rubocop/cop/destroy_all_spec.rb b/spec/rubocop/cop/destroy_all_spec.rb
index df664724a91..f6850a00238 100644
--- a/spec/rubocop/cop/destroy_all_spec.rb
+++ b/spec/rubocop/cop/destroy_all_spec.rb
@@ -2,44 +2,41 @@
require 'fast_spec_helper'
require 'rubocop'
-require 'rubocop/rspec/support'
require_relative '../../../rubocop/cop/destroy_all'
RSpec.describe RuboCop::Cop::DestroyAll do
- include CopHelper
-
subject(:cop) { described_class.new }
it 'flags the use of destroy_all with a send receiver' do
- inspect_source('foo.destroy_all # rubocop: disable Cop/DestroyAll')
-
- expect(cop.offenses.size).to eq(1)
+ expect_offense(<<~CODE)
+ foo.destroy_all # rubocop: disable Cop/DestroyAll
+ ^^^^^^^^^^^^^^^ Use `delete_all` instead of `destroy_all`. [...]
+ CODE
end
it 'flags the use of destroy_all with a constant receiver' do
- inspect_source('User.destroy_all # rubocop: disable Cop/DestroyAll')
-
- expect(cop.offenses.size).to eq(1)
+ expect_offense(<<~CODE)
+ User.destroy_all # rubocop: disable Cop/DestroyAll
+ ^^^^^^^^^^^^^^^^ Use `delete_all` instead of `destroy_all`. [...]
+ CODE
end
it 'flags the use of destroy_all when passing arguments' do
- inspect_source('User.destroy_all([])')
-
- expect(cop.offenses.size).to eq(1)
+ expect_offense(<<~CODE)
+ User.destroy_all([])
+ ^^^^^^^^^^^^^^^^^^^^ Use `delete_all` instead of `destroy_all`. [...]
+ CODE
end
it 'flags the use of destroy_all with a local variable receiver' do
- inspect_source(<<~RUBY)
- users = User.all
- users.destroy_all # rubocop: disable Cop/DestroyAll
- RUBY
-
- expect(cop.offenses.size).to eq(1)
+ expect_offense(<<~CODE)
+ users = User.all
+ users.destroy_all # rubocop: disable Cop/DestroyAll
+ ^^^^^^^^^^^^^^^^^ Use `delete_all` instead of `destroy_all`. [...]
+ CODE
end
it 'does not flag the use of delete_all' do
- inspect_source('foo.delete_all')
-
- expect(cop.offenses).to be_empty
+ expect_no_offenses('foo.delete_all')
end
end
diff --git a/spec/rubocop/cop/include_sidekiq_worker_spec.rb b/spec/rubocop/cop/include_sidekiq_worker_spec.rb
index f12652a1a58..bdd622d4894 100644
--- a/spec/rubocop/cop/include_sidekiq_worker_spec.rb
+++ b/spec/rubocop/cop/include_sidekiq_worker_spec.rb
@@ -3,33 +3,21 @@
require 'fast_spec_helper'
require 'rubocop'
-require 'rubocop/rspec/support'
-
require_relative '../../../rubocop/cop/include_sidekiq_worker'
RSpec.describe RuboCop::Cop::IncludeSidekiqWorker do
- include CopHelper
-
subject(:cop) { described_class.new }
context 'when `Sidekiq::Worker` is included' do
- let(:source) { 'include Sidekiq::Worker' }
- let(:correct_source) { 'include ApplicationWorker' }
-
- it 'registers an offense' do
- inspect_source(source)
-
- aggregate_failures do
- expect(cop.offenses.size).to eq(1)
- expect(cop.offenses.map(&:line)).to eq([1])
- expect(cop.highlights).to eq(['Sidekiq::Worker'])
- end
- end
-
- it 'autocorrects to the right version' do
- autocorrected = autocorrect_source(source)
-
- expect(autocorrected).to eq(correct_source)
+ it 'registers an offense and corrects', :aggregate_failures do
+ expect_offense(<<~CODE)
+ include Sidekiq::Worker
+ ^^^^^^^^^^^^^^^ Include `ApplicationWorker`, not `Sidekiq::Worker`.
+ CODE
+
+ expect_correction(<<~CODE)
+ include ApplicationWorker
+ CODE
end
end
end
diff --git a/spec/rubocop/cop/performance/ar_count_each_spec.rb b/spec/rubocop/cop/performance/ar_count_each_spec.rb
index 6242c7a4c5e..402e3e93147 100644
--- a/spec/rubocop/cop/performance/ar_count_each_spec.rb
+++ b/spec/rubocop/cop/performance/ar_count_each_spec.rb
@@ -5,8 +5,6 @@ require 'rubocop'
require_relative '../../../../rubocop/cop/performance/ar_count_each.rb'
RSpec.describe RuboCop::Cop::Performance::ARCountEach do
- include CopHelper
-
subject(:cop) { described_class.new }
context 'when it is not haml file' do
@@ -32,8 +30,6 @@ RSpec.describe RuboCop::Cop::Performance::ARCountEach do
^^^^^^^^^^^^ If @users is AR relation, avoid `@users.count ...; @users.each... `, this will trigger two queries. Use `@users.load.size ...; @users.each... ` instead. If @users is an array, try to use @users.size.
@users.each { |user| display(user) }
SOURCE
-
- expect(cop.offenses.map(&:cop_name)).to contain_exactly('Performance/ARCountEach')
end
end
diff --git a/spec/rubocop/cop/performance/ar_exists_and_present_blank_spec.rb b/spec/rubocop/cop/performance/ar_exists_and_present_blank_spec.rb
index 3321d400ae1..8497ff0e909 100644
--- a/spec/rubocop/cop/performance/ar_exists_and_present_blank_spec.rb
+++ b/spec/rubocop/cop/performance/ar_exists_and_present_blank_spec.rb
@@ -5,8 +5,6 @@ require 'rubocop'
require_relative '../../../../rubocop/cop/performance/ar_exists_and_present_blank.rb'
RSpec.describe RuboCop::Cop::Performance::ARExistsAndPresentBlank do
- include CopHelper
-
subject(:cop) { described_class.new }
context 'when it is not haml file' do
@@ -32,8 +30,6 @@ RSpec.describe RuboCop::Cop::Performance::ARExistsAndPresentBlank do
show @users if @users.present?
^^^^^^^^^^^^^^^ Avoid `@users.present?`, because it will generate database query 'Select TABLE.*' which is expensive. Suggest to use `@users.any?` to replace `@users.present?`
SOURCE
-
- expect(cop.offenses.map(&:cop_name)).to contain_exactly('Performance/ARExistsAndPresentBlank')
end
end
@@ -44,8 +40,6 @@ RSpec.describe RuboCop::Cop::Performance::ARExistsAndPresentBlank do
show @users if @users.blank?
^^^^^^^^^^^^^ Avoid `@users.blank?`, because it will generate database query 'Select TABLE.*' which is expensive. Suggest to use `@users.empty?` to replace `@users.blank?`
SOURCE
-
- expect(cop.offenses.map(&:cop_name)).to contain_exactly('Performance/ARExistsAndPresentBlank')
end
end
@@ -58,8 +52,6 @@ RSpec.describe RuboCop::Cop::Performance::ARExistsAndPresentBlank do
show @users if @users.present?
^^^^^^^^^^^^^^^ Avoid `@users.present?`, because it will generate database query 'Select TABLE.*' which is expensive. Suggest to use `@users.any?` to replace `@users.present?`
SOURCE
-
- expect(cop.offenses.map(&:cop_name)).to contain_exactly('Performance/ARExistsAndPresentBlank', 'Performance/ARExistsAndPresentBlank')
end
end
diff --git a/spec/rubocop/cop/performance/readlines_each_spec.rb b/spec/rubocop/cop/performance/readlines_each_spec.rb
index c19426606f6..5a30107722a 100644
--- a/spec/rubocop/cop/performance/readlines_each_spec.rb
+++ b/spec/rubocop/cop/performance/readlines_each_spec.rb
@@ -5,19 +5,21 @@ require 'rubocop'
require_relative '../../../../rubocop/cop/performance/readlines_each'
RSpec.describe RuboCop::Cop::Performance::ReadlinesEach do
- include CopHelper
-
subject(:cop) { described_class.new }
let(:message) { 'Avoid `IO.readlines.each`, since it reads contents into memory in full. Use `IO.each_line` or `IO.each` instead.' }
shared_examples_for(:class_read) do |klass|
context "and it is called as a class method on #{klass}" do
- # We can't use `expect_offense` here because indentation changes based on `klass`
it 'flags it as an offense' do
- inspect_source "#{klass}.readlines(file_path).each { |line| puts line }"
+ leading_readline = "#{klass}.readlines(file_path)."
+ padding = " " * leading_readline.length
+ node = "#{leading_readline}each { |line| puts line }"
- expect(cop.offenses.map(&:cop_name)).to contain_exactly('Performance/ReadlinesEach')
+ expect_offense(<<~CODE, node: node)
+ %{node}
+ #{padding}^^^^ Avoid `IO.readlines.each`, since it reads contents into memory in full. [...]
+ CODE
end
end
@@ -62,9 +64,14 @@ RSpec.describe RuboCop::Cop::Performance::ReadlinesEach do
end
it 'autocorrects `readlines.each` to `each_line`' do
- expect(autocorrect_source('obj.readlines.each { |line| line }')).to(
- eq('obj.each_line { |line| line }')
- )
+ expect_offense(<<~CODE)
+ obj.readlines.each { |line| line }
+ ^^^^ Avoid `IO.readlines.each`, since it reads contents into memory in full. [...]
+ CODE
+
+ expect_correction(<<~CODE)
+ obj.each_line { |line| line }
+ CODE
end
end
diff --git a/spec/rubocop/cop/project_path_helper_spec.rb b/spec/rubocop/cop/project_path_helper_spec.rb
index 78a590b89f6..16782802a27 100644
--- a/spec/rubocop/cop/project_path_helper_spec.rb
+++ b/spec/rubocop/cop/project_path_helper_spec.rb
@@ -3,41 +3,30 @@
require 'fast_spec_helper'
require 'rubocop'
-require 'rubocop/rspec/support'
-
require_relative '../../../rubocop/cop/project_path_helper'
RSpec.describe RuboCop::Cop::ProjectPathHelper do
- include CopHelper
-
subject(:cop) { described_class.new }
context "when using namespace_project with the project's namespace" do
let(:source) { 'edit_namespace_project_issue_path(@issue.project.namespace, @issue.project, @issue)' }
let(:correct_source) { 'edit_project_issue_path(@issue.project, @issue)' }
- it 'registers an offense' do
- inspect_source(source)
-
- aggregate_failures do
- expect(cop.offenses.size).to eq(1)
- expect(cop.offenses.map(&:line)).to eq([1])
- expect(cop.highlights).to eq(['edit_namespace_project_issue_path'])
- end
- end
-
- it 'autocorrects to the right version' do
- autocorrected = autocorrect_source(source)
+ it 'registers an offense and corrects', :aggregate_failures do
+ expect_offense(<<~CODE)
+ #{source}
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use short project path helpers without explicitly passing the namespace[...]
+ CODE
- expect(autocorrected).to eq(correct_source)
+ expect_correction(<<~CODE)
+ #{correct_source}
+ CODE
end
end
context 'when using namespace_project with a different namespace' do
it 'registers no offense' do
- inspect_source('edit_namespace_project_issue_path(namespace, project)')
-
- expect(cop.offenses.size).to eq(0)
+ expect_no_offenses('edit_namespace_project_issue_path(namespace, project)')
end
end
end
diff --git a/spec/rubocop/cop/rspec/any_instance_of_spec.rb b/spec/rubocop/cop/rspec/any_instance_of_spec.rb
index 42bb7d196a1..e7675ded25e 100644
--- a/spec/rubocop/cop/rspec/any_instance_of_spec.rb
+++ b/spec/rubocop/cop/rspec/any_instance_of_spec.rb
@@ -5,59 +5,51 @@ require 'fast_spec_helper'
require_relative '../../../../rubocop/cop/rspec/any_instance_of'
RSpec.describe RuboCop::Cop::RSpec::AnyInstanceOf do
- include CopHelper
-
subject(:cop) { described_class.new }
context 'when calling allow_any_instance_of' do
let(:source) do
<<~SRC
- allow_any_instance_of(User).to receive(:invalidate_issue_cache_counts)
+ allow_any_instance_of(User).to receive(:invalidate_issue_cache_counts)
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not use `allow_any_instance_of` [...]
SRC
end
let(:corrected_source) do
<<~SRC
- allow_next_instance_of(User) do |instance|
- allow(instance).to receive(:invalidate_issue_cache_counts)
- end
+ allow_next_instance_of(User) do |instance|
+ allow(instance).to receive(:invalidate_issue_cache_counts)
+ end
SRC
end
- it 'registers an offence' do
- inspect_source(source)
-
- expect(cop.offenses.size).to eq(1)
- end
+ it 'registers an offense and corrects', :aggregate_failures do
+ expect_offense(source)
- it 'can autocorrect the source' do
- expect(autocorrect_source(source)).to eq(corrected_source)
+ expect_correction(corrected_source)
end
end
context 'when calling expect_any_instance_of' do
let(:source) do
<<~SRC
- expect_any_instance_of(User).to receive(:invalidate_issue_cache_counts).with(args).and_return(double)
+ expect_any_instance_of(User).to receive(:invalidate_issue_cache_counts).with(args).and_return(double)
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not use `expect_any_instance_of` [...]
SRC
end
let(:corrected_source) do
<<~SRC
- expect_next_instance_of(User) do |instance|
- expect(instance).to receive(:invalidate_issue_cache_counts).with(args).and_return(double)
- end
+ expect_next_instance_of(User) do |instance|
+ expect(instance).to receive(:invalidate_issue_cache_counts).with(args).and_return(double)
+ end
SRC
end
- it 'registers an offence' do
- inspect_source(source)
-
- expect(cop.offenses.size).to eq(1)
- end
+ it 'registers an offense and corrects', :aggregate_failures do
+ expect_offense(source)
- it 'can autocorrect the source' do
- expect(autocorrect_source(source)).to eq(corrected_source)
+ expect_correction(corrected_source)
end
end
end
diff --git a/spec/rubocop/cop/rspec/be_success_matcher_spec.rb b/spec/rubocop/cop/rspec/be_success_matcher_spec.rb
index d49507c89b1..050f0396fac 100644
--- a/spec/rubocop/cop/rspec/be_success_matcher_spec.rb
+++ b/spec/rubocop/cop/rspec/be_success_matcher_spec.rb
@@ -5,34 +5,27 @@ require 'rubocop'
require_relative '../../../../rubocop/cop/rspec/be_success_matcher'
RSpec.describe RuboCop::Cop::RSpec::BeSuccessMatcher do
- include CopHelper
-
let(:source_file) { 'spec/foo_spec.rb' }
subject(:cop) { described_class.new }
shared_examples 'cop' do |good:, bad:|
context "using #{bad} call" do
- it 'registers an offense' do
- inspect_source(bad, source_file)
-
- expect(cop.offenses.size).to eq(1)
- expect(cop.offenses.map(&:line)).to eq([1])
- expect(cop.highlights).to eq([bad])
- end
-
- it "autocorrects it to `#{good}`" do
- autocorrected = autocorrect_source(bad, source_file)
-
- expect(autocorrected).to eql(good)
+ it 'registers an offense and corrects', :aggregate_failures do
+ expect_offense(<<~CODE, node: bad)
+ %{node}
+ ^{node} Do not use deprecated `success?` method, use `successful?` instead.
+ CODE
+
+ expect_correction(<<~CODE)
+ #{good}
+ CODE
end
end
context "using #{good} call" do
it 'does not register an offense' do
- inspect_source(good)
-
- expect(cop.offenses).to be_empty
+ expect_no_offenses(good)
end
end
end
diff --git a/spec/rubocop/cop/rspec/env_assignment_spec.rb b/spec/rubocop/cop/rspec/env_assignment_spec.rb
index 07afd30fc90..cc132d1532a 100644
--- a/spec/rubocop/cop/rspec/env_assignment_spec.rb
+++ b/spec/rubocop/cop/rspec/env_assignment_spec.rb
@@ -3,13 +3,9 @@
require 'fast_spec_helper'
require 'rubocop'
-require 'rubocop/rspec/support'
-
require_relative '../../../../rubocop/cop/rspec/env_assignment'
RSpec.describe RuboCop::Cop::RSpec::EnvAssignment do
- include CopHelper
-
offense_call_single_quotes_key = %(ENV['FOO'] = 'bar').freeze
offense_call_double_quotes_key = %(ENV["FOO"] = 'bar').freeze
@@ -17,31 +13,24 @@ RSpec.describe RuboCop::Cop::RSpec::EnvAssignment do
subject(:cop) { described_class.new }
- shared_examples 'an offensive ENV#[]= call' do |content|
- it "registers an offense for `#{content}`" do
- inspect_source(content, source_file)
-
- expect(cop.offenses.size).to eq(1)
- expect(cop.offenses.map(&:line)).to eq([1])
- expect(cop.highlights).to eq([content])
- end
- end
-
- shared_examples 'an autocorrected ENV#[]= call' do |content, autocorrected_content|
- it "registers an offense for `#{content}` and autocorrects it to `#{autocorrected_content}`" do
- autocorrected = autocorrect_source(content, source_file)
+ shared_examples 'an offensive and correction ENV#[]= call' do |content, autocorrected_content|
+ it "registers an offense for `#{content}` and corrects", :aggregate_failures do
+ expect_offense(<<~CODE)
+ #{content}
+ ^^^^^^^^^^^^^^^^^^ Don't assign to ENV, use `stub_env` instead.
+ CODE
- expect(autocorrected).to eql(autocorrected_content)
+ expect_correction(<<~CODE)
+ #{autocorrected_content}
+ CODE
end
end
context 'with a key using single quotes' do
- it_behaves_like 'an offensive ENV#[]= call', offense_call_single_quotes_key
- it_behaves_like 'an autocorrected ENV#[]= call', offense_call_single_quotes_key, %(stub_env('FOO', 'bar'))
+ it_behaves_like 'an offensive and correction ENV#[]= call', offense_call_single_quotes_key, %(stub_env('FOO', 'bar'))
end
context 'with a key using double quotes' do
- it_behaves_like 'an offensive ENV#[]= call', offense_call_double_quotes_key
- it_behaves_like 'an autocorrected ENV#[]= call', offense_call_double_quotes_key, %(stub_env("FOO", 'bar'))
+ it_behaves_like 'an offensive and correction ENV#[]= call', offense_call_double_quotes_key, %(stub_env("FOO", 'bar'))
end
end
diff --git a/spec/rubocop/cop/rspec/expect_gitlab_tracking_spec.rb b/spec/rubocop/cop/rspec/expect_gitlab_tracking_spec.rb
index f7adc1373df..d1ce8d01e0b 100644
--- a/spec/rubocop/cop/rspec/expect_gitlab_tracking_spec.rb
+++ b/spec/rubocop/cop/rspec/expect_gitlab_tracking_spec.rb
@@ -2,13 +2,9 @@
require 'fast_spec_helper'
require 'rubocop'
-require 'rubocop/rspec/support'
-
require_relative '../../../../rubocop/cop/rspec/expect_gitlab_tracking'
RSpec.describe RuboCop::Cop::RSpec::ExpectGitlabTracking do
- include CopHelper
-
let(:source_file) { 'spec/foo_spec.rb' }
subject(:cop) { described_class.new }
@@ -36,29 +32,18 @@ RSpec.describe RuboCop::Cop::RSpec::ExpectGitlabTracking do
good_samples.each do |good|
context "good: #{good}" do
it 'does not register an offense' do
- inspect_source(good)
-
- expect(cop.offenses).to be_empty
+ expect_no_offenses(good)
end
end
end
bad_samples.each do |bad|
context "bad: #{bad}" do
- it 'registers an offense', :aggregate_failures do
- inspect_source(bad, source_file)
-
- expect(cop.offenses.size).to eq(1)
- expect(cop.offenses.map(&:line)).to eq([1])
- expect(cop.highlights).to eq([bad])
-
- msg = cop.offenses.first.message
-
- expect(msg).to match(
- /Do not expect directly on `Gitlab::Tracking#event`/
- )
- expect(msg).to match(/add the `snowplow` annotation/)
- expect(msg).to match(/use `expect_snowplow_event` instead/)
+ it 'registers an offense' do
+ expect_offense(<<~CODE, node: bad)
+ %{node}
+ ^{node} Do not expect directly on `Gitlab::Tracking#event`[...]
+ CODE
end
end
end
diff --git a/spec/rubocop/cop/rspec/factories_in_migration_specs_spec.rb b/spec/rubocop/cop/rspec/factories_in_migration_specs_spec.rb
index 7cb8354a37c..8beec53375e 100644
--- a/spec/rubocop/cop/rspec/factories_in_migration_specs_spec.rb
+++ b/spec/rubocop/cop/rspec/factories_in_migration_specs_spec.rb
@@ -3,13 +3,9 @@
require 'fast_spec_helper'
require 'rubocop'
-require 'rubocop/rspec/support'
-
require_relative '../../../../rubocop/cop/rspec/factories_in_migration_specs'
RSpec.describe RuboCop::Cop::RSpec::FactoriesInMigrationSpecs do
- include CopHelper
-
subject(:cop) { described_class.new }
shared_examples 'an offensive factory call' do |namespace|
diff --git a/spec/rubocop/cop/rspec/factory_bot/inline_association_spec.rb b/spec/rubocop/cop/rspec/factory_bot/inline_association_spec.rb
index 33fdaaee3c7..0e6af71ea3e 100644
--- a/spec/rubocop/cop/rspec/factory_bot/inline_association_spec.rb
+++ b/spec/rubocop/cop/rspec/factory_bot/inline_association_spec.rb
@@ -7,8 +7,6 @@ require 'rubocop'
require_relative '../../../../../rubocop/cop/rspec/factory_bot/inline_association'
RSpec.describe RuboCop::Cop::RSpec::FactoryBot::InlineAssociation do
- include CopHelper
-
subject(:cop) { described_class.new }
shared_examples 'offense' do |code_snippet, autocorrected|
@@ -17,27 +15,31 @@ RSpec.describe RuboCop::Cop::RSpec::FactoryBot::InlineAssociation do
let(:offense_marker) { '^' * code_snippet.size }
let(:offense_msg) { msg(type) }
let(:offense) { "#{offense_marker} #{offense_msg}" }
- let(:pristine_source) { source.sub(offense, '') }
let(:source) do
<<~RUBY
- FactoryBot.define do
- factory :project do
- attribute { #{code_snippet} }
- #{offense}
- end
+ FactoryBot.define do
+ factory :project do
+ attribute { #{code_snippet} }
+ #{offense}
end
+ end
RUBY
end
- it 'registers an offense' do
- expect_offense(source)
+ let(:corrected_source) do
+ <<~RUBY
+ FactoryBot.define do
+ factory :project do
+ attribute { #{autocorrected} }
+ end
+ end
+ RUBY
end
- it 'autocorrects the source' do
- corrected = autocorrect_source(pristine_source)
+ it 'registers an offense and corrects', :aggregate_failures do
+ expect_offense(source)
- expect(corrected).not_to include(code_snippet)
- expect(corrected).to include(autocorrected)
+ expect_correction(corrected_source)
end
end
diff --git a/spec/rubocop/cop/rspec/have_gitlab_http_status_spec.rb b/spec/rubocop/cop/rspec/have_gitlab_http_status_spec.rb
index f6040350dc0..c2d97c8992a 100644
--- a/spec/rubocop/cop/rspec/have_gitlab_http_status_spec.rb
+++ b/spec/rubocop/cop/rspec/have_gitlab_http_status_spec.rb
@@ -4,50 +4,42 @@ require 'fast_spec_helper'
require 'rspec-parameterized'
require 'rubocop'
-require 'rubocop/rspec/support'
-
require_relative '../../../../rubocop/cop/rspec/have_gitlab_http_status'
RSpec.describe RuboCop::Cop::RSpec::HaveGitlabHttpStatus do
- include CopHelper
-
using RSpec::Parameterized::TableSyntax
let(:source_file) { 'spec/foo_spec.rb' }
subject(:cop) { described_class.new }
- shared_examples 'offense' do |code|
- it 'registers an offense' do
- inspect_source(code, source_file)
+ shared_examples 'offense' do |bad, good|
+ it 'registers an offense', :aggregate_failures do
+ expect_offense(<<~CODE, node: bad)
+ %{node}
+ ^{node} [...]
+ CODE
- expect(cop.offenses.size).to eq(1)
- expect(cop.offenses.map(&:line)).to eq([1])
- expect(cop.highlights).to eq([code])
+ expect_correction(<<~CODE)
+ #{good}
+ CODE
end
end
shared_examples 'no offense' do |code|
it 'does not register an offense' do
- inspect_source(code)
-
- expect(cop.offenses).to be_empty
- end
- end
-
- shared_examples 'autocorrect' do |bad, good|
- it 'autocorrects' do
- autocorrected = autocorrect_source(bad, source_file)
-
- expect(autocorrected).to eql(good)
+ expect_no_offenses(code)
end
end
- shared_examples 'no autocorrect' do |code|
+ shared_examples 'offense with no autocorrect' do |code|
it 'does not autocorrect' do
- autocorrected = autocorrect_source(code, source_file)
+ expect_offense(<<~CODE, node: code)
+ %{node}
+ ^{node} [...]
+ CODE
- expect(autocorrected).to eql(code)
+ expect_no_corrections
end
end
@@ -64,10 +56,8 @@ RSpec.describe RuboCop::Cop::RSpec::HaveGitlabHttpStatus do
end
with_them do
- include_examples 'offense', params[:bad]
+ include_examples 'offense', params[:bad], params[:good]
include_examples 'no offense', params[:good]
- include_examples 'autocorrect', params[:bad], params[:good]
- include_examples 'no autocorrect', params[:good]
end
end
@@ -77,10 +67,8 @@ RSpec.describe RuboCop::Cop::RSpec::HaveGitlabHttpStatus do
end
with_them do
- include_examples 'offense', params[:bad]
- include_examples 'offense', params[:good]
- include_examples 'autocorrect', params[:bad], params[:good]
- include_examples 'no autocorrect', params[:good]
+ include_examples 'offense', params[:bad], params[:good]
+ include_examples 'offense with no autocorrect', params[:good]
end
end
@@ -114,7 +102,6 @@ RSpec.describe RuboCop::Cop::RSpec::HaveGitlabHttpStatus do
with_them do
include_examples 'no offense', params[:code]
- include_examples 'no autocorrect', params[:code]
end
end
end
diff --git a/spec/rubocop/cop/rspec/htt_party_basic_auth_spec.rb b/spec/rubocop/cop/rspec/htt_party_basic_auth_spec.rb
index 6e9e436602c..eac6ceb3ddf 100644
--- a/spec/rubocop/cop/rspec/htt_party_basic_auth_spec.rb
+++ b/spec/rubocop/cop/rspec/htt_party_basic_auth_spec.rb
@@ -5,12 +5,10 @@ require 'fast_spec_helper'
require_relative '../../../../rubocop/cop/rspec/httparty_basic_auth'
RSpec.describe RuboCop::Cop::RSpec::HTTPartyBasicAuth do
- include CopHelper
-
subject(:cop) { described_class.new }
context 'when passing `basic_auth: { user: ... }`' do
- it 'registers an offence' do
+ it 'registers an offense and corrects', :aggregate_failures do
expect_offense(<<~SOURCE, 'spec/foo.rb')
HTTParty.put(
url,
@@ -19,17 +17,19 @@ RSpec.describe RuboCop::Cop::RSpec::HTTPartyBasicAuth do
body: body
)
SOURCE
- end
- it 'can autocorrect the source' do
- bad = 'HTTParty.put(url, basic_auth: { user: user, password: token })'
- good = 'HTTParty.put(url, basic_auth: { username: user, password: token })'
- expect(autocorrect_source(bad)).to eq(good)
+ expect_correction(<<~SOURCE)
+ HTTParty.put(
+ url,
+ basic_auth: { username: user, password: token },
+ body: body
+ )
+ SOURCE
end
end
context 'when passing `basic_auth: { username: ... }`' do
- it 'does not register an offence' do
+ it 'does not register an offense' do
expect_no_offenses(<<~SOURCE, 'spec/frontend/fixtures/foo.rb')
HTTParty.put(
url,
diff --git a/spec/rubocop/cop/rspec/modify_sidekiq_middleware_spec.rb b/spec/rubocop/cop/rspec/modify_sidekiq_middleware_spec.rb
index d9e3ca5741c..ffabbae90dc 100644
--- a/spec/rubocop/cop/rspec/modify_sidekiq_middleware_spec.rb
+++ b/spec/rubocop/cop/rspec/modify_sidekiq_middleware_spec.rb
@@ -5,33 +5,20 @@ require 'rubocop'
require_relative '../../../../rubocop/cop/rspec/modify_sidekiq_middleware'
RSpec.describe RuboCop::Cop::RSpec::ModifySidekiqMiddleware do
- include CopHelper
-
subject(:cop) { described_class.new }
- let(:source) do
- <<~SRC
- Sidekiq::Testing.server_middleware do |chain|
- chain.add(MyCustomMiddleware)
- end
- SRC
- end
-
- let(:corrected) do
- <<~SRC
- with_sidekiq_server_middleware do |chain|
- chain.add(MyCustomMiddleware)
- end
- SRC
- end
-
- it 'registers an offence' do
- inspect_source(source)
-
- expect(cop.offenses.size).to eq(1)
- end
-
- it 'can autocorrect the source' do
- expect(autocorrect_source(source)).to eq(corrected)
+ it 'registers an offense and corrects', :aggregate_failures do
+ expect_offense(<<~CODE)
+ Sidekiq::Testing.server_middleware do |chain|
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Don't modify global sidekiq middleware, [...]
+ chain.add(MyCustomMiddleware)
+ end
+ CODE
+
+ expect_correction(<<~CODE)
+ with_sidekiq_server_middleware do |chain|
+ chain.add(MyCustomMiddleware)
+ end
+ CODE
end
end
diff --git a/spec/rubocop/cop/rspec/timecop_freeze_spec.rb b/spec/rubocop/cop/rspec/timecop_freeze_spec.rb
index b1cf82492e4..939623f8299 100644
--- a/spec/rubocop/cop/rspec/timecop_freeze_spec.rb
+++ b/spec/rubocop/cop/rspec/timecop_freeze_spec.rb
@@ -3,50 +3,29 @@
require 'fast_spec_helper'
require 'rubocop'
-require 'rubocop/rspec/support'
-
require_relative '../../../../rubocop/cop/rspec/timecop_freeze'
RSpec.describe RuboCop::Cop::RSpec::TimecopFreeze do
- include CopHelper
-
subject(:cop) { described_class.new }
context 'when calling Timecop.freeze' do
- let(:source) do
- <<~SRC
- Timecop.freeze(Time.current) { example.run }
- SRC
- end
-
- let(:corrected_source) do
- <<~SRC
- freeze_time(Time.current) { example.run }
- SRC
- end
-
- it 'registers an offence' do
- inspect_source(source)
-
- expect(cop.offenses.size).to eq(1)
- end
-
- it 'can autocorrect the source' do
- expect(autocorrect_source(source)).to eq(corrected_source)
+ it 'registers an offense and corrects', :aggregate_failures do
+ expect_offense(<<~CODE)
+ Timecop.freeze(Time.current) { example.run }
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not use `Timecop.freeze`, use `freeze_time` instead. [...]
+ CODE
+
+ expect_correction(<<~CODE)
+ freeze_time(Time.current) { example.run }
+ CODE
end
end
context 'when calling a different method on Timecop' do
- let(:source) do
- <<~SRC
- Timecop.travel(Time.current)
- SRC
- end
-
- it 'does not register an offence' do
- inspect_source(source)
-
- expect(cop.offenses).to be_empty
+ it 'does not register an offense' do
+ expect_no_offenses(<<~CODE)
+ Timecop.travel(Time.current)
+ CODE
end
end
end
diff --git a/spec/rubocop/cop/rspec/timecop_travel_spec.rb b/spec/rubocop/cop/rspec/timecop_travel_spec.rb
index 2ee8bfe9ad7..476e45e69a6 100644
--- a/spec/rubocop/cop/rspec/timecop_travel_spec.rb
+++ b/spec/rubocop/cop/rspec/timecop_travel_spec.rb
@@ -3,50 +3,29 @@
require 'fast_spec_helper'
require 'rubocop'
-require 'rubocop/rspec/support'
-
require_relative '../../../../rubocop/cop/rspec/timecop_travel'
RSpec.describe RuboCop::Cop::RSpec::TimecopTravel do
- include CopHelper
-
subject(:cop) { described_class.new }
context 'when calling Timecop.travel' do
- let(:source) do
- <<~SRC
- Timecop.travel(1.day.ago) { create(:issue) }
- SRC
- end
-
- let(:corrected_source) do
- <<~SRC
- travel_to(1.day.ago) { create(:issue) }
- SRC
- end
-
- it 'registers an offence' do
- inspect_source(source)
-
- expect(cop.offenses.size).to eq(1)
- end
-
- it 'can autocorrect the source' do
- expect(autocorrect_source(source)).to eq(corrected_source)
+ it 'registers an offense and corrects', :aggregate_failures do
+ expect_offense(<<~CODE)
+ Timecop.travel(1.day.ago) { create(:issue) }
+ ^^^^^^^^^^^^^^^^^^^^^^^^^ Do not use `Timecop.travel`, use `travel_to` instead. [...]
+ CODE
+
+ expect_correction(<<~CODE)
+ travel_to(1.day.ago) { create(:issue) }
+ CODE
end
end
context 'when calling a different method on Timecop' do
- let(:source) do
- <<~SRC
- Timecop.freeze { create(:issue) }
- SRC
- end
-
- it 'does not register an offence' do
- inspect_source(source)
-
- expect(cop.offenses).to be_empty
+ it 'does not register an offense' do
+ expect_no_offenses(<<~CODE)
+ Timecop.freeze { create(:issue) }
+ CODE
end
end
end
diff --git a/spec/rubocop/cop/rspec/top_level_describe_path_spec.rb b/spec/rubocop/cop/rspec/top_level_describe_path_spec.rb
index 4936936836d..23531cd0201 100644
--- a/spec/rubocop/cop/rspec/top_level_describe_path_spec.rb
+++ b/spec/rubocop/cop/rspec/top_level_describe_path_spec.rb
@@ -5,8 +5,6 @@ require 'rubocop'
require_relative '../../../../rubocop/cop/rspec/top_level_describe_path'
RSpec.describe RuboCop::Cop::RSpec::TopLevelDescribePath do
- include CopHelper
-
subject(:cop) { described_class.new }
context 'when the file ends in _spec.rb' do
diff --git a/spec/rubocop/cop/safe_params_spec.rb b/spec/rubocop/cop/safe_params_spec.rb
index c8f6768c4bb..62f8e542d86 100644
--- a/spec/rubocop/cop/safe_params_spec.rb
+++ b/spec/rubocop/cop/safe_params_spec.rb
@@ -2,12 +2,9 @@
require 'fast_spec_helper'
require 'rubocop'
-require 'rubocop/rspec/support'
require_relative '../../../rubocop/cop/safe_params'
RSpec.describe RuboCop::Cop::SafeParams do
- include CopHelper
-
subject(:cop) { described_class.new }
it 'flags the params as an argument of url_for' do
diff --git a/spec/rubocop/cop/scalability/bulk_perform_with_context_spec.rb b/spec/rubocop/cop/scalability/bulk_perform_with_context_spec.rb
index 6e526f7ad8f..a19ddf9dbe6 100644
--- a/spec/rubocop/cop/scalability/bulk_perform_with_context_spec.rb
+++ b/spec/rubocop/cop/scalability/bulk_perform_with_context_spec.rb
@@ -5,54 +5,44 @@ require 'rubocop'
require_relative '../../../../rubocop/cop/scalability/bulk_perform_with_context'
RSpec.describe RuboCop::Cop::Scalability::BulkPerformWithContext do
- include CopHelper
-
subject(:cop) { described_class.new }
it "adds an offense when calling bulk_perform_async" do
- inspect_source(<<~CODE)
+ expect_offense(<<~CODE)
Worker.bulk_perform_async(args)
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer using `Worker.bulk_perform_async_with_contexts` [...]
CODE
-
- expect(cop.offenses.size).to eq(1)
end
it "adds an offense when calling bulk_perform_in" do
- inspect_source(<<~CODE)
+ expect_offense(<<~CODE)
diffs.each_batch(of: BATCH_SIZE) do |relation, index|
ids = relation.pluck_primary_key.map { |id| [id] }
DeleteDiffFilesWorker.bulk_perform_in(index * 5.minutes, ids)
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer using `Worker.bulk_perform_async_with_contexts` [...]
end
CODE
-
- expect(cop.offenses.size).to eq(1)
end
it "does not add an offense for migrations" do
allow(cop).to receive(:in_migration?).and_return(true)
- inspect_source(<<~CODE)
+ expect_no_offenses(<<~CODE)
Worker.bulk_perform_in(args)
CODE
-
- expect(cop.offenses.size).to eq(0)
end
it "does not add an offence for specs" do
allow(cop).to receive(:in_spec?).and_return(true)
- inspect_source(<<~CODE)
+ expect_no_offenses(<<~CODE)
Worker.bulk_perform_in(args)
CODE
-
- expect(cop.offenses.size).to eq(0)
end
it "does not add an offense for scheduling BackgroundMigrations" do
- inspect_source(<<~CODE)
+ expect_no_offenses(<<~CODE)
BackgroundMigrationWorker.bulk_perform_in(args)
CODE
-
- expect(cop.offenses.size).to eq(0)
end
end
diff --git a/spec/rubocop/cop/scalability/cron_worker_context_spec.rb b/spec/rubocop/cop/scalability/cron_worker_context_spec.rb
index 4699e06e9cf..11b2b82d2f5 100644
--- a/spec/rubocop/cop/scalability/cron_worker_context_spec.rb
+++ b/spec/rubocop/cop/scalability/cron_worker_context_spec.rb
@@ -5,18 +5,15 @@ require 'rubocop'
require_relative '../../../../rubocop/cop/scalability/cron_worker_context'
RSpec.describe RuboCop::Cop::Scalability::CronWorkerContext do
- include CopHelper
-
subject(:cop) { described_class.new }
it 'adds an offense when including CronjobQueue' do
- inspect_source(<<~CODE)
+ expect_offense(<<~CODE)
class SomeWorker
include CronjobQueue
+ ^^^^^^^^^^^^ Manually define an ApplicationContext for cronjob-workers.[...]
end
CODE
-
- expect(cop.offenses.size).to eq(1)
end
it 'does not add offenses for other workers' do
diff --git a/spec/rubocop/cop/scalability/file_uploads_spec.rb b/spec/rubocop/cop/scalability/file_uploads_spec.rb
index 78ff7fea55c..bda5c056b03 100644
--- a/spec/rubocop/cop/scalability/file_uploads_spec.rb
+++ b/spec/rubocop/cop/scalability/file_uploads_spec.rb
@@ -5,8 +5,6 @@ require 'rubocop'
require_relative '../../../../rubocop/cop/scalability/file_uploads'
RSpec.describe RuboCop::Cop::Scalability::FileUploads do
- include CopHelper
-
subject(:cop) { described_class.new }
let(:message) { 'Do not upload files without workhorse acceleration. Please refer to https://docs.gitlab.com/ee/development/uploads.html' }
diff --git a/spec/rubocop/cop/scalability/idempotent_worker_spec.rb b/spec/rubocop/cop/scalability/idempotent_worker_spec.rb
index 666122a9de4..729f2613697 100644
--- a/spec/rubocop/cop/scalability/idempotent_worker_spec.rb
+++ b/spec/rubocop/cop/scalability/idempotent_worker_spec.rb
@@ -5,8 +5,6 @@ require 'rubocop'
require_relative '../../../../rubocop/cop/scalability/idempotent_worker'
RSpec.describe RuboCop::Cop::Scalability::IdempotentWorker do
- include CopHelper
-
subject(:cop) { described_class.new }
before do
@@ -16,21 +14,18 @@ RSpec.describe RuboCop::Cop::Scalability::IdempotentWorker do
end
it 'adds an offense when not defining idempotent method' do
- inspect_source(<<~CODE)
+ expect_offense(<<~CODE)
class SomeWorker
+ ^^^^^^^^^^^^^^^^ Avoid adding not idempotent workers.[...]
end
CODE
-
- expect(cop.offenses.size).to eq(1)
end
it 'adds an offense when not defining idempotent method' do
- inspect_source(<<~CODE)
+ expect_no_offenses(<<~CODE)
class SomeWorker
idempotent!
end
CODE
-
- expect(cop.offenses.size).to be_zero
end
end