WpItem::Existable specs

This commit is contained in:
erwanlr
2013-03-22 21:53:20 +01:00
parent e058b204f4
commit 6f49584546
4 changed files with 101 additions and 4 deletions

View File

@@ -3,6 +3,14 @@
class WpItem
module Existable
# Check the existence of the WpItem
# If the response is supplied, it's used for the verification
# Otherwise a new request is done
#
# @param [ Hash ] options See exists_from_response?
# @param [ Typhoeus::Response ] response
#
# @return [ Boolean ]
def exists?(options = {}, response = nil)
unless response
response = Browser.instance.get(url)
@@ -12,15 +20,18 @@ class WpItem
protected
# options:
# :error_404_hash
# :homepage_hash
# :exclude_content REGEXP
# @param [ Typhoeus::Response ] response
# @param [ options ] options
#
# @option options [ Hash ] :error_404_hash The hash of the error 404 page
# @option options [ Hash ] :homepage_hash The hash of the homepage
# @option options [ Hash ] :exclude_content A regexp with the pattern to exclude from the body of the response
#
# @return [ Boolean ]
def exists_from_response?(response, options = {})
# FIXME : The response is supposed to follow locations, so we should not have 301 or 302.
# However, due to an issue with Typhoeus or Webmock, the location is not followed in specs
# See https://github.com/typhoeus/typhoeus/issues/279
if [200, 301, 302, 401, 403].include?(response.code)
if response.has_valid_hash?(options[:error_404_hash], options[:homepage_hash])
if options[:exclude_content]