为什么机械师对象不保存在嵌套块内?
这是我的规范代码不起作用:
require 'spec_helper'
describe User do
describe "blah" do
it "should save itself" do
user = User.make!
u = User.find user.id
user = User.make!
u = User.find user.id
end
end
end
规范在第二个 User.find 上失败,即使该用户对象有一个 id。
如果我删除“描述“blah”do”块,那么代码似乎可以正常工作。我正在使用机械师 2.0.0.beta2。
如果我在 test.rb 配置文件中禁用机械师缓存,它也可以工作:
Machinist.configure do |config|
config.cache_objects = false
end
有人知道我在这里做错了什么吗?在规范中嵌套多个描述是一种不好的做法吗?
谢谢
This is my spec code that isn't working:
require 'spec_helper'
describe User do
describe "blah" do
it "should save itself" do
user = User.make!
u = User.find user.id
user = User.make!
u = User.find user.id
end
end
end
The spec fails on the 2nd User.find even though that user object has an id.
If I remove the 'describe "blah" do' block then the code seems to work fine. I'm using machinist 2.0.0.beta2.
If I disable machinist caching in my test.rb config file it also works:
Machinist.configure do |config|
config.cache_objects = false
end
Anyone know what I'm doing wrong here? Is it a bad practice to nest multiple describes in a spec?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这也应该有效:
我在使用 Machinist 时总是遇到这个错误。我不认为它是嵌套描述所独有的,它似乎也会在其他情况下出现。真的希望他们能解决这个问题。它会导致看似随机的错误,而且很难追踪。
This should also work:
I run into this bug all the time using Machinist. I don't think it's exclusive to nesting describes, it seems pops up in other situations as well. Really wish they would fix this. It causes seemingly-random errors that are hard to track down.