require 'spec_helper' describe Roadie::Inliner do def use_css(css); @css = css; end def rendering(html, options = {}) Nokogiri::HTML.parse Roadie::Inliner.new(@css, html, options.fetch(:url_options, {:host => 'example.com'})).execute end describe "inlining styles" do before(:each) do # Make sure to have some css even when we don't specify any # We have specific tests for when this is nil use_css '' end it "should inline simple attributes" do use_css 'p { color: green }' rendering('
').should have_styling('color' => 'green').at_selector('p') end it "should combine multiple selectors into one" do use_css "p { color: green; } .tip { float: right; }" rendering('').should have_styling('color' => 'green', 'float' => 'right').at_selector('p') end it "should use the ones attributes with the highest specificality when conflicts arises" do use_css "p { color: red; } .safe { color: green; border: 1px solid black; }" rendering('').should have_styling('color' => 'green', 'border' => '1px solid black').at_selector('p') end it "should support multiple selectors for the same rules" do use_css 'p, a { color: green; }' rendering('').tap do |document| document.should have_styling('color' => 'green').at_selector('p') document.should have_styling('color' => 'green').at_selector('a') end end it "should respect !important properties" do use_css "a { text-decoration: underline !important; } a.hard-to-spot { text-decoration: none; }" rendering('').should have_styling('text-decoration' => 'underline').at_selector('a') end it "should combine with already present inline styles" do use_css "p { color: green }" rendering('').should have_styling('color' => 'green', 'font-size' => '1.1em').at_selector('p') end it "should not overwrite already present inline styles" do use_css "p { color: red }" rendering('').should have_styling('color' => 'green').at_selector('p') end it "should ignore selectors with :psuedo-classes" do use_css 'p:hover { color: red }' rendering('').should_not have_styling('color' => 'red').at_selector('p') end describe "inlineHello World