spec/lib/percy/capybara/loaders/base_loader_spec.rb in percy-capybara-2.6.0 vs spec/lib/percy/capybara/loaders/base_loader_spec.rb in percy-capybara-3.0.0

- old
+ new

@@ -4,19 +4,10 @@ def self.call(_env) [200, {}, File.read(IFRAME_PATH)] end end -# Mock dependency on Poltergeist so we can test an error class. -module Capybara - module Poltergeist - class Error < StandardError; end - class ClientError < Error; end - class FrameNotFound < ClientError; end - end -end - RSpec.describe Percy::Capybara::Loaders::BaseLoader do let(:loader) { described_class.new } describe '#root_html_resource', type: :feature, js: true do it 'includes the root DOM HTML' do @@ -31,26 +22,44 @@ expect(resource.content).to include('Hello World!') expect(resource.sha).to eq(Digest::SHA256.hexdigest(resource.content)) end end describe '#iframes_resources', type: :feature, js: true do - it 'includes the iframe DOM HTML' do + it 'excludes the iframe by default' do visit '/test-iframe.html' loader = described_class.new(page: page) resources = loader.iframes_resources + expect(resources).to eq([]) + end + it 'includes the iframe with DOM HTML when include_iframes true' do + visit '/test-iframe.html' + + loader = described_class.new(page: page, include_iframes: true) + resources = loader.iframes_resources + expect(resources.size).to eq(1) # doesn't include iframe to remote host last_resource = resources.last - expect(last_resource.resource_url).to eq('iframe.html') + expect(last_resource.resource_url).to eq('/iframe.html') expect(last_resource.mimetype).to eq('text/html') expect(last_resource.content).to include('Inside iframe') end - it 'skips poltergeist frame not found errors' do + it 'skips poltergeist frame not found errors when include_iframes true' do visit '/test-iframe.html' - expect(page).to receive(:within_frame).twice.and_raise(Capybara::Poltergeist::FrameNotFound) - loader = described_class.new(page: page) + expect(page).to receive(:within_frame).twice + .and_raise(Capybara::Poltergeist::FrameNotFound, 'Hi') + loader = described_class.new(page: page, include_iframes: true) + resources = loader.iframes_resources + expect(resources.size).to eq(0) + end + it 'skips poltergeist timeout errors when include_iframes true' do + visit '/test-iframe.html' + + expect(page).to receive(:within_frame).twice + .and_raise(Capybara::Poltergeist::TimeoutError, 'Hi') + loader = described_class.new(page: page, include_iframes: true) resources = loader.iframes_resources expect(resources.size).to eq(0) end end describe '#build_resources' do