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

前端之家收集整理的这篇文章主要介绍了ruby-on-rails-3 – 在Cucumber功能中使用Factory Girl步骤定义(Rails 3)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试使用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,您应该在自己的步骤定义中使用它.

原文链接:https://www.f2er.com/ruby/269043.html

猜你在找的Ruby相关文章