18 Sep 2009
I spent some time today creating a Rails application template. As well as performing some general file cleanup, it pulls in the following tools:
I added a prompt for pulling in jQuery and provide an option for specifying the jQuery version. I also provide a bare-bones application layout file and reset browser styles with YUI reset.css. Finally, the whole thing is added to a git repo and the initial commit is made.
The source can be found here.
This tool has been out for a while and I’m impressed with its power; I wish I would’ve done this sooner. Specifically, I’m impressed with the powerful gem command; the :env option allows you to restrict gems to a specific environment. Best of all are the interactive prompt commands:
no?. Using these allowed me to customize the inclusion and version of jQuery for the generated app. Cool stuff.
Further Learning Resources
- Jeremy McAnally’s rails-templates repository
- Railscast on App Templates
- “Don’t Repeat Yourself. Use Rails Templates”
07 Sep 2009
26 Jan 2009
I heart assert_select. But when we’re testing helpers using
ActionView::TestCase, we don’t have a response object available, and assert_select is usually used in the context of a response object. So you might think you can just pass a string of html to assert_select, but unfortunately that doesn’t work. So what’s a Rails developer to do?
You could use regular expressions. You could also vomit on your monitor and stab yourself in the eye. Luckily, there are a couple alternatives.
RSpec. I’m not really an RSpec guy, but it apparently does have support for testing html from helpers.
The helper_me_test plugin from Brian Landau of Viget Labs seems like an elegant and flexible alternative. It takes advantage of the fact that assert_select accepts an optional
HTML::Node object as its first argument. I definitely recommend taking a look at that plugin, especially if you prefer hpricot. The plugin seems to have been spawned as a consequence of this thread on the Rails Lighthouse.
Ultimately I’ve chosen to write something custom, but really lightweight, which involves simply opening the
String class and adding a to_node method that returns the string as an
HTML::Node. I’ve gisted an example. It’s not as elegant as helper_me_test, but it’s so little code that I’ve decided it’s best for the particular app I’m working on.
Hopefully this helps someone.