mirror of
https://github.com/thoughtbot/shoulda-matchers.git
synced 2022-11-09 12:01:38 -05:00
Enable set_the_flash matcher to test for flash.now
This commit is contained in:
parent
f814549b3e
commit
96a80acb59
2 changed files with 45 additions and 1 deletions
|
@ -10,6 +10,7 @@ module Shoulda # :nodoc:
|
|||
# it { should set_the_flash }
|
||||
# it { should set_the_flash.to("Thank you for placing this order.") }
|
||||
# it { should set_the_flash.to(/created/i) }
|
||||
# it { should set_the_flash.to(/logged in/i).now }
|
||||
# it { should_not set_the_flash }
|
||||
def set_the_flash
|
||||
SetTheFlashMatcher.new
|
||||
|
@ -22,6 +23,11 @@ module Shoulda # :nodoc:
|
|||
self
|
||||
end
|
||||
|
||||
def now
|
||||
@now = true
|
||||
self
|
||||
end
|
||||
|
||||
def matches?(controller)
|
||||
@controller = controller
|
||||
sets_the_flash? && string_value_matches? && regexp_value_matches?
|
||||
|
@ -60,7 +66,15 @@ module Shoulda # :nodoc:
|
|||
end
|
||||
|
||||
def flash
|
||||
@controller.send(:flash)
|
||||
flash_and_now = @controller.request.session["flash"]
|
||||
flash = @controller.send(:flash)
|
||||
|
||||
if @now
|
||||
flash.keys.each {|key| flash_and_now.delete(key) }
|
||||
flash_and_now
|
||||
else
|
||||
flash
|
||||
end
|
||||
end
|
||||
|
||||
def expectation
|
||||
|
|
|
@ -28,6 +28,36 @@ class SetTheFlashMatcherTest < ActionController::TestCase # :nodoc:
|
|||
end
|
||||
end
|
||||
|
||||
context "a controller that sets a flash.now message" do
|
||||
setup do
|
||||
@controller = build_response { flash.now[:notice] = 'value' }
|
||||
end
|
||||
|
||||
should "reject setting any flash message" do
|
||||
assert_rejects set_the_flash, @controller
|
||||
end
|
||||
|
||||
should "accept setting any flash.now message" do
|
||||
assert_accepts set_the_flash.now, @controller
|
||||
end
|
||||
|
||||
should "accept setting the exact flash.now message" do
|
||||
assert_accepts set_the_flash.to('value').now, @controller
|
||||
end
|
||||
|
||||
should "accept setting a matched flash.now message" do
|
||||
assert_accepts set_the_flash.to(/value/).now, @controller
|
||||
end
|
||||
|
||||
should "reject setting a different flash.now message" do
|
||||
assert_rejects set_the_flash.to('other').now, @controller
|
||||
end
|
||||
|
||||
should "reject setting a different flash.now pattern" do
|
||||
assert_rejects set_the_flash.to(/other/).now, @controller
|
||||
end
|
||||
end
|
||||
|
||||
context "a controller that doesn't set a flash message" do
|
||||
setup do
|
||||
@controller = build_response
|
||||
|
|
Loading…
Add table
Reference in a new issue