user_path(@user)的rspec错误

时间:2011-11-12 11:12:40

标签: ruby-on-rails 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>

我想从错误消息中将完整的用户哈希放入网址的区域设置部分,如何完成或如何防止这种情况?

€编辑我找到了解决方案:

我必须以这种方式将locale变量传递给user_path(@user)

response.should have_selector('a', :href => user_path(I18n.locale, @user), :content => I1

0 个答案:

没有答案