Welcome to mirror list, hosted at ThFree Co, Russian Federation.

fabricate_usage_spec.rb « qa « cop « rubocop « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7c4b42b91e0e7dae7eb4e241aeb607d80b988846 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# frozen_string_literal: true

require 'rubocop_spec_helper'

require_relative '../../../../rubocop/cop/qa/fabricate_usage'

RSpec.describe RuboCop::Cop::QA::FabricateUsage, feature_category: :quality_management do
  let(:source_file) { 'qa/qa/specs/spec.rb' }

  it 'registers an offense when using fabricate_via_api! for a valid resource' do
    expect_offense(<<~RUBY)
      Resource::Project.fabricate_via_api! do |project|
      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer create(:project[, ...]) here.
        project.name = 'test'
      end
    RUBY
  end

  it 'registers an offense for groups' do
    expect_offense(<<~RUBY)
      Resource::Group.fabricate_via_api! do |group|
      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer create(:group[, ...]) here.
        group.path = 'test'
      end
    RUBY
  end

  it 'does not register an offense when using fabricate_via_api! for an unenforced resource' do
    expect_no_offenses(<<~RUBY)
      Resource::Invalid.fabricate_via_api! do |project|
        project.name = 'test'
      end
    RUBY
  end
end