Dynamic method call in routes spec

I am testing simple get requests for my routes using rspec in my Rails 3.2 application. Since all are get requests, and all just have different action names which are similar to the views' names, it would be really repetitive to manually write a different test for each get request.

Instead, I wanted to come up with something like this:

%(action_1 action_2 action_3 action_4).each do |action|
    it "routes to the #{action} page" do
        get("liver_diseases#{action}_path").should route_to("liver_diseases##{action}")
    end
end

It fails at this pseudocode: get("liver_diseases_#{action}_path") So what I need to do is a dynamic method call - but for what I have found out, that would involve .send(:method_name), for which I need to know the class name. And I couldn't find that.

What do I need to do for this method call to work?

Answers


that would involve .send(:method_name), for which I need to know the class name

When the receiver is missing, it's always self. In the context of a controller example, self should be a controller instance. So you should be able to get that path with:

send "liver_diseases_#{action}_path"

which should be equivalent to:

controller.send "liver_diseases_#{action}_path"

Need Your Help

django autocomplete-light template plus sign

python django-templates django-admin django-autocomplete-light

Newbee here. I'm using django-autocomplete-light for my foreign field key in django admin.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.