trying add a feature - question about Jasmine usage in fulcrum

7 views
Skip to first unread message

Steven Talcott Smith

unread,
Jan 9, 2012, 5:54:39 AM1/9/12
to Fulcrum Devel
We were adding the created_at time to the view and I wanted to add a
view spec for it just to see how the view specs worked.

https://github.com/aelogica/fulcrum/commit/1f50c1c41523941873c833b07c839379d78cd050#L1R22

I am not very familiar with Jasmine but I noticed the Story "mock"
object in story_view.spec.js requires the created_at() function to be
added so it can be used in the view. It bothers me that we had to
copy the code from the story.js model into the view spec. Is this
necessary? Should it be done at all? Perhaps I am not using view
specs properly. Something is not right.

And advice or comments appreciated.

Steven

Malcolm Locke

unread,
Jan 11, 2012, 2:55:03 AM1/11/12
to fulcru...@googlegroups.com

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

Reply all
Reply to author
Forward
0 new messages