instances of classes that `include Adamantium` have their singleton classes frozen
misfo opened this issue · comments
Here's a minimal case:
p RUBY_VERSION #=> "2.0.0"
require 'adamantium'
require 'adamantium/version' # not required by default, oops!
p Adamantium::VERSION #=> "0.1.0"
class Something
include Adamantium
end
p Something.new.singleton_class.frozen? #=> true
This prevents Rspec from being able to mock methods on these instances
It turns out this is a more general problem with Object#freeze
:
obj = Object.new
obj.singleton_class.frozen?
#=> false
obj.freeze
obj.singleton_class.frozen?
#=> true
There has to be a way to mock methods on frozen objects though...
@misfo I typically do not mock methods on a "random" object anymore. The ROM development style leads to very "small" public interface objects, so I generally pass a full instance in, or in rare cases a full mock. But no need to mock one of many methods if an instance.