Make duplicate specs conform with code qualitfy checks

The following discussions from !16515 (merged) should be addressed:

  • @splattael started a discussion: (+2 comments)

    In general I love code de-duplication 👍 However, I wonder if this is one of the rare case where duplication is not bad.

    For example, I also love the flow of GlobalPolicy spec although there's duplication everywhere.

    How about defining two individual describe blocks per policy? Similar to e.g. https://gitlab.com/gitlab-org/gitlab/blob/d27508753b3793f2434d087a85ce73d2f25794d5/spec/policies/global_policy_spec.rb#L184-194

      describe 'view_productivity_analytics' do
        context 'for anonymous' do
          let(:current_user) { nil }
    
          it { is_expected.not_to be_allowed(:view_productivity_analytics) }
        end
    
        context 'for authenticated users' do
          it { is_expected.to be_allowed(:view_productivity_analytics) }
        end
      end
    
      describe 'view_code_analytics' do
        context 'for anonymous' do
          let(:current_user) { nil }
    
          it { is_expected.not_to be_allowed(:view_code_analytics) }
        end
    
        context 'for authenticated users' do
          it { is_expected.to be_allowed(:view_code_analytics) }
        end
      end

    WDYT?

  • @splattael started a discussion:

    Same here. Any thoughts of adding some duplication here as well and creating 2 distinct describe blocks?

Assignee Loading
Time tracking Loading