RubyFlow The Ruby and Rails community linklog

Fix non set locale in path helpets in RSpec test files

This filter hook set the default locale for the filtered examples to get the correct path helpers.

For example the route:

scope "(:locale)" do
  get "xxx/:id", to: "xxx#show", as: :xxx
end

The helper for this route is for example:

xxx_path(1)

This helper will work in rails app in other than test envs, but not in test mode, because “1” will be assigned to :locale and not to :id, and it will complain from not having :id set.

The only solution I found is to stub ActionController::Base.default_url_options.

https://gist.github.com/ubugnu/1a57103b90c32991f4e512d47d9e1561

Post a comment

You can use basic HTML markup (e.g. <a>) or Markdown.

As you are not logged in, you will be
directed via GitHub to signup or sign in