# frozen_string_literal: true

describe 'GH-804', :site, :stdio do
  before do
    File.write('content/item.md', 'Stuff!')
    File.write('Rules', <<EOS)
  compile '/**/*' do
    filter :erb if item[:dynamic]
    write item.identifier.without_ext + '.html'
  end
EOS

    File.write('Checks', <<~EOS)
      check :donkey do
        self.add_issue('Not enough donkeys')
        self.add_issue('Too many cats', subject: '/catlady.md')
      end
    EOS
  end

  it 'does not crash' do
    expect { Nanoc::CLI.run(['check', 'donkey']) }.to(
      raise_error(Nanoc::Core::TrivialError, 'One or more checks failed').and(
        output(
          %r{
            Issues\ found!\n
            \ \ \(global\):\n
            \ \ \ \ \[\ (\e\[31m)?ERROR\ \]\ donkey\ -\ Not\ enough\ donkeys\n
            \ \ /catlady.md:\n\ \ \ \ \[\ (\e\[31m)?ERROR(\e\[0m)?\ \]\ donkey\ -\ Too\ many\ cats\n
          }x,
        ).to_stdout,
      ),
    )
  end
end
