user_path(@user) 的 rspec 错误
我有这个测试:
require 'spec_helper'
describe "LayoutLinks" do
I18n.available_locales.each do |locale|
I18n.locale = locale
.
.
describe "when signed in" do
before(:each) do
@user = Factory(:user)
visit signin_path
fill_in :email, :with => @user.email
fill_in :password, :with => @user.password
click_button
visit root_path
end
.
.
.
it "should have a profile link" do
response.should have_selector('a', :href => "/#{I18n.locale}#{user_path(@user)}", :content => I18n.t(:link_profile))
end
end
end
end
我使用网址中的语言选择。像 /en/... 或 /de/...
此测试收到此错误消息:
No route matches {:action=>"show", :controller=>"users", :locale=>#<the complete User Hash>
我从错误消息中猜测,完整的用户哈希被放入 url 的区域设置部分,这是如何完成的或者我该如何做防止这个?
€编辑我找到了解决方案:
我必须以这种方式将语言环境变量传递给 user_path(@user)
:
response.should have_selector('a', :href => user_path (I18n.locale, @user), :content => I1
I have this test:
require 'spec_helper'
describe "LayoutLinks" do
I18n.available_locales.each do |locale|
I18n.locale = locale
.
.
describe "when signed in" do
before(:each) do
@user = Factory(:user)
visit signin_path
fill_in :email, :with => @user.email
fill_in :password, :with => @user.password
click_button
visit root_path
end
.
.
.
it "should have a profile link" do
response.should have_selector('a', :href => "/#{I18n.locale}#{user_path(@user)}", :content => I18n.t(:link_profile))
end
end
end
end
I work with the language selection in the url. Like /en/... or /de/...
This test gets this error Message:
No route matches {:action=>"show", :controller=>"users", :locale=>#<the complete User Hash>
I guess from the error Message that the complete User hash is put into the locale part of the url, How is that done or how could I prevent this?
€Edit I found the solution:
I had to pass the locale variable to the user_path(@user)
in this way:
response.should have_selector('a', :href => user_path(I18n.locale, @user), :content => I1
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论