2016-05-31 113 views
0

我只是在學習功能規格,我遇到了一個我無法弄清楚的問題。當我嘗試運行我的測試時出現了Capybara::ElementNotFound:。這很奇怪,因爲我一直遵循一個模板詞,但我仍然得到這個錯誤。我想要一些幫助!這是我的代碼和錯誤的清晰。水豚:: ElementNotFound:找不到字段

TEST

require "rails_helper" 

RSpec.feature "Create a subscriber" do 
scenario "Customer can sign up as a subscriber" do 
    visit "/subscribers/new" 

    user = User.create!(email: "[email protected]", password: "password") 
    fill_in "Email", with: "[email protected]" 
    fill_in "Password", with: "password" 
    click_button "Sign in" 

    fill_in "first_name", with: 
    fill_in "last_name", with: 
    fill_in "email", with: 
    fill_in "phone_number", with: "8269338" 

    expect(page).to have_content("Subscriber Has Been Successfully Created") 
end 
end 

VIEW

<%= form_for @subscriber do |form| %> 
    <div class="form-group"> 
    <p> 
    <%= form.label :first %> 
    <%= form.text_field :first_name %> 
    </p> 
    <p> 
    <%= form.label :last %> 
    <%= form.text_field :last_name %> 
    </p> 
    <p> 
    <%= form.label :email %> 
    <%= form.text_field :email %> 
    </p> 
    <p> 
    <%= form.label :phone %> 
    <%= form.text_field :phone_number %> 
    </p> 
</div> 
<%= form.submit "Sign Up", class: "btn btn-primary" %> 

ERROR enter image description here

回答

1

字段的ID都將與subscriber_前綴 - 嘗試改變fill_in "first_name", with: "Cam"fill_in "subscriber_first_name", with: "Cam",看看是否能解決它。