加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-17 04:28:32 所属栏目:百科 来源:网络整理
导读:我正在尝试使用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: "
我正在尝试使用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的用户工厂.一旦我创建它,一切都运作良好.

解决方法

对于那些现在尝试使用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,您应该在自己的步骤定义中使用它.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读