【发布时间】:2017-02-23 22:02:49
【问题描述】:
我正在为视图编写 RSpec 测试,并在尝试填写文本字段时收到以下错误。
1) coordinators/new.html.erb populate page name text entry field filled checks for presence of filled in text field
Failure/Error: fill_in "coordinator_name", with: 'JoeJoe'
Capybara::ElementNotFound:
Unable to find field "coordinator_name"
# ./spec/views/coordinators/new.html.erb_spec.rb:47:in `block (4 levels) in <top (required)>'
这是我的代码的一部分,包括前面找到“coordinator_name”字段的测试。我很困惑为什么在第二次测试中没有找到它?
describe 'name text entry field' do
it 'checks for presence of empty text field for name' do
expect(rendered).to have_field('coordinator_name', text: nil)
end
end
describe 'name text entry field filled' do
it 'checks for presence of filled in text field' do
fill_in "coordinator_name", with: 'JoeJoe'
expect(rendered).to have_field('coordinator_name', text: 'JoeJoe')
end
end
关于如何找到解决方案的任何建议?
【问题讨论】:
-
您的测试代码显示您将
:text选项传递给 has_field -- 如果您尝试测试的值,have_field 不采用:text选项它采用:with选项字段,又是什么rendered? - 没关系,我知道你做错了什么。 -
@KevinEtore 这是一个空文件(没有 html)。但是,当我将 save_and_open_page 用于“检查名称是否存在空文本字段”测试时,也会发生同样的事情(一个空页面)
标签: ruby-on-rails rspec capybara rspec-rails