diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-05-17 15:07:12 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-05-17 15:07:12 +0300 |
commit | 43771438e9ccf20d1b6cf12b690e63844d7c3d49 (patch) | |
tree | 147aefba22d99be62ff3c112f50e205e486e58c7 /spec/rubocop | |
parent | eeb25534bae1021f5b7940138ee56dea8fc79949 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/rubocop')
-rw-r--r-- | spec/rubocop/cop/rspec/factory_bot/local_static_assignment_spec.rb | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/spec/rubocop/cop/rspec/factory_bot/local_static_assignment_spec.rb b/spec/rubocop/cop/rspec/factory_bot/local_static_assignment_spec.rb new file mode 100644 index 00000000000..de86435616c --- /dev/null +++ b/spec/rubocop/cop/rspec/factory_bot/local_static_assignment_spec.rb @@ -0,0 +1,62 @@ +# frozen_string_literal: true + +require 'rubocop_spec_helper' + +require_relative '../../../../../rubocop/cop/rspec/factory_bot/local_static_assignment' + +RSpec.describe RuboCop::Cop::RSpec::FactoryBot::LocalStaticAssignment, feature_category: :tooling do + shared_examples 'local static assignment' do |block| + it "flags static local assignment in `#{block}`" do + expect_offense(<<~RUBY, block: block) + %{block} do + age + name + + random_number = rand(23) + ^^^^^^^^^^^^^^^^^^^^^^^^ Avoid local static assignemnts in factories which lead to static data definitions. + + random_string = SecureRandom.uuid + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Avoid local static assignemnts in factories which lead to static data definitions. + + project + end + RUBY + end + + it 'does not flag correct use' do + expect_no_offenses(<<~RUBY) + #{block} do + age do + random_number = rand(23) + random_number + 1 + end + end + RUBY + end + end + + it_behaves_like 'local static assignment', 'factory :project' + it_behaves_like 'local static assignment', 'transient' + it_behaves_like 'local static assignment', 'trait :closed' + + it 'does not flag local assignments in unrelated blocks' do + expect_no_offenses(<<~RUBY) + factory :project do + sequence(:number) do |n| + random_number = rand(23) + random_number * n + end + + name do + random_string = SecureRandom.uuid + random_string + "-name" + end + + initialize_with do + random_string = SecureRandom.uuid + new(name: random_string) + end + end + RUBY + end +end |