How to Spec flash.now in One Easy Step
Was screwing around this morning trying to successfully spec that flash[:error] is set when the controller actually sets flash.now[:error]. A couple of different Google results had some different approaches none of which thrilled me. Then I tried completely mocking out the flash completely and got this lovely error:
Mock 'Flash now!' received unexpected message :sweep with (no args)
which gave me the brilliant idea to just stub :sweep on the flash. Lo and behold, it works and with a minimum of effort too.
it "should set flash[:error]" do
flash.stub!(:sweep)
post :create, params[:foo] # You'd have set this up for failure in the before block or whatever
flash[:error].should_not be_nil # Spec'ing a specific error message is way brittle
end
Just thought I’d share. Hope you can benefit from it.
1 comment
Leave a Comment