Sha256: 5f71d725d4eea34c84639f2eb0c3cb76d3f3dd429d0169c0f2a8d704cce47e27

Contents?: true

Size: 1.27 KB

Versions: 3

Compression:

Stored size: 1.27 KB

Contents

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

      class HaveFieldsMatcher < Struct.new(:fields)
        attr_reader :page

        def matches?(page)
          @page = page
          fields.all? { |label, value| page.has_field?(label, :with => value) }
        end

        def does_not_match?(page)
          @page = page
          fields.all? { |label, value| page.has_no_field?(label, :with => value) }
        end

        def failure_message_for_should
          field_values = page.all("input, textarea").map { |input| input[:value] }

          "expected page to have the fields #{fields.inspect}, but it didn't.
           The fields on the page had the following values: #{field_values.to_sentence}."
        end

        def failure_message_for_should_not
          "expected page not to have the fields #{fields.inspect}, but it did."
        end
      end

      ##
      #
      # Asserts if the supplied fields exists or not
      #
      # @param [Hash] fields         A hash containing pairs of field name => value
      #
      # Example:
      # page.should have_fields("Author" => "Adam", "Year" => "2011")

      def have_fields(fields)
        HaveFieldsMatcher.new(fields)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
elabs_matchers-0.0.7 lib/elabs_matchers/matchers/have_fields.rb
elabs_matchers-0.0.6 lib/elabs_matchers/matchers/have_fields.rb
elabs_matchers-0.0.5 lib/elabs_matchers/matchers/have_fields.rb