RSpec raises this exception because it is useless to stub a method that does not exist in the source object.
Re-mixing methods are always error-prone, because the simulation may not behave like the original implementation, and therefore the specifications can be successful even if the original implementation would return an error (or even not exist). Allowing to simulate non-existent methods is simply wrong.
Therefore, I would say that you should not try to get around this exception. Just add the name method to your class that throws an explicit exception when running outside the test environment:
def self.name raise NoMethodError
source share