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 Haml::Error
    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 a HAML error' do
      expect { parser }.to raise_error(/invalid filter/i)
    end
  end
end

Fix broken parser spec on Ruby 1.9.3
Fix broken parser spec on Ruby 1.9.3

The behavior of `raise_error` with just the class name is strange on
Ruby 1.9.3, in that it doesn't recognize that `Haml:Error` is indeed the
same class as the actual exception.

This appears to be a bug not worth pursuing at this time, so change to
using a regex.

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