gpt4 book ai didi

rspec - Capybara click_button 不会去创建 Action

转载 作者:行者123 更新时间:2023-12-01 06:44:49 26 4
gpt4 key购买 nike

我有一个这样定义的测试:

    it "should have allow you to fill out the new form and save a customer" do
customer = Factory.build(:customer)
visit new_customer_path
factory_to_form "customer", customer, ["kf_code", "supported"]
click_button "customer_submit"
current_path.should eq(customer_path(Customer.last))
page.should have_content "created customer"
page.should have_content customer.long_name
end

它非常简单,将客户设置为我的客户工厂,然后使用来自该工厂的数据(我的 factory_to_form 宏所做的)填写新的操作表单,然后单击提交按钮。

我的问题是提交按钮似乎永远不会触及创建操作,它会转到“/customers”而不是保存客户。

表格是标准的 form_for(@customer)而按钮只是 f.submit ,我想不出任何原因为什么这个表单可以在浏览器中正常工作,但在这个测试中却不能。

为什么 capybara 不会发布到正确的地方?

最佳答案

是否涉及任何 JavaScript?也许尝试使用像 Webkit 这样的驱动程序。

setup do
Capybara.javascript_driver = :webkit
Capybara.current_driver = Capybara.javascript_driver
end

关于rspec - Capybara click_button 不会去创建 Action ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6748555/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com