2

我的 Rails 应用程序中有两个模型,比如说公司模型和潜在客户模型来添加潜在客户。我必须在添加新潜在客户时测试潜在客户表格。所以我使用了集成测试。我的表单上有字段,我也通过这些字段更新了数据库,但未找到水豚错误元素。我的代码如下

新的潜在客户表格

<title>Add Contact</title>
<h1> Enter Lead information</h1>
<%= form_for @lead, :url => lead_path(@lead.id), :html => { :multipart =>true } do|f|%>                                                                                      
<p>
<%= f.label :Name %><br>
<%= f.text_field :name %>
</p>
<p>
<%= f.label :Linkedln_Address, 'Linkedln_Address' %><br>
<%= f.text_field :linkedln_address %>
</p>
<p>
<%= f.label :Twitter_Feed, 'Twitter_Feed'%><br>
<%= f.text_field :twitter_feed %>
</p>
<p>
<%= f.label :avatar, "Image File" %>
<%= f.file_field :avatar %>
</p>
<p>
<%= f.label :Notes, 'Notes' %><br>
<%= f.text_area :notes %>
</p>
<p>
<%= f.submit %>
</p>
<% end %>'`

我的规格是 spec/requests/leads_spec.rb

`require 'spec_helper'
 describe "POST /lead", type: :feature do
  it 'creates and saves valid lead' do
      visit "/lead/new" 
     fill_in 'Name', :with => "abcdefg"
        fill_in 'linkedln_address', with: 'lmnop@gmail.com'
    fill_in 'twitter_feed', with: 'www.twiitter.com/microsoft'
     fill_in 'notes', with: 'ajkhd akjf \n alskdfh alsjdfh'
     click_button 'create Lead'


    current_path.should ==lead_path
    page.should have_content 'The Lead is Successfully Added'
    within 'h1' do
     page.should have_content "abcdefg"
    end
    page.should have_content "lmnop@gmail.com"
     page.should have_content "www.twiitter.com/microsoft"
      page.should have_content "ajkhd akjf \n alskdfh alsjdfh"
  end
    end

`

4

1 回答 1

0

Capybara 区分大小写,您的按钮可能是“创建潜在客户”而不是“创建潜在客户”(还应验证其他字段)

于 2013-10-10T20:20:29.680 回答