# encoding: UTF-8 require 'spec_helper' describe Roadie::Inliner do def use_css(css); @css = css; end def rendering(html, options = {}) url_options = options.fetch(:url_options, {:host => 'example.com'}) Nokogiri::HTML.parse Roadie::Inliner.new(@css, html, url_options).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') end it "should keep the order of the styles that was inlined" do use_css 'h1 { padding: 2px; margin: 5px; }' rendering('').should have_styling([['padding', '2px'], ['margin', '5px']]) 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') end it "should use the ones attributes with the highest specificality when conflicts arises" do use_css "p { color: red; } .safe { color: green; }" rendering('').should have_styling('color' => 'green') end it "should sort styles by specificity order" do use_css 'p { margin: 2px; } #big { margin: 10px; } .down { margin-bottom: 5px; }' rendering('').should have_styling([ ['margin', '2px'], ['margin-bottom', '5px'] ]) rendering('').should have_styling([ ['margin-bottom', '5px'], ['margin', '10px'] ]) 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') 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']]) end it "should not touch already present inline styles" do use_css "p { color: red }" rendering('').should have_styling([['color', 'red'], ['color', 'green']]) end it "should ignore selectors with :psuedo-classes" do use_css 'p:hover { color: red }' rendering('').should_not have_styling('color' => 'red') end describe "inlineHello World