gpt4 book ai didi

ruby-on-rails - cucumber :从表中选择一个元素进行删除或添加

转载 作者:行者123 更新时间:2023-12-04 05:57:16 25 4
gpt4 key购买 nike

我正在使用 ruby​​ on rails 开发的应用程序中有下表:
alt text

我想在 cucumber 中创建一个测试,我从表中选择一个用户并删除或编辑它。

我不知道它的步骤定义是什么。

我希望能够执行以下操作:

Feature: User Manegement
In order to manage users
As an admin
I want to see a users list and change user properties

Background:
Given the following activated users exists
| name | email |
| Alice Hunter | alice.hunter@example.com |
| Bob Hunter | bob.hunter@example.com |
And the following user records
| name | email |
| Jonh Doe | jonh.doe@example.com |

Scenario: I delete a user from the table
Given I am logged in as admin
When I follow "Administration"
And I follow "User Management"
And I delete "Alice Hunter"
Then I should not see "Alice Hunter"`

任何人都可以帮忙吗?
谢谢你。

@布拉德

错误返回:
  wrong number of arguments (2 for 1) (ArgumentError)
./features/step_definitions/table_steps.rb:26:in `within'
./features/step_definitions/table_steps.rb:26:in `/^I delete "(.*)"$/'

最佳答案

经过一些广泛的搜索和小的重构,我设法解决了这个问题。

我使用了以下步骤:

When /^as admin I (press|follow|check|uncheck|choose) "([^\"]*)" for (.*) whose (.*) is "([^\"]*)"$/ do |action, whatyouclick, class_name, var_name, value|
unless var_name == "id" then
id = eval("\"#{class_name}\".classify.constantize.find_by_#{var_name}(\"#{value}\").id.to_s")
else
id = value
end
within("tr[id=as_admin__#{class_name}-list-#{id}-row]") do
case action
when "press"
click_button(whatyouclick)
when "follow"
click_link(whatyouclick)
when "check"
check(whatyouclick)
when "uncheck"
uncheck(whatyouclick)
when "choose"
uncheck(whatyouclick)
end
end
end

我也对 webrat 的 RDoc 很感兴趣,但我发现的一切似乎都乱七八糟。

关于ruby-on-rails - cucumber :从表中选择一个元素进行删除或添加,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4248889/

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