简体   繁体   中英

Machinist + RSpec and reserved words

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?

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 a context method to Machinist's Lathe's objects, then that method will be called before method_missing? . If you're still experiencing this problem, you could try using remove_method :context before evaluating attributes:

Model.blueprint(:something) do
  remove_method :context
  name "Some name"
  context "some context"
  alias_method :context, :describe
end

I can't tell if that would work, as I can't replicate it locally, but I would give it a shot.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM