Since you're saying that the problems are only in the RSpec tests and the app is working fine, then I assume you're expecting the URLs to be in the form of /:locale/profile(.:format)
. So, if you have something like the following route scope in your app...
config/routes.rb
scope ":locale", locale: /#{I18n.available_locales.join("|")}/ do
get 'profile', to: 'users#profile'
# other routes
end
...and you have something like the following in your controller (probably ApplicationController
) that automatically injects the locale
into the url options...
def url_options
{ locale: I18n.locale }.merge(super)
end
(The above could also be an override of default_url_options
as Tom Walpole mentioned)
...then, you'll need to pass that locale
in as a parameter to your paths in the spec as well:
describe 'User go to profile' do
before do
page.driver.header 'Accept-Language', locale
I18n.locale = locale
sign_in (user)
end
context 'locale EN' do
let(:locale) { :en }
scenario 'and view see profile page' do
visit profile_path
expect(current_path).to eq profile_path(locale: locale)
end
end
end
Assuming the above is correct, you could even test this in a rails console and (probably) get output similar to the following:
irb> app.profile_path
ActionController::UrlGenerationError: No route matches {:action=>"profile", :controller=>"users"} missing required keys: [:locale]
irb> app.profile_path(locale: :en)
"/en/profile"