Sha256: 82cf0f8f7147ec74a632d5f4770b02b9302ecd8a8c5261d5aa7b17a16158c868

Contents?: true

Size: 1.39 KB

Versions: 1

Compression:

Stored size: 1.39 KB

Contents

module Warp
  module ControllerMatchers
    class SetFlashMatcher
      include RSpec::Matchers::Composable

      attr_reader :flash_key, :expected_flash_value
      attr_reader :controller, :failure_message, :failure_message_when_negated, :description

      def initialize(flash_key)
        @flash_key = flash_key
      end

      def to(expected_flash_value)
        @expected_flash_value = expected_flash_value
        self
      end

      def matches?(controller)
        @controller = controller

        if expected_flash_value
          @description = "set flash[:#{flash_key}] to #{expected_flash_value.inspect}"
          @failure_message = "expected flash[:#{flash_key}] to be set to #{expected_flash_value.inspect}"
          @failure_message_when_negated = "expected flash[:#{flash_key}] to not be set to #{expected_flash_value.inspect}"
          values_match?(expected_flash_value, flash_value)
        else
          @description = "set flash[:#{flash_key}]"
          @failure_message = "expected flash[:#{flash_key}] to be set"
          @failure_message_when_negated = "expected flash[:#{flash_key}] to not be set"
          values_match?(false, flash_value.nil?)
        end
      end

      private

      def flash_value
        flash[flash_key]
      end

      def flash
        controller.flash
      end
    end

    def set_flash(flash_key)
      SetFlashMatcher.new(flash_key)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
warp-1.0.0 lib/warp/controller_matchers/set_flash_matcher.rb