Permalink
Browse files

Cleaner flash matcher

  • Loading branch information...
1 parent 73b5a46 commit 76305222fe599e056296bd6b2ea245c307b5e517 Gabe Berke-Williams committed May 7, 2012
Showing with 22 additions and 13 deletions.
  1. +22 −13 lib/shoulda/matchers/action_controller/set_the_flash_matcher.rb
@@ -18,6 +18,10 @@ def set_the_flash
end
class SetTheFlashMatcher # :nodoc:
+ def initialize
+ @options = {}
+ end
+
attr_reader :failure_message, :negative_failure_message
def to(value)
@@ -26,12 +30,12 @@ def to(value)
end
def now
- @now = true
+ @options[:now] = true
self
end
def [](key)
- @key = key
+ @options[:key] = key
self
end
@@ -77,8 +81,8 @@ def regexp_value_matches?
end
def flash_values
- if @key
- [flash.to_hash[@key]]
+ if @options.key?(:key)
+ [flash.to_hash[@options[:key]]]
else
flash.to_hash.values
end
@@ -90,7 +94,7 @@ def flash
else
@flash = @controller.flash.dup
@flash.instance_variable_set(:@used, @controller.flash.instance_variable_get(:@used).dup)
- if ! @now
+ if ! @options[:now]
@flash.sweep
end
@flash
@@ -113,18 +117,23 @@ def flash_description
end
def expected_flash_invocation
- now = ""
- key = ""
+ "flash#{pretty_now}#{pretty_key}"
+ end
- if @now
- now = ".now"
+ def pretty_now
+ if @options[:now]
+ ".now"
+ else
+ ""
end
+ end
- if @key
- key = "[:#{@key}]"
+ def pretty_key
+ if @options[:key]
+ "[:#{@key}]"
+ else
+ ""
end
-
- "flash#{now}#{key}"
end
end
end

0 comments on commit 7630522

Please sign in to comment.