Sha256: 232be335d003084bc2c39060df6cd805fbcb2898b4fcf776bbff1556c11770d3

Contents?: true

Size: 1.59 KB

Versions: 18

Compression:

Stored size: 1.59 KB

Contents

module Webrat
  module Selenium
    module Matchers
      class HaveSelector
        def initialize(expected)
          @expected = expected
        end

        def matches?(response)
          response.session.wait_for do
            response.selenium.is_element_present("css=#{@expected}")
          end
          rescue Webrat::TimeoutError
            false
        end

        def does_not_match?(response)
          response.session.wait_for do
            !response.selenium.is_element_present("css=#{@expected}")
          end
          rescue Webrat::TimeoutError
            false
        end

        # ==== 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
      end

      def have_selector(content)
        HaveSelector.new(content)
      end

      # Asserts that the body of the response contains
      # the supplied selector
      def assert_have_selector(expected)
        hs = HaveSelector.new(expected)
        assert hs.matches?(response), 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), hs.negative_failure_message
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 9 rubygems

Version Path
radiant-1.0.0 ruby-debug/ruby/1.8/gems/webrat-0.7.3/lib/webrat/selenium/matchers/have_selector.rb
indirect-webrat-0.7.5 lib/webrat/selenium/matchers/have_selector.rb
indirect-webrat-0.7.4 lib/webrat/selenium/matchers/have_selector.rb
webrat-0.7.3 lib/webrat/selenium/matchers/have_selector.rb
jbd-webrat-0.7.2.rails3 lib/webrat/selenium/matchers/have_selector.rb
webrat-0.7.2 lib/webrat/selenium/matchers/have_selector.rb
webrat-0.7.2.beta.2 lib/webrat/selenium/matchers/have_selector.rb
mutle-webrat-0.7.2.beta.1 lib/webrat/selenium/matchers/have_selector.rb
thoughtbot-webrat-0.7.2.pre lib/webrat/selenium/matchers/have_selector.rb
webrat-0.7.2.beta.1 lib/webrat/selenium/matchers/have_selector.rb
honkster-webrat-0.7.1.2 lib/webrat/selenium/matchers/have_selector.rb
honkster-webrat-0.7.1.1 lib/webrat/selenium/matchers/have_selector.rb
revo-webrat-0.7.0.1 lib/webrat/selenium/matchers/have_selector.rb
webrat-0.7.1 lib/webrat/selenium/matchers/have_selector.rb
davidtrogers-webrat-0.7.0 lib/webrat/selenium/matchers/have_selector.rb
revo-webrat-0.7.0 lib/webrat/selenium/matchers/have_selector.rb
revo-webrat-0.7.1.pre lib/webrat/selenium/matchers/have_selector.rb
webrat-0.7.0 lib/webrat/selenium/matchers/have_selector.rb