Skip to content

Commit

Permalink
Fix JRuby specs (closes #16).
Browse files Browse the repository at this point in the history
  • Loading branch information
postmodern committed Jan 18, 2024
1 parent dfa5f44 commit 59a7016
Show file tree
Hide file tree
Showing 7 changed files with 169 additions and 45 deletions.
10 changes: 9 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,13 @@ inherit_gem:
rubocop-ronin: rubocop.yml

#
# ronin-FIXME specific exceptions
# ronin-support-web specific exceptions
#

# Need explicit whitespace for the JRuby's specific HTML heredocs.
Layout/TrailingWhitespace:
Exclude:
- spec/agent/mixin_spec.rb
- spec/agent_spec.rb
- spec/html/mixin_spec.rb
- spec/html_spec.rb
70 changes: 56 additions & 14 deletions spec/agent/mixin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,27 @@
)

doc = subject.web_get_html(uri)

expect(doc).to be_kind_of(Nokogiri::HTML::Document)
expect(doc.to_s).to eq(
<<~HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
#{html.chomp}
HTML
)

# XXX: nokogiri's java extensions behave differently from libxml2
if RUBY_ENGINE == 'jruby'
expect(doc.to_s).to eq(
<<~HTML.chomp
<html><head></head><body>
<p>hello world</p>
</body></html>
HTML
)
else
expect(doc.to_s).to eq(
<<~HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
#{html.chomp}
HTML
)
end
end
end

Expand Down Expand Up @@ -232,8 +246,15 @@
)

doc = subject.web_get_xml(uri)

expect(doc).to be_kind_of(Nokogiri::XML::Document)
expect(doc.to_s).to eq(xml)

# XXX: nokogiri's java extensions behave differently from libxml2
if RUBY_ENGINE == 'jruby'
expect(doc.to_s).to eq(xml.chomp)
else
expect(doc.to_s).to eq(xml)
end
end
end

Expand Down Expand Up @@ -454,13 +475,27 @@
)

doc = subject.web_post_html(uri)

expect(doc).to be_kind_of(Nokogiri::HTML::Document)
expect(doc.to_s).to eq(
<<~HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
#{html.chomp}
HTML
)

# XXX: nokogiri's java extensions behave differently from libxml2
if RUBY_ENGINE == 'jruby'
expect(doc.to_s).to eq(
<<~HTML.chomp
<html><head></head><body>
<p>hello world</p>
</body></html>
HTML
)
else
expect(doc.to_s).to eq(
<<~HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
#{html.chomp}
HTML
)
end
end
end

Expand Down Expand Up @@ -507,8 +542,15 @@
)

doc = subject.web_post_xml(uri)

expect(doc).to be_kind_of(Nokogiri::XML::Document)
expect(doc.to_s).to eq(xml)

# XXX: nokogiri's java extensions behave differently from libxml2
if RUBY_ENGINE == 'jruby'
expect(doc.to_s).to eq(xml.chomp)
else
expect(doc.to_s).to eq(xml)
end
end
end

Expand Down
70 changes: 56 additions & 14 deletions spec/agent_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -715,13 +715,27 @@
)

doc = subject.get_html(uri)

expect(doc).to be_kind_of(Nokogiri::HTML::Document)
expect(doc.to_s).to eq(
<<~HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
#{html.chomp}
HTML
)

# XXX: nokogiri's java extensions behave differently from libxml2
if RUBY_ENGINE == 'jruby'
expect(doc.to_s).to eq(
<<~HTML.chomp
<html><head></head><body>
<p>hello world</p>
</body></html>
HTML
)
else
expect(doc.to_s).to eq(
<<~HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
#{html.chomp}
HTML
)
end
end
end

Expand Down Expand Up @@ -768,8 +782,15 @@
)

doc = subject.get_xml(uri)

expect(doc).to be_kind_of(Nokogiri::XML::Document)
expect(doc.to_s).to eq(xml)

# XXX: nokogiri's java extensions behave differently from libxml2
if RUBY_ENGINE == 'jruby'
expect(doc.to_s).to eq(xml.chomp)
else
expect(doc.to_s).to eq(xml)
end
end
end

Expand Down Expand Up @@ -1071,13 +1092,27 @@
)

doc = subject.post_html(uri)

expect(doc).to be_kind_of(Nokogiri::HTML::Document)
expect(doc.to_s).to eq(
<<~HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
#{html.chomp}
HTML
)

