0
我有一个生成的表单为什么在匹配/ id = “MyId ”/通过时,has_selector“#MyId”失败?
#helpers/my_helper.rb
def build_form
form_for object, url: object_path, method: :post do |f|
html = f.text_input :field
html += f.submit
html.html_safe
end
end
而且测试这个助手
#spec/helpers/my_helper_spec.rb
describe MyHelper do
it { expect(helper.my_helper).to have_selector "form[action='#{objects_path}'][method='post']" } # PASSES
it { expect(helper.my_helper).to have_selector "#object_field" } #FAILS - but this should pass
it { expect(helper.my_helper).to match /id=\"object_field\"/ } # PASSES
end
我仍然在学习rspec的一个轨道帮手,所以这可能是一个明显的问题。
为什么在输入上使用have_selector
时这些测试失败。然而have_selector
正确地传递了窗体标签,并且match
传递了输入ID。
尝试使用has_selector:css,“#object_field” –
你看过你的帮助程序返回的实际字符串吗? –
谢谢@FrederickCheung,是的,该字符串包含所有元素和窗体呈现预期。我无法让匹配器按照预期行事。 –