问题标签 [factory-bot]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
ruby-on-rails - 无法使用带有 Cucumber 和 rails 3 的工厂女孩(捆绑程序问题)
我正在尝试在新的 Rails 3 应用程序上运行带有工厂女孩工厂的黄瓜功能。
这是我的 Gemfile:
然后 bundle install commande 运行顺利:
当我运行黄瓜时,这是我得到的错误:
我是否必须为 bundler 做一些特别的事情才能在 github 上查看 factory girl 的存储库?
ruby-on-rails - Authlogic 和密码以及密码确认属性 - 无法访问?
我试图测试我在登录后成功创建了一个新用户(使用 authlogic)。我已经向用户添加了几个新字段,因此只想确保正确保存用户。
问题是尽管创建了一个有效的用户工厂,但每当我尝试获取其属性以发布到 create 方法时,密码和密码确认都会被忽略。我认为这是 authlogic 在后台执行的一种安全方法。这会导致验证失败和测试失败。
我想知道如何解决这个问题?我可以手动输入属性,但这似乎不是很干。
ruby-on-rails - 工厂女孩的额外论据
我需要将额外的参数传递给工厂女孩以在回调中使用。像这样的东西(但实际上更复杂):
然后用这样的东西创建它:
任何想法如何做到这一点?
ruby-on-rails - 工厂女孩什么时候在数据库中创建对象?
我正在尝试使用FactoryGirl
/模拟会话shoulda
(它与固定装置一起使用,但我在使用工厂时遇到问题)。我有以下工厂(用户登录和电子邮件都有unique
验证):
这是测试
但是当我跑步时rake test:functionals
,我得到了这个测试结果
这意味着当我在测试设置中引用它时,该记录已经存在于 db 中。这里有什么我不明白的吗?是否FactoryGirl
在启动时在 db 中创建所有工厂?
轨道 2.3.5/should/FactoryGirl
ruby-on-rails - 如何测试我的表格设计是否正确实现了我的关联?
我已经编写了我的基本模型并定义了它们的关联以及创建关联表的迁移。
编辑 - 强调我特别想测试的内容。
我希望能够测试:
- 关联按预期配置
- 表结构正确支持关联
我已经为我的所有模型编写了 FG 工厂,以期拥有一套完整的测试数据,但我无法掌握如何编写规范来测试 belongs_to 和 has_many 关联。
例如,给定一个拥有多个用户的组织,我希望能够测试我的示例组织是否引用了我的示例用户。
Organization_Factory.rb:
用户工厂.rb:
组织规范.rb:
此示例失败,因为 Organization.users 列表和比较 User :johnny 是同一工厂的不同实例。
我意识到这并没有遵循这些插件(FG,rspec)似乎适用的 BDD 想法,但是看到这是我的第一个 rails 应用程序,我不知道我已经配置了我的关联和表,我很不舒服继续前进结构合理。
ruby-on-rails - 使用带有 factory_girl 的固定装置
在建造以下工厂时:
ResumeType.first
返回nil,我得到一个错误。
ResumeType
记录是通过固定装置加载的。我使用控制台进行了检查,条目在那里,表不是空的。
我在 factory_girl 邮件列表中找到了一个类似的示例,它应该可以工作。
我错过了什么?在运行测试之前,我是否必须以某种方式告诉 factory_girl 设置固定装置?
这就是我的 test_helper 的样子:
ruby-on-rails - How do I setup and utilize Shoulda, Factory_Girl, and Cucumber in a Rails 3 application?
I'm able to get my Gemfile how I like it:
Then, of course, bundle install
From here, would someone be able to walk me through the process of generating a Cucumber scenario, creating a Factory, and then using the factory with Shoulda declarations inside a unit test? I've seen bits and pieces of all of these things scattered over blogs but due to the speed at which Rails3 is moving I am having a hard time finding a definitive source and my own forays have been unsuccessful and frustrating. Rather than providing my error messages I was hoping someone could just walk me through a clean-slate approach to show how it all works. This would probably be a good addition to http://guides.rails.info Testing section.
Perhaps the resource could be: bundle exec rails generate scaffold task description:string notes:text project_id:integer due:date complete:boolean
only using Cucumber of course.
Thank you so much on behalf of all of us still learning and trying to follow tdd/bdd!
ruby-on-rails - 以 factory_girl 命名的蓝图
我正在使用 Factory Girl 但喜欢机械师语法。所以我想知道,是否有任何方法为类创建命名蓝图,以便我可以拥有类似的东西:
有没有办法让 factory_girl 具有这样的机械师语法?我没有找到一个。帮助表示赞赏。
提前谢谢杰森
ruby-on-rails - 在 factory_girl 中填充与儿童的关联
我有一个Foo
has_many 'Bar' 的模型。我为这些对象中的每一个都有一个 factory_girl 工厂。Bar 的工厂与 Foo 有关联;它会在创建 Bar 时实例化一个 Foo。
我想要一个创建包含 Bar 的 Foo 的工厂。理想情况下,此 Bar 将通过 :bar 工厂创建,并尊重用于创建 Foo 的构建策略(创建/构建)。
我知道我可以调用 :bar 工厂,然后从新 Bar 中获取 Foo 引用。我想避免这种情况;在我的测试用例中,重要的对象是 Foo;调用酒吧工厂似乎有点迂回。此外,我可以看到需要具有多个 Bar 的 Foo。
这可能在 factory_girl 中吗?您如何在父级中定义这种关系?
ruby-on-rails - Rails 控制器使用 Shoulda、Factory Girl、Mocha 测试验证码
有人可以提供策略/代码示例/指针来测试 Captcha 验证 + Authlogic 使用 Shoulda、Factory Girl 和 Mocha 吗?
例如,我的 UsersController 类似于:
在这种情况下,您如何使用 Shoulda / Factory Girl / Mocha 模拟/存根来测试对验证码图像的有效和无效响应?
感谢您的帮助,湿婆