Ruby on rails 当表单有文件\字段输入时,Capybara找不到字段
我的规格有一个很奇怪的问题。我有这样的表格:Ruby on rails 当表单有文件\字段输入时,Capybara找不到字段,ruby-on-rails,ruby,rspec,capybara,Ruby On Rails,Ruby,Rspec,Capybara,我的规格有一个很奇怪的问题。我有这样的表格: = simple_form_for [:admin, @provider] do |f| = f.input :provider_type_id = f.input :provider_username = f.input :first_name = f.input :last_name = f.input :athena_health_provider_id = f.input :display_name = f.inp
= simple_form_for [:admin, @provider] do |f|
= f.input :provider_type_id
= f.input :provider_username
= f.input :first_name
= f.input :last_name
= f.input :athena_health_provider_id
= f.input :display_name
= f.input :specialty
= f.input :entity_type
= f.input :home_department
= f.input :billable
= f.input :npi
= f.input :ansi_specialty_code
= f.input :ansi_name_code
= f.input :languages
= f.input :description
= f.input :photo, as: :file
= f.submit class: 'btn btn-primary'
require 'rails_helper'
feature 'Provider edit' do
let(:admin) { create(:user, :admin) }
let(:provider) { create(:provider) }
before do
login_as admin
visit edit_admin_provider_path(provider)
end
context 'when form is filled with invalid data' do
before do
fill_in 'First name', with: nil
click_button 'Update provider'
end
scenario 'redirects to :edit' do
expect(current_path).to eq admin_provider_path(provider)
end
scenario 'contains errors' do
expect(page).to have_text "can't be blank"
end
end
end
以及如下所示的功能规格:
= simple_form_for [:admin, @provider] do |f|
= f.input :provider_type_id
= f.input :provider_username
= f.input :first_name
= f.input :last_name
= f.input :athena_health_provider_id
= f.input :display_name
= f.input :specialty
= f.input :entity_type
= f.input :home_department
= f.input :billable
= f.input :npi
= f.input :ansi_specialty_code
= f.input :ansi_name_code
= f.input :languages
= f.input :description
= f.input :photo, as: :file
= f.submit class: 'btn btn-primary'
require 'rails_helper'
feature 'Provider edit' do
let(:admin) { create(:user, :admin) }
let(:provider) { create(:provider) }
before do
login_as admin
visit edit_admin_provider_path(provider)
end
context 'when form is filled with invalid data' do
before do
fill_in 'First name', with: nil
click_button 'Update provider'
end
scenario 'redirects to :edit' do
expect(current_path).to eq admin_provider_path(provider)
end
scenario 'contains errors' do
expect(page).to have_text "can't be blank"
end
end
end
这个规格不合格。Capybara没有用nil值更新名字输入。但当我将输入更改为:
= f.input :photo
一切正常。这是为什么?用“nil”填充某些内容很奇怪。你能试着用一个空字符串(例如“”)看看它是否有效吗?我试过了,但这不是解决方案…失败会导致什么错误?我想你应该使用
let!(:provider){create(:provider)}
您在水豚身上使用的驱动程序是什么?用“nil”填充某些内容非常奇怪。你能试着用一个空字符串(例如“”)看看它是否有效吗?我试过了,但这不是解决方案…失败会导致什么错误?我想你应该使用let!(:provider){create(:provider)}
您对Capybara使用的驱动程序是什么?