Testing helpers that use the url_for method

I have a helper method:

def my_helper(builder, name, order)
  options = {
    builder.search_key => builder.search_attributes.merge('sort' => order)
  }
  link_to name, url_for(options)
end

The helper adds some parameters (here a simplified example) to the current url and build link. When I try to test this method with RSpec, I get an exception ActionController::RoutingError: No route matches {:search=>{"sort"=>"published_at.asc"}}. How can I drown out the current link, path, controller, action?

+4
source share
1 answer

I would advise you to check only if the options passed as expected link_to(correctly merge the additional parameters ( 'sort' => order)), you do not need to test url_for, Rails already got good coverage for testing this method!

0
source

Source: https://habr.com/ru/post/1535478/


All Articles