From f85c5c27dea81193351a8b3d3a7c76d07f9f7625 Mon Sep 17 00:00:00 2001 From: tbvokh Date: Fri, 5 Feb 2021 10:28:09 +0200 Subject: [PATCH 1/2] Updated dependencies; Fixed error with opening URI --- .travis.yml | 6 ++++-- feed_parser.gemspec | 4 ++-- lib/feed_parser.rb | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 46029af..5cdb3e4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,5 @@ rvm: - - 1.9.3 - - 2.0.0 + - 2.5.0 + - 2.6.0 + - 2.7.0 + - 3.0.0 diff --git a/feed_parser.gemspec b/feed_parser.gemspec index c156ef2..ff1b7e1 100644 --- a/feed_parser.gemspec +++ b/feed_parser.gemspec @@ -12,8 +12,8 @@ Gem::Specification.new do |s| s.add_dependency 'nokogiri' - s.add_development_dependency 'rake', '>= 0.9' - s.add_development_dependency 'rspec', '>= 2.10' + s.add_development_dependency 'rake', '>= 12.3' + s.add_development_dependency 'rspec', '>= 3.10' s.extra_rdoc_files = %w[README.md] diff --git a/lib/feed_parser.rb b/lib/feed_parser.rb index bb619e8..5697166 100644 --- a/lib/feed_parser.rb +++ b/lib/feed_parser.rb @@ -54,7 +54,7 @@ def open_or_follow_redirect(feed_url) @http_options[:redirect] = true if RUBY_VERSION >= '1.9' if ['http', 'https'].include?(uri.scheme) - open(uri.to_s, @http_options) + URI.open(uri.to_s, @http_options) else raise FeedParser::InvalidURI.new("Only URIs with http or https protocol are supported") end From e1dcd97e627fe993da2e90933e8759bd8ed70854 Mon Sep 17 00:00:00 2001 From: tbvokh Date: Mon, 8 Feb 2021 11:53:07 +0200 Subject: [PATCH 2/2] Fixing rspec --- spec/feed_parser_spec.rb | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/spec/feed_parser_spec.rb b/spec/feed_parser_spec.rb index d9651a7..fd99747 100644 --- a/spec/feed_parser_spec.rb +++ b/spec/feed_parser_spec.rb @@ -33,39 +33,39 @@ def http_connection_options describe "#new" do it "should forward given http options to the OpenURI" do - FeedParser.any_instance.should_receive(:open).with("http://blog.example.com/feed/", http_connection_options.merge(:ssl_verify_mode => OpenSSL::SSL::VERIFY_NONE)).and_return(feed_xml) + URI.should_receive(:open).with("http://blog.example.com/feed/", http_connection_options.merge(:ssl_verify_mode => OpenSSL::SSL::VERIFY_NONE)).and_return(feed_xml) fp = FeedParser.new(:url => "http://blog.example.com/feed/", :http => {:ssl_verify_mode => OpenSSL::SSL::VERIFY_NONE}) fp.parse end it "should fetch a feed by url" do - FeedParser.any_instance.should_receive(:open).with("http://blog.example.com/feed/", http_connection_options).and_return(feed_xml) + URI.should_receive(:open).with("http://blog.example.com/feed/", http_connection_options).and_return(feed_xml) fp = FeedParser.new({:url => "http://blog.example.com/feed/"}.merge(http_connection_options)) fp.parse end it "should fetch a feed using basic auth if auth embedded to the url" do - FeedParser.any_instance.should_receive(:open).with("http://blog.example.com/feed/", http_connection_options.merge(:http_basic_authentication => ["user", "pass"])).and_return(feed_xml) + URI.should_receive(:open).with("http://blog.example.com/feed/", http_connection_options.merge(:http_basic_authentication => ["user", "pass"])).and_return(feed_xml) fp = FeedParser.new({:url => "http://user:pass@blog.example.com/feed/"}.merge(http_connection_options)) fp.parse end it "should fetch a feed with only a user name embedded to the url" do - FeedParser.any_instance.should_receive(:open).with("http://blog.example.com/feed/", http_connection_options.merge(:http_basic_authentication => ["user"])).and_return(feed_xml) + URI.should_receive(:open).with("http://blog.example.com/feed/", http_connection_options.merge(:http_basic_authentication => ["user"])).and_return(feed_xml) fp = FeedParser.new({:url => "http://user@blog.example.com/feed/"}.merge(http_connection_options)) fp.parse end it "should follow redirect based on the exception message (even if OpenURI don't want to do it)" do - FeedParser.any_instance.should_receive(:open).with("http://example.com/feed", http_connection_options).and_raise(RuntimeError.new("redirection forbidden: http://example.com/feed -> https://example.com/feed")) - FeedParser.any_instance.should_receive(:open).with("https://example.com/feed", http_connection_options).and_return(feed_xml) + URI.should_receive(:open).with("http://example.com/feed", http_connection_options).and_raise(RuntimeError.new("redirection forbidden: http://example.com/feed -> https://example.com/feed")) + URI.should_receive(:open).with("https://example.com/feed", http_connection_options).and_return(feed_xml) fp = FeedParser.new({:url => "http://example.com/feed"}.merge(http_connection_options)) fp.parse end it "should not follow redirect from a secure connection to a non-secure one" do - FeedParser.any_instance.should_receive(:open).with("https://example.com/feed", http_connection_options).and_raise(RuntimeError.new("redirection forbidden: https://example.com/feed -> http://example.com/feed")) - FeedParser.any_instance.should_not_receive(:open).with("http://example.com/feed", http_connection_options) + URI.should_receive(:open).with("https://example.com/feed", http_connection_options).and_raise(RuntimeError.new("redirection forbidden: https://example.com/feed -> http://example.com/feed")) + URI.should_not_receive(:open).with("http://example.com/feed", http_connection_options) lambda { fp = FeedParser.new({:url => "https://example.com/feed"}.merge(http_connection_options)) fp.parse @@ -73,7 +73,7 @@ def http_connection_options end it "should raise an error unless retrieved XML is not an RSS or an ATOM feed" do - FeedParser.any_instance.should_receive(:open).with("http://example.com/blog/feed/invalid.xml", http_connection_options).and_return("foo bar") + URI.should_receive(:open).with("http://example.com/blog/feed/invalid.xml", http_connection_options).and_return("foo bar") lambda { fp = FeedParser.new({:url => "http://example.com/blog/feed/invalid.xml"}.merge(http_connection_options)) fp.parse