Categories

Links

Search

kvn.io

Notes on Web Development by Kevin Incorvia

Testing routes in isolated Rails Engines with RSpec

04/07/2013

One problem that you can run into when implementing a Rails Engine is hit or miss third party library support.  Even when a library does support engines (i.e. RSpec), because few people code in the context of them, documentation and online support can be few and far between.  When trying to test my mounted and isolated engine’s routes I quickly realized RSpec would produce failures because it was loading my main app’s routes into the tests instead of my engine’s.  It seemed like it should be an easy fix but none of the solutions I found online worked.

Only after a “bundle show rspec-rails” and diving into the code did I find the very easy but non-obvious hook that fixed everything.  Turns out this hook was only added recently to routing tests, is being added to controller tests as we speak, and documentation is certainly light.  To set the routes used in Routing Tests (and soon Controller tests) use this public API:

If you want to read up on the history of the this new feature, see these two commits:

    1. Routing specs can set their own routes
    2. Allow routing specs to access engine routes

You have no excuse to not use Slim

04/05/2013

I’m a huge fan of Slim Templates.  I admit I always liked the idea of HAML, but when I was told that the cognitive load of using HAML was a small but unnecessary burden on  front-end developers, I felt like a whiny kid who couldn’t play with his new toy.  ”But HAML takes minutes to learn!  How could something so easy, slow someone down?” I’d think to myself.

With Slim Templates I believe you have no excuses left.  Slim is so close to HTML it’s absurd. Plus the benefits you get of terseness and forced structure are huge, especially in a team setting.  Check out the comparison I made here where a snippet of ERB was converted to Slim by removing elements (in red) and adding elements (in green).

erb_vs_slim