ibl*_*lue 1 ruby-on-rails factory-bot
在我看来,为了我的目的,factory_girl完全糟透了.一些限制包括:
如果我包含debugger语句,则将它们视为模型属性.我没有调用调试器,只是遇到了奇怪的错误.
FactoryGirl.define do
factory :admin do
name do
debugger # <-- Does not work.
Forgery(:name).full_name
end
email { Forgery(:email).address }
debugger # <-- Does not work either.
password "secret"
end
end
Run Code Online (Sandbox Code Playgroud)
我是太愚蠢还是没有优雅的方式来向用户添加两个帖子?
FactoryGirl.define do
factory :post do
title "Foobar"
content "Some content"
end
factory :user do
name { Forgery(:name).full_name }
email { Forgery(:email).address }
# This does not work, if the Post model requires Post#user to be set.
posts [FactoryGirl.create(:post), FactoryGirl.create(:post)]
end
end
Run Code Online (Sandbox Code Playgroud)
我无法记住发生的事情,但是工厂女孩经常出现奇怪的问题.
所以给出这些例子.有没有这些问题的factory_girl还有其他选择吗?
我同意并发现Factory Girl过于复杂.
我刚才写了一个更简单的宝石(当时至少)是基于工厂女孩的测试的替代品.
工厂定义使用更简单的Ruby,因此行为与您期望的一样.
看看:https: //github.com/ginty/cranky
| 归档时间: |
|
| 查看次数: |
1501 次 |
| 最近记录: |