2013-06-03 16:12:24 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
require 'email'
|
|
|
|
|
2013-06-10 15:33:37 -04:00
|
|
|
describe Email::Styles do
|
2013-06-03 16:12:24 -04:00
|
|
|
|
|
|
|
def style_exists(html, css_rule)
|
2013-06-10 15:33:37 -04:00
|
|
|
fragment = Nokogiri::HTML.fragment(Email::Styles.new(html).format)
|
2013-06-03 16:12:24 -04:00
|
|
|
element = fragment.at(css_rule)
|
|
|
|
expect(element["style"]).not_to be_blank
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns blank from an empty string" do
|
2013-06-10 15:33:37 -04:00
|
|
|
Email::Styles.new("").format.should be_blank
|
2013-06-03 16:12:24 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "attaches a style to h3 tags" do
|
|
|
|
style_exists("<h3>hello</h3>", "h3")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "attaches a style to hr tags" do
|
|
|
|
style_exists("hello<hr>", "hr")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "attaches a style to a tags" do
|
|
|
|
style_exists("<a href='#'>wat</a>", "a")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "attaches a style to ul tags" do
|
|
|
|
style_exists("<ul><li>hello</li></ul>", "ul")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "attaches a style to li tags" do
|
|
|
|
style_exists("<ul><li>hello</li></ul>", "li")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "removes pre tags but keeps their contents" do
|
2013-06-10 15:33:37 -04:00
|
|
|
expect(Email::Styles.new("<pre>hello</pre>").format).to eq("hello")
|
2013-06-03 16:12:24 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|