mirror of
https://github.com/ditkrg/validates_timeliness.git
synced 2026-01-25 15:22:58 +00:00
Datetime select extension fixes with help from @johncarney's fork
This commit is contained in:
35
spec/support/tag_matcher.rb
Normal file
35
spec/support/tag_matcher.rb
Normal file
@@ -0,0 +1,35 @@
|
||||
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
|
||||
Reference in New Issue
Block a user