gpt4 book ai didi

ruby-on-rails-3 - 在 Cucumber 功能中使用 Factory Girl 步骤定义 (Rails 3)

转载 作者:行者123 更新时间:2023-12-04 09:37:26 25 4
gpt4 key购买 nike

我正在尝试使用 Cucumber 和 Factory Girl。以下几行:

  Given I am not logged in
And the following user exists:
| login | email | password | confirmation |
| user50 | user50@mydomain.com | secret50 | secret 50 |
....

引发以下错误:
Undefined step: "the following user exists:" (Cucumber::Undefined exception)
/home/user/RubymineProjects/project/features/sign_in.feature:9:in `And the following user exists:

You can implement step definitions for undefined steps with these snippets:
And /^the following user exists:$/ do |table|
# table is a Cucumber::Ast::Table
pending # express the regexp above with the code you wish you had
end

'

我已经安装了 factory_girl_rails(甚至 RubyMine 的代码完成功能也适用于 Factory Girl 步骤......)
#Gemfile
group :test do
gem "cucumber-rails", ">= 0.3.2"
gem "factory_girl_rails"
end

#features/support/env.rb
require 'factory_girl'
require 'factory_girl/step_definitions'

有任何想法吗?谢谢

更新:感谢@sj26 和@twmills,我意识到我忘了用 Factory Girl 创建一个 :user 工厂。一旦我创建了它,一切都运行良好。

最佳答案

对于那些现在尝试使用 FactoryGirl 助手的人:

从 FactoryGirl 3.5.0 开始,这些步骤助手在 4.0.0 中已弃用并删除:http://robots.thoughtbot.com/post/25650434584/writing-better-cucumber-scenarios-or-why-were

As of FactoryGirl 3.5.0, using any of FactoryGirl’s generated step definitions will print out a deprecation warning. We’ll be removing the step definitions completely in the 4.0.0 release of FactoryGirl in accordance with SemVer. I imagine the existing code will be extracted to a gem similar to Cucumber Rails’ training wheels with a nice warning urging developers not to use the the steps.



因此,如果您想在 Cucumber 中使用 FactoryGirl,您应该在您自己的步骤定义中使用它。

关于ruby-on-rails-3 - 在 Cucumber 功能中使用 Factory Girl 步骤定义 (Rails 3),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6045651/

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