Rather than needing this `name_for` method, I think you could make the `inject` call above build up the const-name-so-far as it goes along. `name_for` feels like it's duplicating that work a bit.  Something like this:

``` ruby
@parent, _ = @context_parts.inject([Object, '']) do |(context, parent_name), part_name|
  full_name = parent_name + '::' + part_name

  module = if const_defined_on?(context, part_name)
    get_const_defined_on(context, part_name)
  else
    ConstantMutator.stub(full_name, Module.new)
  end

  [module, full_name]
end
```

Hmm, maybe that's not actually better.  Injecting two things is a bit weird/non-standard.  I'll leave it here anyway though.