Skip to content

Commit

Permalink
Fix failing CI
Browse files Browse the repository at this point in the history
  • Loading branch information
andyw8 committed May 9, 2021
1 parent 5eb952a commit 67689d7
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 33 deletions.
1 change: 0 additions & 1 deletion ruby-readability.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ Gem::Specification.new do |s|

s.add_development_dependency "rspec", ">= 2.8"
s.add_development_dependency "rspec-expectations", ">= 2.8"
s.add_development_dependency "rr", ">= 1.0"
s.add_dependency 'nokogiri', '>= 1.6.0'
s.add_dependency 'guess_html_encoding', '>= 0.0.4'
end
58 changes: 29 additions & 29 deletions spec/readability_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
</body>
</html>
HTML

@simple_html_with_img_no_text = <<-HTML
<html>
<head>
Expand All @@ -32,16 +32,16 @@
</body>
</html>
HTML

@simple_html_with_img_in_noscript = <<-HTML
<html>
<head>
<title>title!</title>
</head>
<body class='main'>
<div class="article-img">
<img src="http://img.thesun.co.uk/multimedia/archive/00703/sign_up_emails_682__703711a.gif" width="660"
height="317" alt="test" class="lazy"
<img src="http://img.thesun.co.uk/multimedia/archive/00703/sign_up_emails_682__703711a.gif" width="660"
height="317" alt="test" class="lazy"
data-original="http://img.thesun.co.uk/multimedia/archive/01416/dim_1416768a.jpg">
<noscript><img src="http://img.thesun.co.uk/multimedia/archive/01416/dim_1416768a.jpg"></noscript>
</div>
Expand All @@ -61,17 +61,17 @@

FakeWeb.register_uri(:get, "http://img.thesun.co.uk/multimedia/archive/01416/dim_1416768a.jpg",
:body => File.read(File.dirname(__FILE__) + "/fixtures/images/dim_1416768a.jpg"))

