# frozen_string_literal: true require 'spec_helper' describe MyPDFKit::HTMLPreprocessor do describe "#process" do let(:preprocessor) { MyPDFKit::HTMLPreprocessor } let(:root_url) { 'http://example.com/' } # This mirrors Middleware#root_url's response let(:protocol) { 'http' } it "correctly parses host-relative url with single quotes" do original_body = %{test} body = preprocessor.process original_body, root_url, protocol expect(body).to eq("test") end it "correctly parses host-relative url with double quotes" do original_body = %{} body = preprocessor.process original_body, root_url, protocol expect(body).to eq("") end it "correctly parses protocol-relative url with single quotes" do original_body = %{} body = preprocessor.process original_body, root_url, protocol expect(body).to eq("") end it "correctly parses protocol-relative url with double quotes" do original_body = %{} body = preprocessor.process original_body, root_url, protocol expect(body).to eq("") end it "correctly parses multiple tags where first one is root url" do original_body = %{} body = preprocessor.process original_body, root_url, protocol expect(body).to eq "" end it "returns the body even if there are no valid substitutions found" do original_body = "NO MATCH" body = preprocessor.process original_body, root_url, protocol expect(body).to eq("NO MATCH") end context 'when root_url is nil' do it "returns the body safely, without interpolating" do original_body = %{} body = preprocessor.process original_body, nil, protocol expect(body).to eq(%{}) end end context 'when protocol is nil' do it "returns the body safely, without interpolating" do original_body = %{} body = preprocessor.process original_body, root_url, nil expect(body).to eq(%{}) end end context 'when root_url and protocol are both nil' do it "returns the body safely, without interpolating" do original_body = %{} body = preprocessor.process original_body, nil, nil expect(body).to eq original_body end end end end