1

我正在尝试这样做:

我的测试如下:

describe "User pages" do

subject { page }

describe "edit" do
  let(:user) { FactoryGirl.create(:user) }
  before do
    log_in user 
    #visit edit_user_path(user) <-- did not work
  end

describe "page" do
  it "should render edit page" do
    get :edit, :id => user.id
    should have_selector('h1',    text: "Update")
    should have_selector('h2',    text: user.username)
    should have_selector('title', text: "Edit user")
  end
end

describe "with invalid information" do
  before { click_button "Save changes" }
  it { should have_content('error') }
end

结尾

我尝试添加get :edit, :id => user.id,但它引发了异常:

Failure/Error: get :edit, :id => user.id
 ArgumentError:
   bad argument (expected URI object or URI string)

还有什么我想念的吗?

4

3 回答 3

1

1)确保您的测试文件有一个块,如:

 describe UsersController do
   # your tests here
 end

2)尝试像这样重写get

 it "should render edit page" do
    get :edit, :id => user.to_param
    should have_selector('h1',    text: "Update")
    # ...
 end
于 2012-11-06T12:13:22.837 回答
0

试试这个

describe "page" do
  it "should render edit page" do
    p = FactoryGirl.create(:user)
    get :edit, :id => p.id
    should have_selector('h1',    text: "Update")
    should have_selector('h2',    text: user.username)
    should have_selector('title', text: "Edit user")
  end
end
于 2012-11-06T09:53:47.057 回答
0

我最终这样做了:

visit edit_user_path(user.id) 

我不确定是否阅读了有关哪种方法(获取与访问)是首选的内容。

于 2012-11-07T04:24:12.227 回答