2

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

1
  • 1
    It's fine that you can't post your code. Just make up a quick test case of different code which demonstrates the same problem. Commented Aug 24, 2011 at 13:55

1 Answer 1

4

Inside an it or before(:each) block in a controller spec:

controller.send( :your_method_name )

And your function is going to be called.

Sign up to request clarification or add additional context in comments.

2 Comments

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?
controller.send(:method_name), your controller is available at a method called controller.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.