diff options
Diffstat (limited to 'spec/rubocop/cop/rspec')
-rw-r--r-- | spec/rubocop/cop/rspec/env_mocking_spec.rb | 12 | ||||
-rw-r--r-- | spec/rubocop/cop/rspec/feature_category_spec.rb (renamed from spec/rubocop/cop/rspec/invalid_feature_category_spec.rb) | 38 | ||||
-rw-r--r-- | spec/rubocop/cop/rspec/missing_feature_category_spec.rb | 31 |
3 files changed, 29 insertions, 52 deletions
diff --git a/spec/rubocop/cop/rspec/env_mocking_spec.rb b/spec/rubocop/cop/rspec/env_mocking_spec.rb index 189fccf483a..fec2000c88b 100644 --- a/spec/rubocop/cop/rspec/env_mocking_spec.rb +++ b/spec/rubocop/cop/rspec/env_mocking_spec.rb @@ -34,23 +34,23 @@ RSpec.describe RuboCop::Cop::RSpec::EnvMocking, feature_category: :tooling do context 'with mocking bracket calls ' do it_behaves_like 'cop offense mocking the ENV constant correctable with stub_env', - offense_call_brackets_string_quotes, %(stub_env('FOO', 'bar')) + offense_call_brackets_string_quotes, %(stub_env('FOO', 'bar')) it_behaves_like 'cop offense mocking the ENV constant correctable with stub_env', - offense_call_brackets_variables, %(stub_env(key, value)) + offense_call_brackets_variables, %(stub_env(key, value)) end context 'with mocking fetch calls' do it_behaves_like 'cop offense mocking the ENV constant correctable with stub_env', - offense_call_fetch_string_quotes, %(stub_env('FOO', 'bar')) + offense_call_fetch_string_quotes, %(stub_env('FOO', 'bar')) it_behaves_like 'cop offense mocking the ENV constant correctable with stub_env', - offense_call_fetch_variables, %(stub_env(key, value)) + offense_call_fetch_variables, %(stub_env(key, value)) end context 'with other special cases and variations' do it_behaves_like 'cop offense mocking the ENV constant correctable with stub_env', - offense_call_root_env_variables, %(stub_env(key, value)) + offense_call_root_env_variables, %(stub_env(key, value)) it_behaves_like 'cop offense mocking the ENV constant correctable with stub_env', - offense_call_key_value_method_calls, %(stub_env(fetch_key(object), fetch_value(object))) + offense_call_key_value_method_calls, %(stub_env(fetch_key(object), fetch_value(object))) end context 'with acceptable cases' do diff --git a/spec/rubocop/cop/rspec/invalid_feature_category_spec.rb b/spec/rubocop/cop/rspec/feature_category_spec.rb index e5287f7105e..05e3cae012e 100644 --- a/spec/rubocop/cop/rspec/invalid_feature_category_spec.rb +++ b/spec/rubocop/cop/rspec/feature_category_spec.rb @@ -3,14 +3,15 @@ require 'rubocop_spec_helper' require 'rspec-parameterized' -require_relative '../../../../rubocop/cop/rspec/invalid_feature_category' +require_relative '../../../../rubocop/feature_categories' +require_relative '../../../../rubocop/cop/rspec/feature_category' -RSpec.describe RuboCop::Cop::RSpec::InvalidFeatureCategory, feature_category: :tooling do +RSpec.describe RuboCop::Cop::RSpec::FeatureCategory, feature_category: :tooling do shared_examples 'feature category validation' do |valid_category| it 'flags invalid feature category in top level example group' do expect_offense(<<~RUBY, invalid: invalid_category) RSpec.describe 'foo', feature_category: :%{invalid}, foo: :bar do - ^^{invalid} Please use a valid feature category. See https://docs.gitlab.com/ee/development/feature_categorization/#rspec-examples. + ^^{invalid} Please use a valid feature category. See https://docs.gitlab.com/ee/development/feature_categorization/#rspec-examples end RUBY end @@ -19,7 +20,7 @@ RSpec.describe RuboCop::Cop::RSpec::InvalidFeatureCategory, feature_category: :t expect_offense(<<~RUBY, valid: valid_category, invalid: invalid_category) RSpec.describe 'foo', feature_category: :"%{valid}" do context 'bar', foo: :bar, feature_category: :%{invalid} do - ^^{invalid} Please use a valid feature category. See https://docs.gitlab.com/ee/development/feature_categorization/#rspec-examples. + ^^{invalid} Please use a valid feature category. See https://docs.gitlab.com/ee/development/feature_categorization/#rspec-examples end end RUBY @@ -29,7 +30,7 @@ RSpec.describe RuboCop::Cop::RSpec::InvalidFeatureCategory, feature_category: :t expect_offense(<<~RUBY, valid: valid_category, invalid: invalid_category) RSpec.describe 'foo', feature_category: :"%{valid}" do it 'bar', feature_category: :%{invalid} do - ^^{invalid} Please use a valid feature category. See https://docs.gitlab.com/ee/development/feature_categorization/#rspec-examples. + ^^{invalid} Please use a valid feature category. See https://docs.gitlab.com/ee/development/feature_categorization/#rspec-examples end end RUBY @@ -63,21 +64,14 @@ RSpec.describe RuboCop::Cop::RSpec::InvalidFeatureCategory, feature_category: :t let(:invalid_category) { :invalid_category } - context 'with categories defined in config/feature_categories.yml' do - where(:valid_category) do - YAML.load_file(rails_root_join('config/feature_categories.yml')) - end + context 'with defined in config/feature_categories.yml and custom categories' do + where(:valid_category) { RuboCop::FeatureCategories.available_with_custom.to_a } with_them do it_behaves_like 'feature category validation', params[:valid_category] end end - context 'with custom categories' do - it_behaves_like 'feature category validation', 'tooling' - it_behaves_like 'feature category validation', 'shared' - end - it 'flags invalid feature category for non-symbols' do expect_offense(<<~RUBY, invalid: invalid_category) RSpec.describe 'foo', feature_category: "%{invalid}" do @@ -91,9 +85,11 @@ RSpec.describe RuboCop::Cop::RSpec::InvalidFeatureCategory, feature_category: :t end it 'does not flag use of invalid categories in non-example code' do + valid_category = RuboCop::FeatureCategories.available.first + # See https://gitlab.com/gitlab-org/gitlab/-/issues/381882#note_1265865125 expect_no_offenses(<<~RUBY) - RSpec.describe 'A spec' do + RSpec.describe 'A spec', feature_category: :#{valid_category} do let(:api_handler) do Class.new(described_class) do namespace '/test' do @@ -112,6 +108,18 @@ RSpec.describe RuboCop::Cop::RSpec::InvalidFeatureCategory, feature_category: :t RUBY end + it 'flags missing feature category in top level example group' do + expect_offense(<<~RUBY) + RSpec.describe 'foo' do + ^^^^^^^^^^^^^^^^^^^^^^^ Please use a valid feature category. See https://docs.gitlab.com/ee/development/feature_categorization/#rspec-examples + end + + RSpec.describe 'foo', some: :tag do + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Please use a valid feature category. See https://docs.gitlab.com/ee/development/feature_categorization/#rspec-examples + end + RUBY + end + describe '#external_dependency_checksum' do it 'returns a SHA256 digest used by RuboCop to invalid cache' do expect(cop.external_dependency_checksum).to match(/^\h{64}$/) diff --git a/spec/rubocop/cop/rspec/missing_feature_category_spec.rb b/spec/rubocop/cop/rspec/missing_feature_category_spec.rb deleted file mode 100644 index 41b1d2b8580..00000000000 --- a/spec/rubocop/cop/rspec/missing_feature_category_spec.rb +++ /dev/null @@ -1,31 +0,0 @@ -# frozen_string_literal: true - -require 'rubocop_spec_helper' -require_relative '../../../../rubocop/cop/rspec/missing_feature_category' - -RSpec.describe RuboCop::Cop::RSpec::MissingFeatureCategory, feature_category: :tooling do - it 'flags missing feature category in top level example group' do - expect_offense(<<~RUBY) - RSpec.describe 'foo' do - ^^^^^^^^^^^^^^^^^^^^ Please add missing feature category. See https://docs.gitlab.com/ee/development/feature_categorization/#rspec-examples. - end - - RSpec.describe 'foo', some: :tag do - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Please add missing feature category. See https://docs.gitlab.com/ee/development/feature_categorization/#rspec-examples. - end - RUBY - end - - it 'does not flag if feature category is defined' do - expect_no_offenses(<<~RUBY) - RSpec.describe 'foo', feature_category: :foo do - end - - RSpec.describe 'foo', some: :tag, feature_category: :foo do - end - - RSpec.describe 'foo', feature_category: :foo, some: :tag do - end - RUBY - end -end |