Capybara选择下拉

时间:2014-04-18 06:41:36

标签: ruby-on-rails capybara factory-bot

我正在学习单元测试,当涉及到Capybara的选择选项时,我有点迷失。有人可以解释我如何让工厂女孩通过这项测试。

项目特征规范

require 'spec_helper'   
describe 'create project creation' do   

  it 'allows user to create a project' do
    visit projects_path
    click_link 'Create Project'

    fill_in 'Title', with: 'Secklow Sounds'
    fill_in 'Description', with: 'This is the project description'
    select('Jane', :from => 'Client')
    select('Mike', :from => 'Client Assistant')
    select('active', from: 'Status')
    fill_in 'Budget', with: '200'
    fill_in 'Start date', with: '24 January 2013'
    fill_in 'Deadline', with: '24 January 2014'

    click_button 'Create Project'

    expect(page).to have_content('Project was successfully created.')

  end  
end

工厂女孩

FactoryGirl.define do
  factory :project do
    title "MyString"
    description "MyText"
    status 1
    budget "9.99"
    user_id 1
    assistant_id 1
    start_date "2014-04-17"
    deadline "2014-04-17"
    slug "MyString"
  end
end

我的问题是如何在运行测试时出现错误时让它们一起工作

Failures:

  1) create project creation allows user to create a project
     Failure/Error: select('Jane', :from => 'Client')
     Capybara::ElementNotFound:
       Unable to find option "Jane"
     # ./spec/features/project_feature_spec.rb:13:in `block (2 levels) in <top (required)>'

修改

我的表单

= simple_form_for(@project, :defaults => { :wrapper_html => {:class => 'form-group'}, :input_html => { :class => 'form-control', :role => 'form' } }) do |f|

  .form-inputs
    = f.input :title
    = f.input :description
    .row
      .col-md-2
        = f.association :user, label: 'Client'
      .col-md-2
        = f.association :assistant, label: 'Client Assistant'
      .col-md-2
        = f.input :status, collection: %w{ pending active completed suspended funding  }, include_blank: false
      .col-md-2
        %br
        .input-group
          %span.input-group-addon €
          = f.input_field :budget, class: 'form-control', label: true
    .row
      .col-md-2
        = f.input :start_date, as: :string, placeholder: '23 February 2014'
      .col-md-2
        = f.input :deadline, as: :string, placeholder: '16 March 2014'

  .form-actions
    = f.button :submit, class: 'btn'

0 个答案:

没有答案
相关问题