require 'spec_helper' describe "Roadie functionality" do def parse_html(html) Nokogiri::HTML.parse(html) end it "adds missing structure" do html = "

Hello world!

".encode("Shift_JIS") document = Roadie::Document.new(html) result = document.transform unless defined?(JRuby) # JRuby has a bug that makes DTD manipulation impossible # See Nokogiri bugs #984 and #985 # https://github.com/sparklemotion/nokogiri/issues/984 # https://github.com/sparklemotion/nokogiri/issues/985 expect(result).to include("") end expect(result).to include("") expect(result).to include("") expect(result).to include("") expect(result).to include(" Hello world!

Hello world!

Check out these awesome prices!

HTML document.add_css <<-CSS em { color: red; } h1 { text-align: center; } CSS result = parse_html document.transform expect(result).to have_styling('text-align' => 'center').at_selector('h1') expect(result).to have_styling('color' => 'red').at_selector('p > em') end it "inlines css from disk" do document = Roadie::Document.new <<-HTML Hello world!

Hello world!

Check out these awesome prices!

HTML result = parse_html document.transform expect(result).to have_styling('font-size' => '200%').at_selector('p > em') end it "crashes when stylesheets cannot be found, unless using NullProvider" do document = Roadie::Document.new <<-HTML HTML expect { document.transform }.to raise_error(Roadie::CssNotFound, /does_not_exist\.css/) document.asset_providers << Roadie::NullProvider.new expect { document.transform }.to_not raise_error end it "makes URLs absolute" do document = Roadie::Document.new <<-HTML About us HTML document.asset_providers = TestProvider.new( "/style.css" => "a { background: url(/assets/link-abcdef1234567890.png); }" ) document.url_options = {host: "myapp.com", scheme: "https", path: "rails/app/"} result = parse_html document.transform expect(result.at_css("a")["href"]).to eq("https://myapp.com/rails/app/about_us") expect(result.at_css("img")["src"]).to eq("https://myapp.com/rails/app/assets/about_us-abcdef1234567890.png") expect(result).to have_styling( "background" => 'url("https://myapp.com/rails/app/assets/bg-abcdef1234567890.png")' ).at_selector("body") expect(result).to have_styling( "background" => 'url(https://myapp.com/rails/app/assets/link-abcdef1234567890.png)' ).at_selector("a") end it "allows custom callbacks during inlining" do document = Roadie::Document.new <<-HTML Hello world HTML document.before_transformation = proc { |dom| dom.at_css("body")["class"] = "roadie" } document.after_transformation = proc { |dom| dom.at_css("span").remove } result = parse_html document.transform expect(result.at_css("body")["class"]).to eq("roadie") expect(result.at_css("span")).to be_nil end end