Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Continue cleaning up matchers.
  • Loading branch information
Gabe Berke-Williams committed Mar 30, 2012
1 parent 36006d8 commit 96df0b1
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions lib/shoulda/matchers/action_controller/set_the_flash_matcher.rb
Expand Up @@ -18,6 +18,7 @@ def set_the_flash
end

class SetTheFlashMatcher # :nodoc:
attr_reader :failure_message, :negative_failure_message

def to(value)
@value = value
Expand All @@ -39,8 +40,6 @@ def matches?(controller)
sets_the_flash? && string_value_matches? && regexp_value_matches?
end

attr_reader :failure_message, :negative_failure_message

def description
description = "set the #{expected_flash_invocation}"
description << " to #{@value.inspect}" unless @value.nil?
Expand All @@ -62,13 +61,19 @@ def sets_the_flash?
end

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

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

def flash_values
Expand All @@ -80,11 +85,16 @@ def flash_values
end

def flash
return @flash if @flash
@flash = @controller.flash.dup
@flash.instance_variable_set(:@used, @controller.flash.instance_variable_get(:@used).dup)
@flash.sweep unless @now
@flash
if @flash
@flash
else
@flash = @controller.flash.dup
@flash.instance_variable_set(:@used, @controller.flash.instance_variable_get(:@used).dup)
if ! @now
@flash.sweep
end
@flash
end
end

def expectation
Expand Down

0 comments on commit 96df0b1

Please sign in to comment.