Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
rvm:
- 1.9.3
- 2.0.0
- 2.5.0
- 2.6.0
- 2.7.0
- 3.0.0
4 changes: 2 additions & 2 deletions feed_parser.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
2 changes: 1 addition & 1 deletion lib/feed_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 9 additions & 9 deletions spec/feed_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,47 +33,47 @@ 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
}.should raise_error(RuntimeError, "redirection forbidden: https://example.com/feed -> http://example.com/feed")
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
Expand Down