2016-05-30 13:55:11 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-07-10 14:24:02 +00:00
|
|
|
describe Banzai::Filter::ReferenceFilter do
|
2017-08-02 19:55:11 +00:00
|
|
|
let(:project) { build_stubbed(:project) }
|
2016-05-30 13:55:11 +00:00
|
|
|
|
|
|
|
describe '#each_node' do
|
|
|
|
it 'iterates over the nodes in a document' do
|
|
|
|
document = Nokogiri::HTML.fragment('<a href="foo">foo</a>')
|
|
|
|
filter = described_class.new(document, project: project)
|
|
|
|
|
2017-06-21 13:48:12 +00:00
|
|
|
expect { |b| filter.each_node(&b) }
|
|
|
|
.to yield_with_args(an_instance_of(Nokogiri::XML::Element))
|
2016-05-30 13:55:11 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns an Enumerator when no block is given' do
|
|
|
|
document = Nokogiri::HTML.fragment('<a href="foo">foo</a>')
|
|
|
|
filter = described_class.new(document, project: project)
|
|
|
|
|
|
|
|
expect(filter.each_node).to be_an_instance_of(Enumerator)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'skips links with a "gfm" class' do
|
|
|
|
document = Nokogiri::HTML.fragment('<a href="foo" class="gfm">foo</a>')
|
|
|
|
filter = described_class.new(document, project: project)
|
|
|
|
|
|
|
|
expect { |b| filter.each_node(&b) }.not_to yield_control
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'skips text nodes in pre elements' do
|
|
|
|
document = Nokogiri::HTML.fragment('<pre>foo</pre>')
|
|
|
|
filter = described_class.new(document, project: project)
|
|
|
|
|
|
|
|
expect { |b| filter.each_node(&b) }.not_to yield_control
|
|
|
|
end
|
|
|
|
end
|
2016-05-30 13:56:05 +00:00
|
|
|
|
|
|
|
describe '#nodes' do
|
|
|
|
it 'returns an Array of the HTML nodes' do
|
|
|
|
document = Nokogiri::HTML.fragment('<a href="foo">foo</a>')
|
|
|
|
filter = described_class.new(document, project: project)
|
|
|
|
|
|
|
|
expect(filter.nodes).to eq([document.children[0]])
|
|
|
|
end
|
|
|
|
end
|
2016-05-30 13:55:11 +00:00
|
|
|
end
|