class Shoulda::Matchers::ActionController::SetTheFlashMatcher

:nodoc:

def [](key)

def [](key)
  @options[:key] = key
  self
end

def description

def description
  description = "set the #{expected_flash_invocation}"
  description << " to #{@value.inspect}" unless @value.nil?
  description
end

def expectation

def expectation
  expectation = "the #{expected_flash_invocation} to be set"
  expectation << " to #{@value.inspect}" unless @value.nil?
  expectation << ", but #{flash_description}"
  expectation
end

def expected_flash_invocation

def expected_flash_invocation
  "flash#{pretty_now}#{pretty_key}"
end

def failure_message_for_should

def failure_message_for_should
  "Expected #{expectation}"
end

def failure_message_for_should_not

def failure_message_for_should_not
  "Did not expect #{expectation}"
end

def flash

def flash
  if @flash
    @flash
  else
    @flash = @controller.flash.dup
    used = @controller.flash.instance_variable_get(:@used).dup
    @flash.instance_variable_set(:@used, used)
    sweep_flash_if_necessary
    @flash
  end
end

def flash_description

def flash_description
  if flash.blank?
    'no flash was set'
  else
    "was #{flash.inspect}"
  end
end

def flash_values

def flash_values
  if @options.key?(:key)
    [flash.to_hash[@options[:key]]]
  else
    flash.to_hash.values
  end
end

def initialize

:nodoc:
def initialize
  @options = {}
end

def matches?(controller)

def matches?(controller)
  @controller = controller
  sets_the_flash? && string_value_matches? && regexp_value_matches?
end

def now

def now
  @options[:now] = true
  self
end

def pretty_key

def pretty_key
  if @options[:key]
    "[:#{@options[:key]}]"
  else
    ''
  end
end

def pretty_now

def pretty_now
  if @options[:now]
    '.now'
  else
    ''
  end
end

def regexp_value_matches?

def regexp_value_matches?
  if @value.is_a?(Regexp)
    flash_values.any? {|value| value =~ @value }
  else
    true
  end
end

def sets_the_flash?

def sets_the_flash?
  flash_values.any?
end

def string_value_matches?

def string_value_matches?
  if @value.is_a?(String)
    flash_values.any? {|value| value == @value }
  else
    true
  end
end

def sweep_flash_if_necessary

def sweep_flash_if_necessary
  unless @options[:now]
    @flash.sweep
  end
end

def to(value)

def to(value)
  if !value.is_a?(String) && !value.is_a?(Regexp)
    raise "cannot match against #{value.inspect}"
  end
  @value = value
  self
end