Sha256: c4070c3fa7d1b616926fda03cf27619612a2ca506690f81a666d068e9bfc17f8

Contents?: true

Size: 1.76 KB

Versions: 2

Compression:

Stored size: 1.76 KB

Contents

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

      class HaveFlashMatcher < Struct.new(:type, :message)
        attr_reader :page

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

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

        def failure_message
          "Expected flash #{type} to be '#{message}' but was '#{page.find(selector_type, selector).text}'."
        end
        alias_method :failure_message_for_should, :failure_message

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

        private

        def selector_type
          ElabsMatchers.send(:"flash_#{type}_selector_type")
        end

        def selector
          ElabsMatchers.send(:"flash_#{type}_selector")
        end
      end

      ##
      #
      # Asserts if the supplied flash notice exists or not
      #
      # @param [String] message              The content of the flash notice
      #
      # Example:
      # page.should have_flash_notice("Success")

      def have_flash_notice(message)
        HaveFlashMatcher.new(:notice, message)
      end

      ##
      #
      # Asserts if the supplied flash alert exists or not
      #
      # @param [String] message              The content of the flash alert
      #
      # Example:
      # page.should have_flash_alert("Error")

      def have_flash_alert(message)
        HaveFlashMatcher.new(:alert, message)
      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_flash.rb
elabs_matchers-1.0.0 lib/elabs_matchers/matchers/have_flash.rb