Reputation: 616
I frequently use OCMock with the excellent OCHamcrest matchers. But I often encounter test failure messages that aren't as helpful as they could be. This is because the OCHamcrest output relies heavily on the value returned by the "description" method of objects but OCMockObject's default description implementation is very generic.
Is there a recommended way to have mock objects return a custom description?
I've tried stubbing the "description" method on my mock objects but that doesn't seem to work.
As a workaround I've created a OCClassMockObject+Description
category extension that adds a setMockDescription:
method, but I'm hoping there's a more officially supported solution. (If not, maybe I'll polish mine up and submit a pull request.)
Here are examples of some of the results I'd like to improve...
assertThat(recommendedSong, is(mockSong1));
Expected <OCMockObject[SongBar]>, but was <OCMockObject[SongBar]>
assertThat(playlist.songs, contains(mockSong1, mockSong2, nil));
Expected a collection containing [<OCMockObject[SongBar]>, <OCMockObject[SongBar]>], but item 0: was <OCMockObject[SongBar]>
Upvotes: 1
Views: 130