-6ren">
gpt4 book ai didi

ruby-on-rails - 使用 Capybara 发送表单时会添加换行符

转载 作者:数据小太阳 更新时间:2023-10-29 07:19:54 25 4
gpt4 key购买 nike

我在 Rails 应用程序中使用 Capybara 进行了此测试:

within "#register" do
fill_in "Biography (optionnal)", :with => "Hello world!"
end

click_on "Save"

# Check that form is repopulated with old input
expect(find_field('user_bio').value).to eq('Hello world!')

这是我从测试中得到的:

Failure/Error: expect(find_field('user_bio').value).to eq('Hello world!')   
expected: "Hello world!"
got: "\nHello world!"

我从来没有手动在 user_bio 字段前添加换行符。

这可能来自哪里?

编辑 1:在谷歌搜索之后,Github 上似乎有一个 PR,它被合并了。所以我想这不是 Capybara 的错误。参见 https://github.com/jnicklas/capybara/commit/755a724d4b10e6841a0eeb58af43375236b33247

最佳答案

你可以在保存之前做一个过滤器来清除新行

在你的模型中添加

 before_save :clear_new_lines

protected
def clear_new_lines
self.user_bio = user_bio.gsub("\n",'')
end

关于ruby-on-rails - 使用 Capybara 发送表单时会添加换行符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15347779/

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