Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to test ApplicationController method defined also as a helper method?

In my ApplicationController I have a method defined as a helper method:

helper_method :some_method_here

  • How do I test ApplicationController in RSpec at all?
  • How do I include/call this helper method when testing my views/helpers?

I'm using Rails3 with RSpec2

like image 784
Mirko Avatar asked Jan 19 '11 18:01

Mirko


People also ask

What is helper method?

A helper method is a small utility function that can be used to extract logic from views and controllers, keeping them lean. Views should never have logic because they're meant to display HTML.

How do you use the helper method in Ruby on Rails?

A Helper method is used to perform a particular repetitive task common across multiple classes. This keeps us from repeating the same piece of code in different classes again and again. And then in the view code, you call the helper method and pass it to the user as an argument.


1 Answers

You can use an anonymous controller to test your ApplicationController, as describe in the RSpec documentation. There's also a section on testing helpers.

like image 101
Jimmy Avatar answered Nov 07 '22 05:11

Jimmy