FakeWeb.register_uri(:get, "http://img.thesun.co.uk/multimedia/archive/00703/sign_up_emails_682__703711a.gif",
:body => File.read(File.dirname(__FILE__) + "/fixtures/images/sign_up_emails_682__703711a.gif"))
FakeWeb.register_uri(:get, "http://img.thesun.co.uk/multimedia/archive/00703/sign_up_emails_682__703712a.gif",

FakeWeb.register_uri(:get, "http://img.thesun.co.uk/multimedia/archive/00703/sign_up_emails_682__703712a.gif",
:body => File.read(File.dirname(__FILE__) + "/fixtures/images/sign_up_emails_682__703712a.gif"))

# Register images for codinghorror
FakeWeb.register_uri(:get, 'http://blog.codinghorror.com/content/images/2014/Sep/JohnPinhole.jpg',
FakeWeb.register_uri(:get, 'http://blog.codinghorror.com/content/images/2014/Sep/JohnPinhole.jpg',
:body => File.read(File.dirname(__FILE__) + "/fixtures/images/JohnPinhole.jpg"))
FakeWeb.register_uri(:get, 'http://blog.codinghorror.com/content/images/2014/Sep/Confusion_of_Tongues.png',
FakeWeb.register_uri(:get, 'http://blog.codinghorror.com/content/images/2014/Sep/Confusion_of_Tongues.png',
:body => File.read(File.dirname(__FILE__) + "/fixtures/images/Confusion_of_Tongues.png"))
end

Expand Down Expand Up @@ -117,7 +117,7 @@
</body>
</html>
HTML
do_not_allow(@doc).load_image(anything)
expect(@doc).not_to receive(:get_image_size)
@doc.images.should == []
end

Expand Down Expand Up @@ -169,17 +169,17 @@
@doc.images.should == ["http://news.bbcimg.co.uk/media/images/57060000/gif/_57060487_sub_escapes304x416.gif"]
@doc.best_candidate_has_image.should == true
end

it "should not miss an image if it exists by itself in a div without text" do
@doc = Readability::Document.new(@simple_html_with_img_no_text,:tags => %w[div p img a], :attributes => %w[src href], :remove_empty_nodes => false, :do_not_guess_encoding => true)
@doc.images.should == ["http://img.thesun.co.uk/multimedia/archive/01416/dim_1416768a.jpg"]
end

it "should not double count an image between script and noscript" do
@doc = Readability::Document.new(@simple_html_with_img_in_noscript,:tags => %w[div p img a], :attributes => %w[src href], :remove_empty_nodes => false, :do_not_guess_encoding => true)
@doc.images.should == ["http://img.thesun.co.uk/multimedia/archive/00703/sign_up_emails_682__703711a.gif", "http://img.thesun.co.uk/multimedia/archive/01416/dim_1416768a.jpg"]
end

end
end
end
Expand Down Expand Up @@ -211,7 +211,7 @@
HTML
doc.author.should eql("Austin Fonacier")
end

it "should pick up readability's recommended author format" do
doc = Readability::Document.new(<<-HTML)
<html>
Expand All @@ -226,7 +226,7 @@
HTML
doc.author.should eql("Austin Fonacier")
end

it "should pick up vcard fn" do
doc = Readability::Document.new(<<-HTML)
<html>
Expand All @@ -242,7 +242,7 @@
HTML
doc.author.should eql("Austin Fonacier")
end

it "should pick up <a rel='author'>" do
doc = Readability::Document.new(<<-HTML)
<html>
Expand All @@ -254,7 +254,7 @@
HTML
doc.author.should eql("Danny Banks (rel)")
end

it "should pick up <div id='author'>" do
doc = Readability::Document.new(<<-HTML)
<html>
Expand Down Expand Up @@ -475,13 +475,13 @@
end

it "should allow encoding guessing to be skipped" do
do_not_allow(GuessHtmlEncoding).encode
expect(GuessHtmlEncoding).to_not receive(:encode)
doc = Readability::Document.new(@simple_html_fixture, :do_not_guess_encoding => true)
doc.content
end

it "should allow encoding guessing to be overridden" do
do_not_allow(GuessHtmlEncoding).encode
expect(GuessHtmlEncoding).to_not receive(:encode)
doc = Readability::Document.new(@simple_html_fixture, :encoding => "UTF-8")
doc.content
end
Expand All @@ -505,42 +505,42 @@
Readability::Document.new('<html><head><meta http-equiv="refresh" content="0;URL=http://example.com"></head></html>').content.should == '<div><div></div></div>'
end
end

describe "No side-effects" do
before do
@bbc = File.read(File.dirname(__FILE__) + "/fixtures/bbc.html")
@nytimes = File.read(File.dirname(__FILE__) + "/fixtures/nytimes.html")
@thesum = File.read(File.dirname(__FILE__) + "/fixtures/thesun.html")
end

it "should not have any side-effects when calling content() and then images()" do
@doc=Readability::Document.new(@nytimes, :tags => %w[div p img a], :attributes => %w[src href], :remove_empty_nodes => false,
@doc=Readability::Document.new(@nytimes, :tags => %w[div p img a], :attributes => %w[src href], :remove_empty_nodes => false,
:do_not_guess_encoding => true)
@doc.images.should == ["http://graphics8.nytimes.com/images/2011/12/02/opinion/02fixes-freelancersunion/02fixes-freelancersunion-blog427.jpg"]
@doc.content
@doc.images.should == ["http://graphics8.nytimes.com/images/2011/12/02/opinion/02fixes-freelancersunion/02fixes-freelancersunion-blog427.jpg"]
end

it "should not have any side-effects when calling content() multiple times" do
@doc=Readability::Document.new(@nytimes, :tags => %w[div p img a], :attributes => %w[src href], :remove_empty_nodes => false,
@doc=Readability::Document.new(@nytimes, :tags => %w[div p img a], :attributes => %w[src href], :remove_empty_nodes => false,
:do_not_guess_encoding => true)
@doc.content.should == @doc.content
end

it "should not have any side-effects when calling content and images multiple times" do
@doc=Readability::Document.new(@nytimes, :tags => %w[div p img a], :attributes => %w[src href], :remove_empty_nodes => false,
@doc=Readability::Document.new(@nytimes, :tags => %w[div p img a], :attributes => %w[src href], :remove_empty_nodes => false,
:do_not_guess_encoding => true)
@doc.images.should == ["http://graphics8.nytimes.com/images/2011/12/02/opinion/02fixes-freelancersunion/02fixes-freelancersunion-blog427.jpg"]
@doc.content.should == @doc.content
@doc.images.should == ["http://graphics8.nytimes.com/images/2011/12/02/opinion/02fixes-freelancersunion/02fixes-freelancersunion-blog427.jpg"]
end

end

describe "Code blocks" do
before do
@code = File.read(File.dirname(__FILE__) + "/fixtures/code.html")
@content = Readability::Document.new(@code,
@content = Readability::Document.new(@code,
:tags => %w[div p img a ul ol li h1 h2 h3 h4 h5 h6 blockquote strong em b code pre],
:attributes => %w[src href],
:remove_empty_nodes => false).content
Expand Down
3 changes: 0 additions & 3 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
require 'rubygems'
require 'readability'
require 'rr'
require 'fakeweb'

FakeWeb.allow_net_connect = false

RSpec.configure do |config|
config.mock_with :rr

config.expect_with :rspec do |c|
c.syntax = [:should, :expect]
end
Expand Down

0 comments on commit 67689d7

Please sign in to comment.