我正在學習測試,但Webrat沒有找到使用fill_in
的表單字段的一些問題,即使我已驗證它在正確的頁面上。 Webrat是否處理了字段名稱或ID?我已經嘗試使用Ruby符號和表單名稱來訪問該字段,但在我的情況下都不起作用。你看到我的實現有什麼不正確嗎?Rails 3集成測試 - 使用webrat fill_in找不到字段
錯誤消息:
5) Forwarding should forward the user to the requested page after signin
Failure/Error: integration_sign_in(user)
Could not find field: :email
測試代碼:
it "should forward the user to the requested page after signin" do
user = Factory(:user)
visit edit_user_path(user)
# The test automatically follows the redirect to the signin page
puts current_url
integration_sign_in(user)
# The test follows the redirect again, this time to users/edit
response.should render_template('users/edit')
end
其中integration_sign_in
處於spec_helper.rb
def integration_sign_in(user)
fill_in :email, :with => user.email
fill_in :password, :with => user.password
click_button
end
表單字段HTML:
<form action='/sessions' class='mtm' id='sign-in-form' method='post'>
<input name='authenticity_token' type='hidden' value='iIIqT6bUwiJkpqpgxm5sjAj3egrNcEgeXPsYmbKQ02U='>
<div class='landingSignInForm'>
<label class='mas signin-label' for='email'>E-mail:</label>
<input class="mls ras" id="email" name="email" placeholder="e-mail address" type="text" />
<label class='mas signin-label' for='password'>Password:</label>
<input class="mls ras" id="password" name="password" placeholder="password" type="password" />
<input checked='checked' class='mls mtm' name='remember' type='checkbox' value='permanent'>
<span class='remember-me-label'>Keep me signed in</span>
<input class='mls mvm ram medium silver button' name='submit' type='submit' value='Sign in'>
<a class='forgot-password' href='#'>Forget your password?</a>
</div>
</form>
感謝Brett的迴應。不幸的是上述工作都沒有(符號,名稱,ID等)。我幾乎準備放棄Webrat並安裝Capybara,看看它是否只是Webrat問題 – iwasrobbed 2011-03-16 21:42:32
不知道,那麼,對不起,我忍不住了。祝你好運! – 2011-03-16 22:01:14
不用擔心,再次感謝! – iwasrobbed 2011-03-16 22:02:23