1
0
Fork 0
mirror of https://github.com/thoughtbot/shoulda-matchers.git synced 2022-11-09 12:01:38 -05:00

Make flash.now more intuitive

This commit is contained in:
Joshua Clayton 2010-08-02 11:20:51 -04:00
parent 97fb23835c
commit ab895dfea8
2 changed files with 28 additions and 3 deletions

View file

@ -66,10 +66,11 @@ module Shoulda # :nodoc:
end
def flash
flash_and_now = @controller.request.session["flash"]
return @flash if @flash
flash_and_now = @controller.request.session["flash"].dup if @controller.request.session["flash"]
flash = @controller.send(:flash)
if @now
@flash = if @now
flash.keys.each {|key| flash_and_now.delete(key) }
flash_and_now
else
@ -78,7 +79,7 @@ module Shoulda # :nodoc:
end
def expectation
expectation = "the flash to be set"
expectation = "the flash#{".now" if @now} to be set"
expectation << " to #{@value.inspect}" unless @value.nil?
expectation << ", but #{flash_description}"
expectation

View file

@ -58,6 +58,30 @@ class SetTheFlashMatcherTest < ActionController::TestCase # :nodoc:
end
end
context "a controller that sets multiple flash messages" do
setup do
@controller = build_response {
flash.now[:notice] = 'value'
flash[:success] = 'great job'
}
end
should "accept setting any flash.now message" do
assert_accepts set_the_flash.now, @controller
assert_accepts set_the_flash, @controller
end
should "accept setting a matched flash.now message" do
assert_accepts set_the_flash.to(/value/).now, @controller
assert_accepts set_the_flash.to(/great/), @controller
end
should "reject setting a different flash.now message" do
assert_rejects set_the_flash.to('other').now, @controller
assert_rejects set_the_flash.to('other'), @controller
end
end
context "a controller that doesn't set a flash message" do
setup do
@controller = build_response