我正在做我的註冊頁面的測試,但我得到這個錯誤,說它找不到該字段。我使用的輸入ID在FILL_IN方法水豚:: ElementNotFound:無法找到字段「user_email」
<%= form_for @user, url: {action: "create"},html: {class: "horizontal-form", id: "signup-form"} do |f| %>
<div class="form-group">
<%= f.email_field :email, placeholder: "Email", class: "form-control" %>
<%= f.text_field :username, placeholder: "Username", class: "form-control" %>
<%= f.password_field :password, placeholder: "Password", class: "form-control" %>
<%= f.password_field :password_confirmation, placeholder: "Password Confirmation", class: "form-control" %>
<%= f.submit "Sign Up", class: "btn" %>
</div>
<% end %>
測試
require 'rails_helper'
RSpec.describe UsersController, type: :controller do
describe "GET Sign-Up" do
it "returns http success" do
visit '/signup'
get :new
expect(response).to have_http_status(:success)
end
end
describe "Post User" do
it "creates user" do
user_params = FactoryGirl.attributes_for(:user)
fill_in "user_email", with: "user_params[:email]"
fill_in "user_username", with: user_params[:username]
fill_in "user_password", with: user_params[:password_digest]
fill_in "user_password_confirmation", with: user_params[:password_digest]
click_button "Sign Up"
expect {
post :create, user: user_params
}.to change(User, :count).by(1)
expect(current_path).to redirect_to(root_path)
end
end
end
,但我不斷收到此錯誤
1) UsersController GET Sign-Up returns http success
Failure/Error: fill_in "user_email", with: "user_params[:email]"
Capybara::ElementNotFound:
Unable to find field "user_email"
我添加了'visit'/ signup'',但仍然是相同的錯誤 – eustass
你可以刪除fill_in和click_button行嗎?他們不需要進行測試。 –