From 2f90719e68884498f69dee1e944908459b2f8fbc Mon Sep 17 00:00:00 2001 From: Tom Beauvais Date: Wed, 20 May 2015 20:43:53 -0400 Subject: [PATCH] Refactor tests to run with jruby --- test/helper.rb | 6 +++++- test/test_links.rb | 2 +- test/test_premailer.rb | 16 ++++++++++------ 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/test/helper.rb b/test/helper.rb index 30e4f5f2..3f4775b8 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -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 diff --git a/test/test_links.rb b/test/test_links.rb index 97d5b1b4..2ef468f1 100644 --- a/test/test_links.rb +++ b/test/test_links.rb @@ -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 = [ diff --git a/test/test_premailer.rb b/test/test_premailer.rb index ef60226d..28f74025 100644 --- a/test/test_premailer.rb +++ b/test/test_premailer.rb @@ -231,9 +231,11 @@ def test_carriage_returns_as_entities 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 @@ -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'] @@ -306,9 +308,12 @@ def test_output_encoding def test_meta_encoding_downcase meta_encoding = '' - expected_html = Regexp.new(Regexp.escape(''), 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 @@ -323,9 +328,8 @@ def test_meta_encoding_upcase def test_htmlentities html_entities = "’" - expected_html = "\n

'

\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