Class: RSpec::Sitemap::Matchers::IncludeUrl

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/sitemap/matchers/include_url.rb

Constant Summary collapse

ALLOWED_ATTRS =
%w(priority changefreq lastmod)

Instance Method Summary collapse

Constructor Details

#initialize(expected_location) ⇒ IncludeUrl

Returns a new instance of IncludeUrl.



6
7
8
# File 'lib/rspec/sitemap/matchers/include_url.rb', line 6

def initialize(expected_location)
  @expected_location = expected_location
end

Instance Method Details

#changefreq(expected_changefreq) ⇒ Object



40
41
42
43
# File 'lib/rspec/sitemap/matchers/include_url.rb', line 40

def changefreq(expected_changefreq)
  expected_attributes.merge!(:changefreq => expected_changefreq)
  self
end

#failure_messageObject



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/rspec/sitemap/matchers/include_url.rb', line 17

def failure_message
  [].tap do |messages|
    messages << "expected #{@actual} to include a URL to #{@expected_location}"
    unmatched_attributes.each { |attribute, actual_value|
      if actual_value.nil?
        messages << "with a #{attribute} of #{expected_attributes[attribute]} but the #{attribute} was not set"
      else
        messages << "with a #{attribute} of #{expected_attributes[attribute]} but it was set to #{actual_value}"
      end
    }
  end.join(' ')
end

#lastmod(expected_lastmod) ⇒ Object



35
36
37
38
# File 'lib/rspec/sitemap/matchers/include_url.rb', line 35

def lastmod(expected_lastmod)
  expected_attributes.merge!(:lastmod => expected_lastmod)
  self
end

#matches?(actual) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


11
12
13
14
15
# File 'lib/rspec/sitemap/matchers/include_url.rb', line 11

def matches?(actual)
  @actual = Nokogiri::XML(actual) { |config| config.noblanks }
  @nodes = @actual.xpath(construct_xpath)
  @nodes.any? && attributes_match?
end

#priority(expected_priority) ⇒ Object



30
31
32
33
# File 'lib/rspec/sitemap/matchers/include_url.rb', line 30

def priority(expected_priority)
  expected_attributes.merge!(:priority => expected_priority)
  self
end