summaryrefslogtreecommitdiff
path: root/spec/lib/banzai/filter/yaml_front_matter_filter_spec.rb
blob: fe70eada7eb44ac95fa38ee63b5fa986e989bc9a (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
require 'rails_helper'

describe Banzai::Filter::YamlFrontMatterFilter, lib: true do
  include FilterSpecHelper

  it 'allows for `encoding:` before the frontmatter' do
    content = <<-MD.strip_heredoc
      # encoding: UTF-8
      ---
      foo: foo
      ---

      # Header

      Content
    MD

    output = filter(content)

    expect(output).not_to match 'encoding'
  end

  it 'converts YAML frontmatter to a fenced code block' do
    content = <<-MD.strip_heredoc
      ---
      bar: :bar_symbol
      ---

      # Header

      Content
    MD

    output = filter(content)

    aggregate_failures do
      expect(output).not_to include '---'
      expect(output).to include "```yaml\nbar: :bar_symbol\n```"
    end
  end

  context 'on content without frontmatter' do
    it 'returns the content unmodified' do
      content = <<-MD.strip_heredoc
        # This is some Markdown

        It has no YAML frontmatter to parse.
      MD

      expect(filter(content)).to eq content
    end
  end
end