require 'spec_helper'

describe HamlLint::Parser do
  context 'when skip_frontmatter is true' do
    let(:parser) { HamlLint::Parser.new(haml, 'skip_frontmatter' => true) }

    let(:haml) { <<-HAML }
---
:key: value
---
%tag
  Some non-inline text
- 'some code'
    HAML

    it 'excludes the frontmatter' do
      expect(parser.contents).to eq(<<-CONTENT)
%tag
  Some non-inline text
- 'some code'
      CONTENT
    end

    context 'when haml has --- as content' do
      let(:haml) { <<-HAML }
---
:key: value
---
%tag
  Some non-inline text
- 'some code'
  ---
    HAML

      it 'is not greedy' do
        expect(parser.contents).to eq(<<-CONTENT)
%tag
  Some non-inline text
- 'some code'
  ---
      CONTENT
      end
    end
  end

  context 'when skip_frontmatter is false' do
    let(:parser) { HamlLint::Parser.new(haml, 'skip_frontmatter' => false) }
    let(:haml) { <<-HAML }
---
:key: value
---
%tag
  Some non-inline text
- 'some code'
    HAML

    it 'raises HAML error' do
      expect { parser }.to raise_error('Invalid filter name ":key: value".')
    end
  end
end

require 'spec_helper'

describe HamlLint::Parser do
  context 'when skip_frontmatter is true' do
    let(:parser) { HamlLint::Parser.new(haml, 'skip_frontmatter' => true) }

    let(:haml) { normalize_indent(<<-HAML) }
      ---
      :key: value
      ---
      %tag
        Some non-inline text
      - 'some code'
    HAML

    it 'excludes the frontmatter' do
      expect(parser.contents).to eq(normalize_indent(<<-CONTENT))
        %tag
          Some non-inline text
        - 'some code'
      CONTENT
    end

    context 'when haml has --- as content' do
      let(:haml) { normalize_indent(<<-HAML) }
        ---
        :key: value
        ---
        %tag
          Some non-inline text
        - 'some code'
          ---
      HAML

      it 'is not greedy' do
        expect(parser.contents).to eq(normalize_indent(<<-CONTENT))
          %tag
            Some non-inline text
          - 'some code'
            ---
        CONTENT
      end
    end
  end

  context 'when skip_frontmatter is false' do
    let(:parser) { HamlLint::Parser.new(haml, 'skip_frontmatter' => false) }
    let(:haml) { normalize_indent(<<-HAML) }
      ---
      :key: value
      ---
      %tag
        Some non-inline text
      - 'some code'
    HAML

    it 'raises HAML error' do
      expect { parser }.to raise_error('Invalid filter name ":key: value".')
    end
  end
end

Indent heredocs in Parser spec
Indent heredocs in Parser spec

Heredocs that aren't indented are more difficult to read. Fix that by
indenting them and using the `normalize_indent` helper to avoid a parse
error.

Change-Id: Ia8cde89109290a548f421ad1db642e9c7926c7a4
Reviewed-on: http://gerrit.causes.com/42552
Tested-by: jenkins <d95b56ce41a2e1ac4cecdd398defd7414407cc08@causes.com>
Reviewed-by: Shane da Silva <67fb7bfe39f841b16a1f86d3928acc568d12c716@brigade.com>
