Factory_Girl 耙子问题
我正在使用 Cucumber、Devise 和 Factory_Girl 创建一个新的 Rails 3.1 应用程序。我成功安装了 Devise 和 Cucumber。然后,我创建了包含以下内容的spec/factories.rb文件:
require 'factory_girl'
Factory.define :user do |user|
user.name 'Test User'
user.email '[email protected]'
user.password' testpass'
end
我还添加了spec/support/devise.rb以添加Devise的测试挂钩:
RSpec.configure do |config|
config.include Devise::TestHelpers, :type => :controller
end
关于测试,我没有触及任何其他内容,现在每次运行任何 rake 命令我都会得到以下信息(在这种情况下我运行了 rake spec,只是为了确保一切都准备好进行测试):
rake aborted!
Factory already registered: user
Tasks: TOP => spec => db:test:prepare => db:abort_if_pending_migrations => environment
(See full trace by running task with --trace)
现在,如果我从工厂文件中删除 Factory.define 块,它运行正常。我做了一些谷歌搜索,但一无所获。既然说工厂已经注册,那么Devise是否出于某种原因已经创建了工厂?
I'm creating a new Rails 3.1 application using Cucumber, Devise, and Factory_Girl. I installed successfully Devise and Cucumber. I then created the spec/factories.rb file that contains the following:
require 'factory_girl'
Factory.define :user do |user|
user.name 'Test User'
user.email '[email protected]'
user.password' testpass'
end
I also added spec/support/devise.rb to add in the test hooks for Devise:
RSpec.configure do |config|
config.include Devise::TestHelpers, :type => :controller
end
In regards to testing, I have not touched anything else and now everytime I run any rake command I get the following (I ran rake spec in this case, just to make sure everything is ready for tests):
rake aborted!
Factory already registered: user
Tasks: TOP => spec => db:test:prepare => db:abort_if_pending_migrations => environment
(See full trace by running task with --trace)
Now if I remove the Factory.define block from the factories file, it runs fine. I've done some Google searching and have come up with absolutely nothing. Since it's saying the Factory is already registered, is Devise for whatever reason, creating a factory already?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论