【问题标题】:Setting up factory girl with cucumber and rails 3用黄瓜和铁轨建立工厂女孩 3
【发布时间】:2011-01-22 00:22:33
【问题描述】:

我正在尝试使用 rails 3 设置工厂女孩,但是当我 rake cucumber 时出现此错误:

james@james-laptop:~/rails-projs/simple-beach-63$ rake cucumber:wip
(in /home/james/rails-projs/simple-beach-63)
bundle exec /usr/bin/ruby1.8 -I "/usr/lib/ruby/gems/1.8/gems/cucumber-0.9.4/lib:lib"

"/usr/lib/ruby/gems/1.8/gems/cucumber-0.9.4/bin/cucumber" --profile wip 使用 wip 配置文件... 未初始化的常量工厂 (NameError) /usr/lib/ruby/gems/1.8/gems/rspec-expectations-2.1.0/lib/rspec/expectations/backward_compatibility.rb:6:in const_missing' /usr/lib/ruby/gems/1.8/gems/factory_girl-1.3.3/lib/factory_girl/step_definitions.rb:25 /home/james/rails-projs/simple-beach-63/features/support/env.rb:8:inrequire' /home/james/rails-projs/simple-beach-63/features/support/env.rb:8

一秒能拉过来看看吗?

我在 Gemfile 中有这个:

gem 'factory_girl_rails'
gem 'factory_girl'

我在 feature/support/env.rb 中有这个

require "factory_girl/step_definitions"
require "factory_girl"
require File.dirname(__FILE__) + "/factories"

然后我在 features/support/factories.rb 中定义了一个工厂

感谢您的帮助

【问题讨论】:

  • 如果你使用 factory_girl_rails gem 会发生什么?

标签: ruby-on-rails ruby-on-rails-3 cucumber factory-bot


【解决方案1】:

您应该只需要这些步骤。

宝石文件:

group :development, :test do
  gem "rspec-rails"
end

group :test do
  gem "cucumber-rails"
  gem "factory_girl_rails"
end

功能/支持/factory_girl.rb:

require 'factory_girl/step_definitions'

spec/factories.rb:

# your Factory definitions.

【讨论】:

    【解决方案2】:

    丹,

    我已按照您的步骤操作,但我仍然无法使用工厂女孩步骤定义。

    当我尝试时:

      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)
    
    You can implement step definitions for undefined steps with these snippets:
    Given /^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
    

    关于缺少什么的任何想法?

    【讨论】:

    • 您需要首先在 features/support/factory_girl.rb 中 require 'factory_girl_rails',因为步骤定义是从您的工厂生成的。
    【解决方案3】:

    这里的问题是您没有正确调用您的表。从您的功能文件中调用该表的行应如下所示:

    And the following user with <login> and <email> <password> and <confirmation> exists
    

    您的步骤定义应如下所示:

    And /^The following user with ([A-za-z0-9\.@:]+) and ([A-za-z0-9\.@:]+) ([A-za-z0-9\.@:]+) and ([A-za-z0-9\.@:]+) exists$/ do |login, email, password, confirmation|
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多