# XXX: nokogiri's java extensions behave differently from libxml2
if RUBY_ENGINE == 'jruby'
expect(doc.to_s).to eq(
<<~HTML.chomp
<html><head></head><body>
<p>hello world</p>
</body></html>
HTML
)
else
expect(doc.to_s).to eq(
<<~HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
#{html.chomp}
HTML
)
end
end
end

Expand Down Expand Up @@ -1124,8 +1159,15 @@
)

doc = subject.post_xml(uri)

expect(doc).to be_kind_of(Nokogiri::XML::Document)
expect(doc.to_s).to eq(xml)

# XXX: nokogiri's java extensions behave differently from libxml2
if RUBY_ENGINE == 'jruby'
expect(doc.to_s).to eq(xml.chomp)
else
expect(doc.to_s).to eq(xml)
end
end
end

Expand Down
16 changes: 10 additions & 6 deletions spec/html/mixin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@
# XXX: nokogiri's java extensions behave differently from libxml2
if RUBY_ENGINE == 'jruby'
expect(doc.to_s).to eq(
<<~HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
#{html}
<<~HTML.chomp
<html><head></head><body>
<p id="foo">Foo</p>
</body></html>
HTML
)
else
Expand Down Expand Up @@ -54,9 +56,11 @@
# XXX: nokogiri's java extensions behave differently from libxml2
if RUBY_ENGINE == 'jruby'
expect(doc.to_s).to eq(
<<~HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
#{html}
<<~HTML.chomp
<html><head></head><body>
<p id="foo">Foo</p>
</body></html>
HTML
)
else
Expand Down
16 changes: 10 additions & 6 deletions spec/html_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
# XXX: nokogiri's java extensions behave differently from libxml2
if RUBY_ENGINE == 'jruby'
expect(doc.to_s).to eq(
<<~HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
#{html}
<<~HTML.chomp
<html><head></head><body>
<p id="foo">Foo</p>
</body></html>
HTML
)
else
Expand Down Expand Up @@ -48,9 +50,11 @@
# XXX: nokogiri's java extensions behave differently from libxml2
if RUBY_ENGINE == 'jruby'
expect(doc.to_s).to eq(
<<~HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
#{html}
<<~HTML.chomp
<html><head></head><body>
<p id="foo">Foo</p>
</body></html>
HTML
)
else
Expand Down
16 changes: 14 additions & 2 deletions spec/xml/mixin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@
doc = subject.xml_parse(xml)

expect(doc).to be_kind_of(Nokogiri::XML::Document)
expect(doc.to_s).to eq(xml)

# XXX: nokogiri's java extensions behave differently from libxml2
if RUBY_ENGINE == 'jruby'
expect(doc.to_s).to eq(xml.chomp)
else
expect(doc.to_s).to eq(xml)
end
end

context "when given a block" do
Expand All @@ -34,7 +40,13 @@
doc = subject.xml_open(xml_file)

expect(doc).to be_kind_of(Nokogiri::XML::Document)
expect(doc.to_s).to eq(xml)

# XXX: nokogiri's java extensions behave differently from libxml2
if RUBY_ENGINE == 'jruby'
expect(doc.to_s).to eq(xml.chomp)
else
expect(doc.to_s).to eq(xml)
end
end

context "when given a block" do
Expand Down
16 changes: 14 additions & 2 deletions spec/xml_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@
doc = subject.parse(xml)

expect(doc).to be_kind_of(Nokogiri::XML::Document)
expect(doc.to_s).to eq(xml)

# XXX: nokogiri's java extensions behave differently from libxml2
if RUBY_ENGINE == 'jruby'
expect(doc.to_s).to eq(xml.chomp)
else
expect(doc.to_s).to eq(xml)
end
end

context "when given a block" do
Expand All @@ -28,7 +34,13 @@
doc = subject.open(xml_file)

expect(doc).to be_kind_of(Nokogiri::XML::Document)
expect(doc.to_s).to eq(xml)

# XXX: nokogiri's java extensions behave differently from libxml2
if RUBY_ENGINE == 'jruby'
expect(doc.to_s).to eq(xml.chomp)
else
expect(doc.to_s).to eq(xml)
end
end

context "when given a block" do
Expand Down

0 comments on commit 59a7016

Please sign in to comment.