blob_presenter_spec.rb 1.24 KB
Newer Older
1 2 3 4 5
# frozen_string_literal: true

require 'spec_helper'

describe BlobPresenter, :seed_helper do
6
  let(:repository) { Gitlab::Git::Repository.new('default', TEST_REPO_PATH, '', 'group/project') }
7 8 9 10 11 12 13 14 15 16 17 18 19 20

  let(:git_blob) do
    Gitlab::Git::Blob.find(
      repository,
      'fa1b1e6c004a68b7d8763b86455da9e6b23e36d6',
      'files/ruby/regex.rb'
    )
  end
  let(:blob) { Blob.new(git_blob) }

  describe '#highlight' do
    subject { described_class.new(blob) }

    it 'returns highlighted content' do
21
      expect(Gitlab::Highlight).to receive(:highlight).with('files/ruby/regex.rb', git_blob.data, plain: nil, language: nil)
22 23 24 25

      subject.highlight
    end

26 27
    it 'returns plain content when :plain is true' do
      expect(Gitlab::Highlight).to receive(:highlight).with('files/ruby/regex.rb', git_blob.data, plain: true, language: nil)
28

29
      subject.highlight(plain: true)
30 31 32 33 34 35 36 37
    end

    context 'gitlab-language contains a match' do
      before do
        allow(blob).to receive(:language_from_gitattributes).and_return('ruby')
      end

      it 'passes language to inner call' do
38
        expect(Gitlab::Highlight).to receive(:highlight).with('files/ruby/regex.rb', git_blob.data, plain: nil, language: 'ruby')
39 40 41 42 43 44

        subject.highlight
      end
    end
  end
end