Capybara and Poltergeist with RSpec


capybara

I used to think cucumber for Rails is a little bit over kill for the developer. Because every time you have to write a lot of regular expression to work it out. But in the recently project, we use Capybara and poltergeist with RSpec to solve this problem. It even can test your SPA and integrate with CI very nicely.

Poltergeist is a driver for Capybara. It allows you to run your Capybara tests on a headless WebKit browser, provided by PhantomJS. So, what is headless? That means you don’t need to fire up your browser. What’s that mean? Fast!!

  • Poltergeist is a wrapper for PhantomJS, so make sure your test env have that. If not brew install phantomjs in Mac.
  • Travis CI and codeship has PhantomJS pre-installed.

Codeship


codeship logo

Nowaday, all the code should be tested before shipped. But we are all human being, we make mistakes. Sometime you are thinking just one line of code, not a big deal, just push it. Unfortunately, that line of code cause errors. So, we need something to automate test our codes after we pushed it to verify our code pass all the test case or not. That’s why CI introduced.

And for CI, in my option, there are two kinds right now, one is Jenkins with docker(more manual) and one is Codeship/travis-ci(more automated).

Data Association with FactoryGirl

If you ever work with Rails and TDD, you may hear Factory girl: a great data mock gem to replace fixture. But sometime when your modal have some association with other modals, and that model have other associations, try to write a factory with callback (after build/create) become so hard. But thanks to thoughtbot, factory girl have data association build-in. You can read this post.