class HtmlExpectationsHook
Public Instance Methods
compile(request)
click to toggle source
# File lib/expectations_hook.rb, line 2 def compile(request) request end
run!(request)
click to toggle source
# File lib/expectations_hook.rb, line 6 def run!(request) document = Nokogiri::HTML(compile_content(request)) request.expectations.map do |raw| evaluate_expectation raw, document end end
Private Instance Methods
checker_for(expectation)
click to toggle source
# File lib/expectations_hook.rb, line 22 def checker_for(expectation) lang = expectation.binding.starts_with?('css:')? 'CSS' : 'HTML' "Checker::#{lang}".constantize end
compile_content(request)
click to toggle source
# File lib/expectations_hook.rb, line 31 def compile_content(request) request.content.presence || request.extra end
evaluate_expectation(raw, document)
click to toggle source
# File lib/expectations_hook.rb, line 15 def evaluate_expectation(raw, document) expectation = Mulang::Expectation.parse(raw.with_indifferent_access) binding = expectation.binding.gsub(/(css:)|(html:)/, '') matches = checker_for(expectation).run document, expectation, binding {expectation: raw, result: negate(expectation, matches)} end
negate(expectation, matches)
click to toggle source
# File lib/expectations_hook.rb, line 27 def negate(expectation, matches) expectation.inspection.negated? ? matches.blank? : matches.present? end