Sha256: d4e90605104712e56552720521c5f3b84ae22d909dfa6c374ee41a2b2828b69f

Contents?: true

Size: 1.41 KB

Versions: 2

Compression:

Stored size: 1.41 KB

Contents

module ElabsMatchers
  module Matchers
    module HaveHeader
      rspec :type => :request
      rspec :type => :feature

      class HaveHeaderMatcher < Struct.new(:text)
        attr_reader :page

        def matches?(page)
          @page = page
          page.has_selector?(selector_type, selector, :text => text)
        end

        def does_not_match?(page)
          @page = page
          page.has_no_selector?(selector_type, selector, :text => text)
        end

        def failure_message
          headers = page.all(selector_type, selector).map { |h| "'#{h.text}'" }.to_sentence
          "Expected header to be '#{text}' but it had the headers #{headers}."
        end
        alias_method :failure_message_for_should, :failure_message

        def failure_message_when_negated
          "Expected header not to be '#{text}' but it was."
        end
        alias_method :failure_message_for_should_not, :failure_message_when_negated

        private

        def selector
          ElabsMatchers.header_selector
        end

        def selector_type
          ElabsMatchers.header_selector_type
        end
      end

      ##
      #
      # Asserts if the supplied header exists or not
      #
      # @param [String] text              The content of the header
      #
      # Example:
      # page.should have_header("Elabs")

      def have_header(text)
        HaveHeaderMatcher.new(text)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
elabs_matchers-1.0.1 lib/elabs_matchers/matchers/have_header.rb
elabs_matchers-1.0.0 lib/elabs_matchers/matchers/have_header.rb