I'm currently using ruby 1.9.2 and rails 3 and I'm in the middle of rspec testing. Basically, I have a function that is called by a before filter in the application controller such that it obviously gets run every time a controller action is made anywhere on my site. For testing purposes, I'm writing tests for a different controller but my actions do not set off my before filter function call. Is there any way to specifically call functions from a specific controller within rspec tests? I can't post the code online, so no use asking for it :P.
Thanks
-
1It's fine that you can't post your code. Just make up a quick test case of different code which demonstrates the same problem.Craig Stuntz– Craig Stuntz2011-08-24 13:55:31 +00:00Commented Aug 24, 2011 at 13:55
Add a comment
|
1 Answer
Inside an it or before(:each) block in a controller spec:
controller.send( :your_method_name )
And your function is going to be called.
2 Comments
trflach
So if I'm writing tests in "reports_controller_spec.rb" and I want to call a function that exists in my "application_controller.rb", I would put "application_controller.send(:method_name)" in the test?
Maurício Linhares
controller.send(:method_name), your controller is available at a method called controller.