class BeValidAsset::BeValidFeed

Public Class Methods

new() click to toggle source
# File lib/be_valid_asset/be_valid_feed.rb, line 10
def initialize()
end

Public Instance Methods

description() click to toggle source
# File lib/be_valid_asset/be_valid_feed.rb, line 23
def description
  "be valid feed (RSS / Atom)"
end
failure_message() click to toggle source
# File lib/be_valid_asset/be_valid_feed.rb, line 27
def failure_message
  " expected feed to be valid, but validation produced these errors:\n#{@message}"
end
failure_message_when_negated() click to toggle source
# File lib/be_valid_asset/be_valid_feed.rb, line 31
def failure_message_when_negated
  " expected to not be valid, but was (missing validation?)"
end
Also aliased as: negative_failure_message
matches?(fragment) click to toggle source
# File lib/be_valid_asset/be_valid_feed.rb, line 13
def matches?(fragment)

  if fragment.respond_to? :body
    fragment = fragment.body.to_s
  end

  query_params = { :rawdata => fragment, :manual => '1' }
  return validate(query_params)
end
negative_failure_message()

continue to support Rspec < 3

Private Instance Methods

call_validator(query_params) click to toggle source

The feed service takes params differently.

# File lib/be_valid_asset/be_valid_feed.rb, line 40
def call_validator(query_params)
  check_net_enabled
  params = "rawdata=#{CGI.escape(query_params[:rawdata])}&manual=1&output=soap12"
  return http_start(validator_host).post(validator_path, params, {} )
end
error_line_prefix() click to toggle source
# File lib/be_valid_asset/be_valid_feed.rb, line 67
def error_line_prefix
  'Invalid feed'
end
process_errors(query_params, response) click to toggle source
# File lib/be_valid_asset/be_valid_feed.rb, line 51
def process_errors(query_params, response)
  fragment = query_params[:rawdata]
  fragment.split($/).each_with_index{|line, index| @message << "#{'%04i' % (index+1)} : #{line}#{$/}"} if Configuration.display_invalid_content
  REXML::Document.new(response.body).root.each_element('//error') do |e|
    @message << "#{error_line_prefix}: line #{e.elements['line'].text}: #{e.elements['text'].text}\n"
  end
end
response_indicates_valid?(response) click to toggle source

The feed validator uses a different response type, so we have to override these here.

# File lib/be_valid_asset/be_valid_feed.rb, line 47
def response_indicates_valid?(response)
  REXML::Document.new(response.body).root.get_elements('//m:validity').first.text == 'true'
end
validator_host() click to toggle source
# File lib/be_valid_asset/be_valid_feed.rb, line 59
def validator_host
  Configuration.feed_validator_host
end
validator_path() click to toggle source
# File lib/be_valid_asset/be_valid_feed.rb, line 63
def validator_path
  Configuration.feed_validator_path
end