机械师 + RSpec 和保留字
我有一个蓝图:
Model.blueprint(:something) do
name "Some name"
context "some context"
end
“context”是Model的一个属性,但它也是RSpec的保留字。当我尝试 make 和 object 时,我在“context”行上收到 ArgumentError 。
有什么想法如何克服这种情况?
I have a blueprint:
Model.blueprint(:something) do
name "Some name"
context "some context"
end
"context" is an attribute of Model, but it is also a reserved word of RSpec. When I try to make and object I get ArgumentError on "context" line.
Any ideas how to overcome this situation?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
无法使用 Machinist 2.0.0.beta2 复制此内容。
Machinist 的工作方式是重写
method_missing?
,然后根据这些参数分配属性。如果 rspec 以某种方式将context
方法分配给 Machinist's Lathe 的对象,那么该方法将在method_missing?
之前调用。如果您仍然遇到此问题,您可以在评估属性之前尝试使用remove_method :context
:我无法判断这是否有效,因为我无法在本地复制它,但我会给出这是一个镜头。
Unable to replicate this with Machinist 2.0.0.beta2.
Machinist works by overriding
method_missing?
and then assigning attributes based on those arguments. If rspec is somehow assigning acontext
method to Machinist's Lathe's objects, then that method will be called beforemethod_missing?
. If you're still experiencing this problem, you could try usingremove_method :context
before evaluating attributes:I can't tell if that would work, as I can't replicate it locally, but I would give it a shot.