Skip to content
This repository was archived by the owner on Dec 16, 2021. It is now read-only.

Commit

Permalink
Refactor tests to run with jruby
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Beauvais committed May 21, 2015
1 parent 6b65e17 commit 2f90719
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
6 changes: 5 additions & 1 deletion test/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ def remote_setup(f = 'base.html', opts = {})
end

def adapters
RUBY_PLATFORM == 'java' ? [:nokogiri] : [:nokogiri, :hpricot]
jruby? ? [:nokogiri] : [:nokogiri, :hpricot]
end

def jruby?
RUBY_PLATFORM == 'java'
end

end
2 changes: 1 addition & 1 deletion test/test_links.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def test_empty_query_string

def test_appending_link_query_string
qs = 'utm_source=1234&tracking=good&doublescape'
adapter = RUBY_PLATFORM == 'java' ? :nokogiri : :hpricot
adapter = jruby? ? :nokogiri : :hpricot
opts = {:base_url => 'http://example.com/', :link_query_string => qs, :with_html_string => true, :adapter => adapter}

appendable = [
Expand Down
16 changes: 10 additions & 6 deletions test/test_premailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,11 @@ def test_carriage_returns_as_entities
</body></html>
html

regex = jruby? ? /\n\n/ : /\n\r/

adapters.each do |adapter|
pm = Premailer.new(html, :with_html_string => true, :adapter => adapter)
assert_match /\r/, pm.to_inline_css
assert_match regex, pm.to_inline_css
end
end

Expand All @@ -244,7 +246,7 @@ def test_advanced_selectors
assert_match /italic/, @doc.at('p[attr~=quote]')['style']
assert_match /italic/, @doc.at('ul li:first-of-type')['style']

if RUBY_PLATFORM != 'java'
if !jruby?
remote_setup('base.html', :adapter => :hpricot)
assert_match /italic/, @doc.at('p[@attr~="quote"]')['style']
assert_match /italic/, @doc.at('ul li:first-of-type')['style']
Expand Down Expand Up @@ -306,9 +308,12 @@ def test_output_encoding

def test_meta_encoding_downcase
meta_encoding = '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">'
expected_html = Regexp.new(Regexp.escape('<meta http-equiv="Content-Type" content="text/html; charset=utf-8">'), Regexp::IGNORECASE)
http_equiv = Regexp.new(Regexp.escape('http-equiv="Content-Type"'), Regexp::IGNORECASE)
content = Regexp.new(Regexp.escape('content="text/html; charset=utf-8"'), Regexp::IGNORECASE)
pm = Premailer.new(meta_encoding, :with_html_string => true, :adapter => :nokogiri, :input_encoding => "utf-8")
assert_match expected_html, pm.to_inline_css
doc = pm.to_inline_css
assert_match http_equiv, doc
assert_match content, doc
end

def test_meta_encoding_upcase
Expand All @@ -323,9 +328,8 @@ def test_meta_encoding_upcase

def test_htmlentities
html_entities = "&#8217;"
expected_html = "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" \"http://www.w3.org/TR/REC-html40/loose.dtd\">\n<html><body><p>'</p></body></html>\n"
pm = Premailer.new(html_entities, :with_html_string => true, :adapter => :nokogiri, :replace_html_entities => true)
assert_equal expected_html, pm.to_inline_css
assert_equal html_entities, pm.processed_doc.css('body').text
end

# If a line other than the first line in the html string begins with a URI
Expand Down

0 comments on commit 2f90719

Please sign in to comment.