spec/lib/percy/capybara/loaders/filesystem_loader_spec.rb in percy-capybara-2.4.5 vs spec/lib/percy/capybara/loaders/filesystem_loader_spec.rb in percy-capybara-2.5.0
- old
+ new
@@ -1,26 +1,29 @@
RSpec.describe Percy::Capybara::Loaders::FilesystemLoader do
let(:fake_page) { OpenStruct.new(current_url: 'http://localhost/foo') }
let(:assets_dir) { File.expand_path('../../client/testdata', __FILE__) }
- let(:base_url) { '/url-prefix' }
+ let(:base_url) { '/url-prefix/' }
let(:loader) { described_class.new(base_url: base_url, assets_dir: assets_dir, page: fake_page) }
describe 'initialize' do
context 'assets_dir not specified' do
let(:assets_dir) { nil }
+
it 'raises an error' do
expect { loader }.to raise_error(ArgumentError)
end
end
context 'assets_dir is not an absolute path' do
let(:assets_dir) { '../../client/testdata' }
+
it 'raises an error' do
expect { loader }.to raise_error(ArgumentError)
end
end
context 'assets_dir doesn\'t exist' do
let(:assets_dir) { File.expand_path('../../client/testdata-doesnt-exist', __FILE__) }
+
it 'raises an error' do
expect { loader }.to raise_error(ArgumentError)
end
end
end
@@ -108,12 +111,30 @@
'/url-prefix/test-images.html',
'/url-prefix/test-localtest-me-images.html',
]
expect(actual_urls).to match_array(expected_urls)
end
+ it 'works with different base_url configs' do
+ loader = described_class.new(base_url: '/url-prefix/', assets_dir: assets_dir)
+ expected_urls = loader.build_resources.collect(&:resource_url)
+ expect(expected_urls).to include('/url-prefix/css/font.css')
+
+ loader = described_class.new(base_url: '/url-prefix', assets_dir: assets_dir)
+ expected_urls = loader.build_resources.collect(&:resource_url)
+ expect(expected_urls).to include('/url-prefix/css/font.css')
+
+ loader = described_class.new(base_url: '/', assets_dir: assets_dir)
+ expected_urls = loader.build_resources.collect(&:resource_url)
+ expect(expected_urls).to include('/css/font.css')
+
+ loader = described_class.new(base_url: '', assets_dir: assets_dir)
+ expected_urls = loader.build_resources.collect(&:resource_url)
+ expect(expected_urls).to include('/css/font.css')
+ end
end
context 'assets_dir with only skippable resources' do
let(:assets_dir) { File.expand_path('../../client/testdata/assets/images', __FILE__) }
+
it 'returns an empty list' do
expect(loader.build_resources).to eq([])
end
end
end