Sha256: 1de728da12690b65a71779e135faa0a77aeefea56c80e94329879bbf71403103

Contents?: true

Size: 1.95 KB

Versions: 77

Compression:

Stored size: 1.95 KB

Contents

module Webrat
  module Selenium
    module Matchers

      class HaveTag < HaveSelector #:nodoc:
        # ==== Returns
        # String:: The failure message.
        def failure_message
          "expected following output to contain a #{tag_inspect} tag:\n#{@document}"
        end

        # ==== Returns
        # String:: The failure message to be displayed in negative matches.
        def negative_failure_message
          "expected following output to omit a #{tag_inspect}:\n#{@document}"
        end

        def tag_inspect
          options = @expected.last.dup
          content = options.delete(:content)

          html = "<#{@expected.first}"
          options.each do |k,v|
            html << " #{k}='#{v}'"
          end

          if content
            html << ">#{content}</#{@expected.first}>"
          else
            html << "/>"
          end

          html
        end

        def query
          options  = @expected.last.dup
          selector = @expected.first.to_s

          selector << ":contains('#{options.delete(:content)}')" if options[:content]

          options.each do |key, value|
            selector << "[#{key}='#{value}']"
          end

          Nokogiri::CSS.parse(selector).map { |ast| ast.to_xpath }
        end
      end

      def have_tag(name, attributes = {}, &block)
        HaveTag.new([name, attributes], &block)
      end

      alias_method :match_tag, :have_tag

      # Asserts that the body of the response contains
      # the supplied tag with the associated selectors
      def assert_have_tag(name, attributes = {})
        ht = HaveTag.new([name, attributes])
        assert ht.matches?(response), ht.failure_message
      end

      # Asserts that the body of the response
      # does not contain the supplied string or regepx
      def assert_have_no_tag(name, attributes = {})
        ht = HaveTag.new([name, attributes])
        assert !ht.matches?(response), ht.negative_failure_message
      end

    end
  end
end

Version data entries

77 entries across 77 versions & 31 rubygems

Version Path
aslakhellesoy-webrat-0.4.4.1 lib/webrat/selenium/matchers/have_tag.rb
casebook-webrat-0.4.4.1 lib/webrat/selenium/matchers/have_tag.rb
cavalle-webrat-0.4.4.1 lib/webrat/selenium/matchers/have_tag.rb
cavalle-webrat-0.4.4.2 lib/webrat/selenium/matchers/have_tag.rb
davidtrogers-webrat-0.4.4.2 lib/webrat/selenium/matchers/have_tag.rb
dbrady-webrat-0.4.4.1 lib/webrat/selenium/matchers/have_tag.rb
dbrady-webrat-0.4.4.2 lib/webrat/selenium/matchers/have_tag.rb
dbrady-webrat-0.4.4 lib/webrat/selenium/matchers/have_tag.rb
diabolo-diabolo-webrat-0.4.4 lib/webrat/selenium/matchers/have_tag.rb
diabolo-webrat-0.4.3 lib/webrat/selenium/matchers/have_tag.rb
diabolo-webrat-0.4.4.1 lib/webrat/selenium/matchers/have_tag.rb
diabolo-webrat-0.4.4.2 lib/webrat/selenium/matchers/have_tag.rb
diabolo-webrat-0.4.4 lib/webrat/selenium/matchers/have_tag.rb
diabolo-webrat-0.5.1 lib/webrat/selenium/matchers/have_tag.rb
dstrelau-webrat-0.5.1 lib/webrat/selenium/matchers/have_tag.rb
emipair-webrat-0.0.1 lib/webrat/selenium/matchers/have_tag.rb
futuresinc-webrat-0.4.4.100 lib/webrat/selenium/matchers/have_tag.rb
futuresinc-webrat-0.4.4.99 lib/webrat/selenium/matchers/have_tag.rb
garnierjm-webrat-0.4.5 lib/webrat/selenium/matchers/have_tag.rb
hardbap-webrat-0.5.1 lib/webrat/selenium/matchers/have_tag.rb