测试Rspec中未定义的方法`user_path'

时间:2015-07-04 21:38:05

标签: ruby-on-rails ruby rspec

我运行测试rspec并显示错误:

<GridView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/gridview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:columnWidth="90dp"
    android:numColumns="auto_fit"
    android:verticalSpacing="10dp"
    android:horizontalSpacing="10dp"
    android:stretchMode="columnWidth"
    android:gravity="center"
    />

如何正确设置测试路线?

user_spec.rb

Failure/Error: before { visit user_path(user) }
   NoMethodError:
     undefined method `user_path' for #<RSpec::ExampleGroups::UserPages::ProfilePage:0xcd1f7c0>

我的 routes.rb ,其中添加了i route get'/ users /:id',用于:'users#show',:as =&gt; :用户

require 'rails_helper'

describe "User pages" do

  subject { page }

  describe "profile page" do
      let(:user) { FactoryGirl.create(:user) }
      before { visit user_path(user) }

      it { should have_content(user.name) }
      it { should have_title(user.name) }
  end
  describe "signup page" do
    before { visit signup_path }

    it { should have_content("Sign up") }
    it { should have_title(full_title('Sign up')) }
  end
end

请解释一下,如何正确添加测试rspec的路线。我使用rails 4. M

1 个答案:

答案 0 :(得分:1)

我添加了类型::功能来描述“个人资料页面”,问题已修复。谢谢,BroiSatse