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

top_level_describe_path_spec.rb « rspec « cop « rubocop « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 78e6bec51d49985b7736a074c579a4799f8fdfcf (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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# frozen_string_literal: true

require 'fast_spec_helper'
require_relative '../../../../rubocop/cop/rspec/top_level_describe_path'

RSpec.describe RuboCop::Cop::RSpec::TopLevelDescribePath do
  subject(:cop) { described_class.new }

  context 'when the file ends in _spec.rb' do
    it 'registers no offenses' do
      expect_no_offenses(<<~SOURCE, 'spec/foo_spec.rb')
        describe 'Foo' do
        end
      SOURCE
    end
  end

  context 'when the file is a frontend fixture' do
    it 'registers no offenses' do
      expect_no_offenses(<<~SOURCE, 'spec/frontend/fixtures/foo.rb')
        describe 'Foo' do
        end
      SOURCE
    end
  end

  context 'when the describe is in a shared example' do
    context 'with shared_examples' do
      it 'registers no offenses' do
        expect_no_offenses(<<~SOURCE, 'spec/foo.rb')
          shared_examples 'Foo' do
            describe '#bar' do
            end
          end
        SOURCE
      end
    end

    context 'with shared_examples_for' do
      it 'registers no offenses' do
        expect_no_offenses(<<~SOURCE, 'spec/foo.rb')
          shared_examples_for 'Foo' do
            describe '#bar' do
            end
          end
        SOURCE
      end
    end
  end

  context 'when the describe is at the top level' do
    it 'marks the describe as offending' do
      expect_offense(<<~SOURCE, 'spec/foo.rb')
        describe 'Foo' do
        ^^^^^^^^^^^^^^ #{described_class::MESSAGE}
        end
      SOURCE
    end
  end
end