class Shoulda::Matchers::ActionController::SetTheFlashMatcher

:nodoc:

def description

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

def expectation

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

def failure_message

def failure_message
  "Expected #{expectation}"
end

def flash

def flash
  return @flash if @flash
  @flash = @controller.flash.dup
  @flash.sweep unless @now
  @flash
end

def flash_description

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

def matches?(controller)

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

def negative_failure_message

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

def now

def now
  @now = true
  self
end

def regexp_value_matches?

def regexp_value_matches?
  return true unless Regexp === @value
  flash.to_hash.values.any? {|value| value =~ @value }
end

def sets_the_flash?

def sets_the_flash?
  !flash.blank?
end

def string_value_matches?

def string_value_matches?
  return true unless String === @value
  flash.to_hash.values.any? {|value| value == @value }
end

def to(value)

def to(value)
  @value = value
  self
end