Hunt Jon
2009-May-26 14:32 UTC
[rspec-users] How to spec two lines in application_controller.rb
I need to spec the following lines: helper :all # include all helpers, all the time protect_from_forgery # See ActionController::RequestForgeryProtection for detail Can anybody give me a hint? I create "application_controller_spec.rb" and now what? Jon
Andrew Timberlake
2009-May-26 15:14 UTC
[rspec-users] How to spec two lines in application_controller.rb
On Tue, May 26, 2009 at 4:32 PM, Hunt Jon <jona.hunt777 at gmail.com> wrote:> I need to spec the following lines: > > ?helper :all # include all helpers, all the time > ?protect_from_forgery # See > ActionController::RequestForgeryProtection for detail > > Can anybody give me a hint? > > I create "application_controller_spec.rb" and now what? > > JonYou shouldn''t need to spec those two lines specifically. What you want to do is spec the behaviour. So if you want a particular helper method to be available, write a spec that relies on that helper method (in another controller because they all use ApplicationController). If you then take out helper :all, your spec may fail (don''t know, never tried) If it doesn''t, well then you don''t need the line :-) For protect_from_forgery, again spec the behaviour you expect (again, in a different controller spec) If you take out the line and your code still works, you don''t need the line. If you take it out and the spec breaks, you know you''ve tested the behaviour you want, and not a line! I never spec either of these lines because their behaviour is tested in the Rails code. I am only concerned with testing my applications and the behaviour I want out of them. As an aside, if you''re concerned about code coverage, both lines should execute with every controller test as they must execute while creating the ApplicationController class. Regards Andrew Timberlake http://ramblingsonrails.com http://MyMvelope.com - The SIMPLE way to manage your savings
Fernando Perez
2009-May-26 16:52 UTC
[rspec-users] How to spec two lines in application_controller.rb
Hunt Jon wrote:> I need to spec the following lines:No you don''t. They are thoroughly tested in the Rails framework and you didn''t add any behavior to them, so reading them makes it immediately clear what they are doing. Don''t worry without specing these 2 lines you''ll still get your 100% coverage. -- Posted via http://www.ruby-forum.com/.