# frozen_string_literal: true require "spec_helper" require "shared_examples/url_rewriter" module Roadie describe UrlRewriter do let(:generator) { double("URL generator") } subject(:rewriter) { UrlRewriter.new(generator) } it_behaves_like "url rewriter" describe "transforming DOM trees" do def dom_document(html) Nokogiri::HTML.parse html end it "rewrites all a[href]" do expect(generator).to receive(:generate_url).with("some/path").and_return "http://foo.com/" dom = dom_document <<-HTML
Some path HTML expect { rewriter.transform_dom dom }.to change { dom.at_css("a")["href"] }.to "http://foo.com/" end it "rewrites relative img[src]" do expect(generator).to receive(:generate_url).with("some/path.jpg").and_return "http://foo.com/image.jpg" dom = dom_document <<-HTML HTML expect { rewriter.transform_dom dom }.to change { dom.at_css("img")["src"] }.to "http://foo.com/image.jpg" end it "rewrites url() directives inside style attributes" do expect(generator).to receive(:generate_url).with("some/path.jpg").and_return "http://foo.com/image.jpg" dom = dom_document <<-HTML