File: blob_language_from_git_attributes_spec.rb

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (32 lines) | stat: -rw-r--r-- 968 bytes parent folder | download
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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe BlobLanguageFromGitAttributes do
  include FakeBlobHelpers

  let(:project) { build(:project, :repository) }

  describe '#language_from_gitattributes' do
    subject(:blob) { fake_blob(path: 'file.md') }

    it 'returns return value from gitattribute' do
      allow(blob.repository).to receive(:exists?).and_return(true)
      expect(blob.repository).to receive(:gitattribute).with(blob.path, 'gitlab-language').and_return('erb?parent=json')

      expect(blob.language_from_gitattributes).to eq('erb?parent=json')
    end

    it 'returns nil if repository is absent' do
      allow(blob).to receive(:repository).and_return(nil)

      expect(blob.language_from_gitattributes).to eq(nil)
    end

    it 'returns nil if repository does not exist' do
      allow(blob.repository).to receive(:exists?).and_return(false)

      expect(blob.language_from_gitattributes).to eq(nil)
    end
  end
end