gpt4 book ai didi

ruby - 工厂女郎 : Factory not registered: user (ArgumentError)

转载 作者:数据小太阳 更新时间:2023-10-29 06:36:24 24 4
gpt4 key购买 nike

在使用 FactoryGirl 将所有鸭子按正确顺序排列时遇到很多麻烦。

设置极简 Rails 应用程序 (3.0.11)、factory_girl_rails (1.4.0)、factory_girl (2.3.2) & cucumber-rails (1.2.1) 和 ruby​​-1.8.7-p352。

cucumber 测试是:

Feature: a
Scenario: test factory-girl
Given the following user exists:
| name | email |
| Brandon | brandon@example.com |

结果是这样的:

cucumber 
Using the default profile...
"Adam Advertiser"
"a@b.com"
#<User id: nil, name: nil, created_at: nil, updated_at: nil, email: nil>
Feature: a

Scenario: test factory-girl # features/users.feature:2
Given the following user exists: # factory_girl-2.3.2/lib/factory_girl/step_definitions.rb:100
| name | email |
| Brandon | brandon@example.com |
**Factory not registered: user (ArgumentError)**
features/users.feature:3:in `Given the following user exists:'

Failing Scenarios:
cucumber features/users.feature:2 # Scenario: test factory-girl

1 scenario (1 failed)
1 step (1 failed)
0m0.107s

这似乎是一个加载顺序问题,也许吧。将不胜感激任何帮助,以做到这一点。问候罗斯

features/Factories.rb 因此:

FactoryGirl.define do
factory :user do
name 'Adam Advertiser'
email 'a@b.com'
end
end
pp FactoryGirl.create(:user)

require 'factory_girl/step_definitions'

我的 features/support/env.rb 是:

require 'pp'
require 'cucumber/rails'

require 'factory_girl_rails'

我的 GemFile 是:

source 'http://rubygems.org'

gem 'rails', '3.0.11'

gem 'sqlite3'


group :development, :test do

gem 'cucumber-rails'
gem 'factory_girl_rails' # rails 3 version

end

最佳答案

require 'factory_girl_rails' 之后立即调用 FactoryGirl.find_definitions 为我解决了类似的问题。

参见 Cannot get factory_girl running under rails 3.0.5,unexpected tCONSTANT

关于ruby - 工厂女郎 : Factory not registered: user (ArgumentError),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8409787/

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