Sha256: 5e4cdf763f2dc2b3f9bd875be144b6a107f0a109d461eca761f4ab009ad80fd1
Contents?: true
Size: 1.43 KB
Versions: 18
Compression:
Stored size: 1.43 KB
Contents
module Webrat module Matchers class HaveSelector < HaveXpath #:nodoc: # ==== Returns # String:: The failure message. def failure_message "expected following text to match selector #{@expected}:\n#{@document}" end # ==== Returns # String:: The failure message to be displayed in negative matches. def negative_failure_message "expected following text to not match selector #{@expected}:\n#{@document}" end def query Nokogiri::CSS::Parser.parse(*super).map { |ast| ast.to_xpath } end end # Matches HTML content against a CSS 3 selector. # # ==== Parameters # expected<String>:: The CSS selector to look for. # # ==== Returns # HaveSelector:: A new have selector matcher. def have_selector(expected, &block) HaveSelector.new(expected, &block) end alias_method :match_selector, :have_selector # Asserts that the body of the response contains # the supplied selector def assert_have_selector(expected) hs = HaveSelector.new(expected) assert hs.matches?(response_body), hs.failure_message end # Asserts that the body of the response # does not contain the supplied string or regepx def assert_have_no_selector(expected) hs = HaveSelector.new(expected) assert !hs.matches?(response_body), hs.negative_failure_message end end end
Version data entries
18 entries across 18 versions & 4 rubygems