Path: blob/master/spec/shared_examples/finders/wp_items/urls_in_page.rb
486 views
# frozen_string_literal: true12shared_examples 'App::Finders::WpItems::UrlsInPage' do3before do4allow(finder.target).to receive(:content_dir).and_return('wp-content')56stub_request(:get, page_url).to_return(body: defined?(body) ? body : File.read(fixtures.join(fixture)))7end89describe '#items_from_links' do10context 'when none found' do11let(:fixture) { 'none.html' }1213it 'returns an empty array' do14expect(finder.items_from_links(type)).to eql([])15end16end1718context 'when found' do19let(:fixture) { 'found.html' }2021it 'returns the expected array' do22expect(finder.items_from_links(type, uniq: uniq_links)).to eql expected_from_links23end24end2526context 'when a lof of unrelated links' do27let(:body) do28Array.new(250) { |i| "<a href='#{url}#{i}.html'>Link</a><img src='#{url}img-#{i}.gif'/>" }.join("\n")29end3031it 'should not take a while to process the page' do32time_start = Time.now33expect(finder.items_from_links(type)).to eql []34time_end = Time.now3536expect(time_end - time_start).to be < 137end38end39end4041describe '#items_from_codes' do42context 'when none found' do43let(:fixture) { 'none.html' }4445it 'returns an empty array' do46expect(finder.items_from_codes(type)).to eql([])47end48end4950context 'when found' do51let(:fixture) { 'found.html' }5253it 'returns the expected array' do54expect(finder.items_from_codes(type, uniq: uniq_codes)).to eql expected_from_codes55end56end57end58end596061