bundle install
bundle exec ruby feedjira_test.rb
bundle exec ruby monkeypatched_feedjira_test.rb
Last active
August 29, 2015 14:10
-
-
Save deborasetton/1cf4e11e66249f4d8ade to your computer and use it in GitHub Desktop.
Test case for Feedjira issue #253
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'feedjira' | |
| xml = <<-XML | |
| <?xml version="1.0" encoding="UTF-8" ?> | |
| <rss version="2.0"> | |
| <channel> | |
| <title>RSS Title</title> | |
| <item> | |
| <description>This entry is ok.</description> | |
| </item> | |
| <item> | |
| <description>Here is an invalid character: \xE9!</description> | |
| </item> | |
| <item> | |
| <description>This other entry is also ok, but never reached.</description> | |
| </item> | |
| </channel> | |
| </rss> | |
| XML | |
| # Force Feedjira::Parser::RSS.able_to_parse? to return true | |
| xml.force_encoding("ASCII-8BIT") | |
| # Callback that is supposed to be called | |
| callback = ->(*args) { puts "Callback was called with args: "; puts args.inspect } | |
| # This line should cause callback to be called, but nothing happens | |
| feed = Feedjira::Feed.parse(xml, &callback) | |
| # Inspect feed object | |
| puts "Feed entries: #{feed.entries.count}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| source 'https://rubygems.org' | |
| gem 'feedjira', git: 'https://github.com/feedjira/feedjira.git' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'feedjira' | |
| # Monkey-patch Feedjira | |
| module Feedjira::FeedUtilities::ClassMethods | |
| def parse(xml, &block) | |
| xml = xml.lstrip | |
| xml = preprocess(xml) if preprocess_xml | |
| super xml, block | |
| end | |
| end | |
| # Run the same script | |
| load './feedjira_test.rb' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment