Testing ember with ember-rails

I was just wondering how others approach testing their ember apps when using ember-rails. I could write integration tests using Capybara with a headless webkit javascript driver like poltergeist. Ember App Kit uses Qunit + Ember Testing + Testem. I’m not sure if testing ember was intentionally omitted from the design of ember-rails. It seems strange that figuring out how to test ember applications with ember-rails is ambiguous since rails developers have a strong heritage of testing. Since ember-rails has generators for everything else, I would think that those generators would also generate accompanying tests as rails generators do.

Any suggestions would be welcome. I am just about at the point of forking ember-rails and writing some QUnit generators to try to match what ember app kit uses.

1 Like

After doing a bit of investigation, capybara + poltergeist (phantomjs driver for capybara), is not bad at all.

Here is a very basic capybara spec example: https://gist.github.com/mrinterweb/9014607

Are other people testing with Capybara and poltergeist?

I’ve just released a book today on the subject of Ember.js and testing with Rails.

You may find that useful.

I took the approach of using Teaspoon and QUint as I find it better to test My Ember code natively rather that driving it via Capybara. I also found it a bit difficult to work with the Ember run loop with Capybara which made testing in isolation difficult.

1 Like

Martin, thank you for that book. I just bought it. I am up to page 25, and so far the book is pure gold. I’m definitely going to take the approach of using teaspoon + QUnit for my testing.

I must admit that I feel a bit guilty. I’ve been underwhelmed with books I have purchased on leanpub in the past, so I only paid the minimum. Your book is a quick read at 63 pages (so far), but the content I’ve read so far is fantastic.

1 Like

Martin, does your book explain how to setup tests with the ember-cli style of apps with ES6 modules? I’m currently struggling with that and would happily buy your book if that’s the case.

@charles_demers, no, sorry, Ember CLI didn’t exist when I started writing. Because it’s aimed at Rails applications, we use Rails infrastructure to do all the heavy lifting.

Martin, that looks like an awesome book! I couldn’t see any direct mention of this on the product page - does your book cover Ember Data or are you using a different data library or a custom approach?

Hi @lookingsideways, yes Ember data is used for persistence management and does include relationships.

I’ve been on a bit of a pause recently as I’m swamped with other work, so haven’t updated it in a month or so. There are currently some issues relating to mocking HTTP requests (the library ‘fakehr’ doesn’t work since Ember 1.4) and the use of the Teaspoon gem (need to use specific version).

I do hope to get back into writing soon.

Cool. I went ahead and bought it anyway, it’s good to see some new learning material coming out!

Oh! Well thanks for that. I hope you find it useful and give me a yell if you need anything clarified.

I’m coding along with your book and on page 90 when I include the turnOnRESTAdapter function in the setup as described the tests just freeze. I guess that’s related to ‘fakehr’ not working?

Yes, you are correct. I’m looking at replacing fakehr with pretender (by the same author)

https://github.com/trek/pretender

[quote=“mfeckie, post:10, topic:4162, full:true”] Oh! Well thanks for that. I hope you find it useful and give me a yell if you need anything clarified. [/quote] - I bought the book and am enjoying going through it so far - is there a code repo (or even a zip file like the Pragmatic series uses) that customers have access to? If not, I think this might be a helpful accompaniment to the book.

I agree, it would be useful! DM me your email and I’ll share it with you.

@mfeckie - done, though I sent the message to you on another discourse powered forum (after a bit of Internet searching) due to this one not having private message buttons enabled on your profile…hope that’s ok and not alarming, I really wanted the code lol :wink:

Not sure why the PM button isn’t available for me! I can’t even find a place to enable it in the preferences. Anyhoo, I’ve replied to your email now :smile: