gpt4 book ai didi

ruby-on-rails - 晒干萝卜步骤定义

转载 作者:行者123 更新时间:2023-11-28 20:15:59 25 4
gpt4 key购买 nike

我知道这可以通过捕获可选组来使用 cucumber (参见此处的 tip 3),并且我在萝卜中工作,但我不喜欢这个解决方案。

我正在尝试消除多个步骤,这些步骤只是彼此的积极/消极。

所以不是这样的 2 个步骤:

step "I should see :content in the footer" do |content|
within(".footer-main") do
page.should(have_selector("h3", text: content))
end
end

step "I should not see :content in the footer" do |content|
within(".footer-main") do
page.should_not(have_selector("h3", text: content))
end
end

我能做到:

step "I should :not_text see :content in the footer" do |not_text, content|
within(".footer-main") do
not_text.blank? ? page.should(have_selector("h3", text: content)) : page.should_not(have_selector("h3", text: content))
end
end

这工作正常,但我真正不喜欢的是我必须像这样在积极的情况下放置空括号:

Scenario: User should see Company in the footer
When I visit the "root page"
Then I should "" see "Company" in the footer

有更好的方法吗?

最佳答案

如何使用以下步骤定义:

step "I :should_or_not_text see :content in the footer" do |should_or_not_text, content|
within(".footer-main") do
should_or_not_text == "should" ? page.should(have_selector("h3", text: content)) : page.should_not(have_selector("h3", text: content))
end
end

然后该功能看起来更干净一点:

Scenario: User should see Company in the footer
When I visit the "root page"
Then I "should" see "Company" in the footer

关于ruby-on-rails - 晒干萝卜步骤定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11235340/

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