class Test::Unit::TestCase
Public Class Methods
Class-level method to quickly create validation tests for a bunch of actions at once in Rails. For example, if you have a FooController with three actions, just add one line to foo_controller_test.rb:
assert_valid_feed :bar, :baz, :qux
# File lib/feed_validator/assertions.rb, line 80 def self.assert_valid_feed(*actions) actions.each do |action| class_eval <<-EOF def test_#{action}_valid_feed get :#{action} assert_valid_feed end EOF end end
Public Instance Methods
Assert that feed is valid according the W3C Feed Validation online service. By default, it validates the contents of @response.body, which is set after calling one of the get/post/etc helper methods in rails. You can also pass it a string to be validated. Validation errors, warnings and informations, if any, will be included in the output. The response from the validator service will be cached in the system temp directory to minimize duplicate calls.
For example in Rails, if you have a FooController with an action Bar, put this in foo_controller_test.rb:
def test_bar_valid_feed get :bar assert_valid_feed end
# File lib/feed_validator/assertions.rb, line 59 def assert_valid_feed(fragment=@response.body) v = W3C::FeedValidator.new() filename = File.join Dir::tmpdir, 'feed.' + Digest::MD5.hexdigest(fragment).to_s begin response = File.open filename do |f| Marshal.load(f) end v.parse(response) rescue unless v.validate_data(fragment) warn("Sorry! could not validate the feed.") return assert(true,'') end File.open filename, 'w+' do |f| Marshal.dump v.response, f end end assert(v.valid?, v.valid? ? '' : v.to_s) end