Hi, How can I test flash.now[:key] is being set in a controller test? Both flash[:key] and flash.now[:key].should == message didn''t work I can use response.session["flash"][:key].should == message . Just looks bad Thanks Yi -- http://yiwenandsoftware.wordpress.com -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20090327/e380216b/attachment.html>
2009/3/28 Yi <hayafirst at gmail.com>:> How can I test flash.now[:key] is being set in a controller test? Both > flash[:key] and flash.now[:key].should == message didn''t work > > I can use response.session["flash"][:key].should == message . Just looks badThat''s odd. In a controller example, you should have a #flash method available to do exactly what you tried: http://rspec.rubyforge.org/rspec-rails/1.2.2/classes/Spec/Rails/Example/FunctionalExampleGroup.html#M000051 Try this: where you would like to put the expectation, put "puts self.class". Then run it and see what class name it prints. If it''s ControllerExampleGroup, then there''s something weird going on. If it''s not, then it hasn''t figured out that you''re spec''ing a controller. In that case, post the opening of the describe block and we''ll be able to see what''s going on. Peter
Yi wrote:> Hi, > > How can I test flash.now[:key] is being set in a controller test? Both > flash[:key] and flash.now[:key].should == message didn''t work > > I can use response.session["flash"][:key].should == message . Just > looks bad > > Thanks > > Yi > > -- > http://yiwenandsoftware.wordpress.comIn the past I have used this article to test flash.now in rspec: http://www.kerrybuckley.org/2007/07/04/correct-use-of-the-flash-in-rails/ Note, that the post is pretty old and so rspec-rails may support this out of the box by now.. I don''t know though. -Ben