how to test a function not a action on controller on ruby

Hi, everyone, How to test a function not a action on controller test on ruby? like this: def namesomeone ( firstname, lastname) some codes end how to test this function namesomeone. who knows, please tell me, Thanks!

I personally feel that if something is difficult to test then it's probably not designed very well. This is almost certainly the case for you. Most likely you should move that method to the model, and it becomes obvious how to test it. Or you could write a test for an action that uses it, and verify that you get the proper output.

If a method isn't part of an object's API, you shouldn't be writing a test for it! That's far too granular. You want to write tests for an object's observable behavior.

Pat

There is nothing bad about having a function that is not an action in a controller. Filters are a perfect example of methods in controllers that aren't actions. Testing these methods directly is a great idea as well. Since they're usually protected, you'll have to use .send which will work for non-protected methods as well:

@controller.send(:method, *args)

or in Rspec:

controller.send(:method, *args)