【发布时间】:2011-07-15 06:56:56
【问题描述】:
我第一次玩 RoR,遇到了一个奇怪的错误。我的导航链接有以下测试代码:
describe "when logged in" do
before(:each) do
@user = Factory(:user)
visit login_path
#the line below is the weird one
fill_in "session[user_name]", :with => @user.user_name
fill_in :password, :with => @user.password
click_button
end
it "should have navigation links" do
response.should have_selector("nav")
end
it "should have link to log out" do
response.should have_selector("a", :href => logout_path, :content => "Log out")
end
end
上面的代码可以正常工作,但是如果我要更改行
fill_in "session[user_name]", :with => @user.user_name
到
fill_in :user_name, :with => @user.user_name
它不起作用,我不知道为什么。我得到的错误是
Failure/Error: fill_in :user_name, :with => @user.user_name
Webrat::NotFoundError:
Could not find field: :user_name
生成的相关html为:
<label for="session_user_name">User name</label><br/>
<input id="session_user_name" name="session[user_name]" size="30" type="text" />
<label for="session_password">Password</label><br/>
<input id="session_password" name="session[password]" size="30" type="password" />
如果您查看您看到的代码,我对密码就是这样做的,而且效果很好。我想使用导致错误的语法,所以我做错了什么吗?
【问题讨论】:
-
请包含表单的输出 HTML。
-
查看更新...只添加了html的相关部分。
标签: ruby-on-rails-3 rspec webrat