The idea is that each unit is tested in isolation, so you don't actually
care about the implementation of the Story model when testing the
StoryView, or even what it returns.
All you care about is:
- The view calls this.model.created_at()
- Whatever is returned from that call gets added correctly to the DOM
Personally, I would just create a method that returns a static string:
created_at: function() { return "19 Sep 2011, 2:25pm"; }
You could also use a Sinon stub to the same effect:
created_at: sinon.stub().returns("19 Sep 2011, 2:25pm")
Although I'd probably use the former in this case. I'd only use the
stub for more complex cases, for example when I wanted to check how many
times the method was called and with what arguments, etc.
You would also be able to remove created_at from the initialisation
attributes for this.story and this.new_story again.
This also means that the implementation and output of Story.created_at()
can change and it won't require any modifications of the StoryView
specs.
Hope that makes sense!
Malc