开发者

HAML-Fixtures with jasmine

Is it possible to use haml-fixtures in conjunction with jasmine-jquery?

I'm not really satisfied with having to create a lot of static html-fixtures because all of my views are written开发者_开发知识库 in haml. So not only would I have to create a lot of duplicate code but also I would have to rewrite the (already duplicate) code to HTML. Double pain.

Any suggestions? Best practices? Anybody worked with jasmine-jquery and fixtures so far?


Yep. There are 3 paths I know about:

  1. Create fixtures manually like you are doing now. This can feel like duplicate code. The pros are that it's pretty simple (and intuitive as lots of people start out that way). Longer term I think it's good if it helps you reduce the coupling between your markup and your jQuery scripts. I found that using this technique encouraged me to figure out the simplest markup required for my jQuery code.

  2. This is probably the answer you're looking for. Generated fixtures from your haml templates. This blog post will walk you through one method, but the google can show you some more. This is nice because you're guaranteed that the haml code and JS is in sync. The down-side is that it's some complexity that can-- and does-- go wrong.

  3. All my recent projects have gone further and eliminated all but a very basic dependence on the generated markup. My templates generally output a single <div> along with some data attributes on the page, and the Javascript builds all the DOM elements for me (instead of haml). Javascript based templates facilitate this. The Jasmine tests are quite simple, and the testing can usually be done sans fixtures, using var $dom = $('<div>'); as the whole fixture. If you are going to have to deal with the data on the client anyways, this, I find, is overall simpler.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