-
Job Ad: Java Web Developer for Bezurk
We're on the lookout for a Java Web Developer (ad on Craigslist). I managed to get "Ruby on Rails" into the ad copy somewhere heh - it gets kinda lonely working in a development team of Java heads. Anyway, we're looking for a great Java developer to work with us in Singapore - if you're up for it, send us your resume. I would really like to get someone with some interest in Rails development to work together with on some upcoming (Rails) projects (you know, like after all the real work is done).
-
Excluding specific tests with rake
Sometimes, I just want to skip just that one test when I run my tests with
rake testbecause it takes much longer than other tests, and it gets in the way of rapid iterative cycles when coding. I looked around and haven't found a way to do that with rake, so I set down to writing a custom rake task.namespace :test do namespace :units do Rake::TestTask.new(:excluding => 'db:test:prepare') do |t| if ENV['THESE'] def t.file_list exclusion_patterns = ENV['THESE'].split(',') unit_tests = FileList['test/unit/**/*_test.rb'].select do |path| excluded = exclusion_patterns.select { |excl| /#{excl}/.match(path) } p "Excluding #{path}" if not excluded.empty? excluded.empty? end end else p 'Running all unit tests (specify THESE="pattern1, pattern2" to exclude files)' t.pattern = 'test/unit/**/*_test.rb' end t.libs << 'test' t.verbose = true end Rake::Task['test:units:excluding'].comment = 'Run unit tests with exclusions (specify exclusions with THESE="pattern1,pattern2")' end endOf course,
rake test:recentandrake test:uncommittedwould suffice for most purposes, but there are times when I just want to not run that a particular test or tests because they just take too long (and by definition, get in the way) and I'm pretty sure they won't be broken. (Always run all the tests before a commit though, don't be naughty.)You can run the task like this:
rake test:units:excluding THESE="item_test,atte\w*"Update: As it turns out, the task descriptions weren't being set correctly. Revision 5016 fixes this so
rake -Tshows the task descriptions properly. -
Some functional testing gotchas in Ruby on Rails
I've been writing lots of functional tests lately and came across several unexpected gotchas. Seeing as how forgetful I am recently, I'll jot them down here (and hopefully benefit anyone else who comes across the same problems).
Testing flash.now
Testing the contents of the flash.now, somewhat surprisingly, can't be done with code like this:
assert_equal 'Unable to activate your account.', flash.now[:error]flash.now[:error]would benil, in your functional test, and a quick lookup on Google brought me to HowToTestFlash.Now on the Rails wiki. Apparently, Rails renders the flash in the view and then proceeds to clear the contents of flash.now (so it isn't accessible in your functional test). So, you'd have to test the contents of the rendered page, instead of testing the flash itself:assert_tag :tag => 'div', :attributes => { :class => 'flash error' }, :content => 'Unable to activate your account.'Asserting cookies
This one's particularly annoying - trying to assert that cookies are set by your controllers. Unlike what was written in the Rails manual on testing (granted, it's rather well-known that the manuals are somewhat outdated), you cannot retrieve cookies using a Symbol as an index into the
cookieshash in your functional tests.cookies[:auth_token] = { :value => session[:user].remember_token, :expires => session[:user].remember_token_expires_at } assert cookies[:auth_token] # nil assert cookies['auth_token'] # This works.Thanks to Herry for pointing this out - it saved me an exercise in frustration.
Yet another cookie testing gotcha is testing for the deletion of cookies (example use case: deleting a users cookie after he logs out). So you may do this in your controller:
cookies.delete :auth_tokenAnd expect this to pass in your test:
assert_nil cookies['auth_token']But nope, instead of setting the cookie to
nil, the cookie is actually emptied.assert cookies['auth_token'].empty? # This works.I just used wrote my own custom assertion (there is an assert_cookie plugin around but I didn't think this justified adding another plugin to the application, not just yet):
def assert_no_cookie(cookie_name) cookies[cookie_name].nil? || cookies[cookie_name].empty? endUpdate: as it turns out,
assert_no_cookieandassert_cookie_equalsexist as custom assertions in ActionPack (source), but have been deprecated in favor of thecookiescollection. Still, looking up thecookiescollection with a Symbol but having it returnnilis unexpected behavior considering the inline documentation says it should work. -
From Typo to Mephisto
So with the usual fickle-mindedness, I've changed my blog software from Typo to Mephisto. Well, it wasn't so much based on a whim - there were some reasons I wanted to stop using Typo:
- For some reason, Typo is very unstable for me on my VPS with 160MB RAM. I deploy Typo on a mongrel_cluster of 2 mongrels, fronting it with Apache 2.2 + mod_proxy_balancer, and all 160MB RAM and 192MB of swap is used up whenever I post an article or sweep the cache. Comments also take noticeably longer to post on my blog than on other Typo blogs. I'm not sure what exactly I've done wrong.
- I often get an obscure NilClass error that screws up the front page whenever pages are regenerated (often caused by someone posting a comment or an article).
- Changing the blog's design requires one to create or edit an existing Typo theme - I kinda missed WordPress's Web-based template editing. This was a significant roadblock to me ever changing the look and feel of my Typo blog.
Coincidentally, my urge to swap to Mephisto coincided with the release of mephisto 0.6 (Immortus) just today, and after some minor hiccups, I managed to get Mephisto up and running with my articles imported from Typo. (Still couldn't get Capistrano to play well though, which I'm guessing is due to Rails version conflicts - I guess I'll just have to do with the release version.)
Documentation is rather sparse at the moment, especially on how to convert from Typo to Mephisto (I updated that wiki page while I was there). I dug around in Mephisto 0.6’s source and found the converters in vendor/plugins/mephisto_converter. Not sure if there is a web interface to this - either way, things worked almost perfectly just running this command:
script/runner "Mephisto.convert_from :typo" -e productionYou need to create a typo entry in database.yml that points to your existing Typo database. Also, the conversion will fail if any of your Typo users and email addresses are the same as the default Mephisto user admin. To avoid this just change the Mephisto user(s) login and email to something else.
So there's that, hopefully some time this year I'll update the look and feel.
-
Essential plugins for Trac
I've been setting up several Trac installations recently, and while Trac by itself is already pretty awesome (I love it's simplicity and functionality that doesn't get in the way), I was pretty dismayed to discover that administration isn't that great. Configuring Trac is a matter of (more) hacking at the command line with the trac-admin script, and user administration is managed with htpasswd or whatever authentication scheme that you choose (point being, you can't manage users via Trac itself).
Thankfully, there are some plugins that you can install to alleviate the situation. Trac itself publishes the WebAdmin plugin, which is slated for inclusion in Trac in Trac 0.11. This adds a web interface to trac-admin and it's pretty darned useful when used with two other plugins: Account Manager plugin and WebAdmin Users plugin.
Account Manager plugin adds HTML form-based login instead of the default HTTP authentication with plain olde Trac (plus user registration and changing of passwords). I'll let you in on a secret - I never managed to configure my Trac installs properly to use HTTP auth, but with this plugin it just worked.
The WebAdmin Users plugin let's you add/remove users via WebAdmin plugin.

By the way, if anyone has got a Linux binary for mod_dav_svn.so for Apache 2.2, let me know - I'm too lazy to go through the whole trouble of compiling it.
subscribe via RSS