Gặp nhiều rắc rối khi nhận tất cả vịt theo đúng thứ tự với FactoryGirl.FactoryGirl: Nhà máy chưa đăng ký: người dùng (ArgumentError)
Thiết lập ứng dụng đường ray nhỏ gọn (3.0.11), factory_girl_rails (1.4.0), factory_girl (2.3.2) & dưa chuột-đường ray (1.2.1) và ruby-1.8.7-p352.
Các thử nghiệm dưa chuột là:
Feature: a
Scenario: test factory-girl
Given the following user exists:
| name | email |
| Brandon | [email protected] |
Kết quả là thế này:
cucumber
Using the default profile...
"Adam Advertiser"
"[email protected]"
#<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 | [email protected] |
**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
Có vẻ như một vấn đề trình tự tải, có thể. Sẽ đánh giá cao bất kỳ sự trợ giúp nào để có được quyền này. Trân Ross
tính năng/Factories.rb là như sau:
FactoryGirl.define do
factory :user do
name 'Adam Advertiser'
email '[email protected]'
end
end
pp FactoryGirl.create(:user)
require 'factory_girl/step_definitions'
My tính năng/support/env.rb là:
require 'pp'
require 'cucumber/rails'
require 'factory_girl_rails'
My GemFile là:
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
ở đâu? test_helper.rb? – Gerry
Trong câu hỏi, điều này nằm trong 'các tính năng/hỗ trợ/env.rb' ... – pagid