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
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/validates_timeliness-4.0.2/spec/support/tag_matcher.rb
validates_timeliness-4.0.2 spec/support/tag_matcher.rb
validates_timeliness-4.0.1 spec/support/tag_matcher.rb
validates_timeliness-4.0.0 spec/support/tag_matcher.rb
sp-validates_timeliness-3.1.3 spec/support/tag_matcher.rb
sp-validates_timeliness-3.1.2 spec/support/tag_matcher.rb
jc-validates_timeliness-3.1.1 spec/support/tag_matcher.rb
jc-validates_timeliness-3.1.0 spec/support/tag_matcher.rb