causes the mock trainwreck, and this assessor can be mocked easily. Dependency injection Dependency injection (DI), the process by which a dependency is passed to the client which will use it, can be used to soften the trainwreck. One method of DI that is easy to use is a location object to reduce the complexity of building the mock object. Below is the example above reworked with a DI build_mock method to help set mock values on dependent objects. While for this simple example it doesn't appear to help much, in a more complicated scenario it could reduce complexity in manually setting the values. def build_mock(name, map, locator, refs) obj = mock(name, map) refs.each do |ref| obj.send("#{ref}=", locator[ref.to_sym]) end obj end locator = {} locator[:HeadLibrarian] = mock('HeadLibrarian', :name => 'Jane Smith') locator[:Funding] = mock('Funding', :type => 'public') locator[:Library] = build_mock('Library', {}, locator, ['HeadLibrarian', 'Funding']) Libraries Mockito Testing library in various languages can make the mock trainwreck easier to navigate with helpers. An example is Mockito that provides annotations to assist in injecting mocks into objects. Using the @InjectMocks annotation and @Mock annotation, when Mockito initializes all the mocks it will inject Library with the mocks for funding and head librarian.public class LibraryTester { @Mock HeadLibrarian h; @Mock Funding f; @InjectMocks Library l; @Before public void initMocks() { MockitoAnnotations.initMocks(this); } @Test public void testLibrary() { when(l.getHeadLibrarian().getName()).thenReturn("Jane Smith"); when(l.getFunding().getType()).thenReturn("public"); //tests here } } Demeter The use of libraries can also be used to address mock trainwreck. One such library is called demeter, and it can be used to provide Law of Demeter duck typing assessors that automatically creates assessors for single level nested models. By using this library, a person can mock the assessors that their code uses of the child function, as seen in the example below. require "demeter" class Library extend Demeter demeter :HeadLibrarian demeter :Funding def initialize @HeadLibrarian = HeadLibrarian.new @Funding = Funding.new end end l = mock('Library', :HeadLibrarian_name => 'Jane Smith', :Funding.type => 'public') l.HeadLibrarian_name #Jane Smith References Unit testing