Sha256: 7c184660d48c46c9d1e48054387b49c577a87837954ab9ec5ec7b2094f14ffbe

Contents?: true

Size: 624 Bytes

Versions: 28

Compression:

Stored size: 624 Bytes

Contents

require 'nokogiri'

module TagMatcher
  extend RSpec::Matchers::DSL

  matcher :have_tag do |selector|
    match do |subject|
      matches = doc(subject).search(selector)

      if @inner_text
        matches = matches.select { |element| element.inner_text == @inner_text }
      end

      matches.any?
    end

    chain :with_inner_text do |inner_text|
      @inner_text = inner_text
    end

    private

    def body(subject)
      if subject.respond_to?(:body)
        subject.body
      else
        subject.to_s
      end
    end

    def doc(subject)
      @doc ||= Nokogiri::HTML(body(subject))
    end
  end
end

Version data entries

28 entries across 28 versions & 4 rubygems

Version Path
validates_timeliness-8.0.0.beta1 spec/support/tag_matcher.rb
validates_timeliness-7.0.0 spec/support/tag_matcher.rb
validates_timeliness-7.0.0.beta2 spec/support/tag_matcher.rb
validates_timeliness-5.0.1 spec/support/tag_matcher.rb
validates_timeliness-6.0.1 spec/support/tag_matcher.rb
validates_timeliness-7.0.0.beta1 spec/support/tag_matcher.rb
validates_timeliness-6.0.0 spec/support/tag_matcher.rb
validates_timeliness-6.0.0.beta2 spec/support/tag_matcher.rb
validates_timeliness-6.0.0.beta1 spec/support/tag_matcher.rb
validates_timeliness-6.0.0.alpha1 spec/support/tag_matcher.rb
validates_timeliness-5.0.0 spec/support/tag_matcher.rb
validates_timeliness-5.0.0.beta2 spec/support/tag_matcher.rb
validates_timeliness-5.0.0.beta1 spec/support/tag_matcher.rb
validates_timeliness-5.0.0.alpha5 spec/support/tag_matcher.rb
validates_timeliness-4.1.1 spec/support/tag_matcher.rb
validates_timeliness-4.1.0 spec/support/tag_matcher.rb
validates_timeliness-5.0.0.alpha4 spec/support/tag_matcher.rb
validates_timeliness-5.0.0.alpha3 spec/support/tag_matcher.rb
validates_timeliness-5.0.0.alpha2 spec/support/tag_matcher.rb
validates_timeliness-5.0.0.alpha1 spec/support/tag_matcher.rb