require 'spec_helper'
describe Codeqa::Checkers::HtmlValidator do
it_behaves_like 'a checker'
it 'should check erb files' do
source = source_with('', 'file.html.erb')
expect(described_class.check?(source)).to be_truthy
source = source_with('', 'test.rhtml')
expect(described_class.check?(source)).to be_truthy
source = source_with('', 'test.text.html')
expect(described_class.check?(source)).to be_truthy
source = source_with('', 'zipped.zip')
expect(described_class.check?(source)).to be_falsey
end
it 'should detect html tag errors' do
text = '
'
source = source_with(text)
checker = check_with(described_class, source)
expect(checker).to be_error
expect(checker.errors.details).to eq([
[:source, text],
[1, 'Opening and ending tag mismatch: ul line 1 and div']
])
end
it 'should detect attribute till end of file errors' do
text = "')
checker = check_with(described_class, source)
expect(checker).to be_success
end
it "should no complain about nbsp 'spaces'" do
source = source_with('something fooo
')
checker = check_with(described_class, source)
expect(checker).to be_success
end
context 'script tags' do
it 'should replace script tags with html comment' do
text = ''
source = source_with(text)
checker = described_class.new(source)
expect(checker.stripped_html).to eq('')
end
it 'should replace multiline script tags while keeping the linecount correct' do
text = <<-EOR
EOR
source = source_with(text)
checker = described_class.new(source)
expect(checker.stripped_html).to eq(<<-EOR)
EOR
end
it 'should replace script tags when there are multiple script tags in the text' do
text = <<-EOR
content
EOR
source = source_with(text)
checker = described_class.new(source)
expect(checker.stripped_html).to eq(<<-EOR)
content
EOR
end
end
end