A Puzzle for Polite Ruby Programmers

I really enjoyed Jim Weirich’s session on polite programming at the Scottish Ruby Conference. He covered a problem that’s been vexing me for some time, about avoiding the use of method aliasing, by using inheritance instead. Unfortunately, his suggested solution didn’t tell me anything I hadn’t already tried. I still think this must be possible, […]

Two Truths I’ve Learned About Writing Clean Rails Apps

In summary: Implement every feature without javascript first, add javascript as a progressive enhancement Stick to REST. Always. Now I’m as suspicious of absolute rules as you probably are, but these two have served me extremely well in keeping my Rails code clean and easy to maintain. I’m happy to push the boat out and […]

Using Capybara with RSpec Outside Cucumber

If you want to try using Capybara for browser automation on it’s own, here’s a simple script to get you started: require ‘rubygems’ require ‘capybara’ require ‘capybara/dsl’ Capybara.default_driver = :selenium Capybara.app_host = “http://www.google.com” require “rspec/expectations” class Google include Capybara include RSpec::Matchers def search_for(text) visit “/” fill_in “q”, :with => text click_button “Search” end def ensure_results_contain(expected_text) […]

Installing Ruby Gems with Native Extensions on Windows

If you’re stuck trying to run Ruby on Windows, one barrier you might have encountered is in trying to install a gem like ruby-debug or rdiscount. You’ll have seen an error like this: %gem install ruby-debug Building native extensions. This could take a while… ERROR: Error installing ruby-debug: ERROR: Failed to build gem native extension. […]

Fix RubyMine 2.02 Cucumber Integration

If you’re using the latest version of RubyMine (2.0.2) with the latest version of Cucumber (actually anything above 0.7), you’ll probably see this ugly warning when you try to run your cukes from within the IDE: The bug has been logged, and there’s a published workaround, but I wanted something a bit easier to use. […]

MegaMutex: A Distributed Mutex for Ruby

Sometimes I need to do this: unless enough_widgets? make_more_widgets end Which is all well and good, until I start letting two or more of these codes run in parallel. If you’ve never thought about this before, what can happen is something nasty called a race condition, where two or more processes (or threads) simultaneously check […]

PartialDebugger Plug-in for Rails

Ever look at the HTML output from an old project and wonder which the hell partial rendered which the heck bit of the HTML? Wonder no more. ./script/plugin install git://github.com/mattwynne/partial_debugger.git Then add this to your config/environments/development.rb PartialDebugger.enable …because you probably don’t want this running in production.

Rails Tip: Use Polymorphism to Extend your Controllers at Runtime

Metaprogramming in Ruby comes in for quite a bit of stick at times, the accusation being that code which modifies itself at runtime can be hard to understand. As Martin Fowler recently described, there’s a sweet spot where you use just enough to get some of the incredible benefits that Ruby offers, without leaving behind […]

Goodbye CruiseControl.rb, Hello Hudson

Imagine you have a friend who writes a blog. Maybe you actually do. Let’s call him ‘Chump’. One day you’re chatting, and the conversation turns to technology. It turns out that Chump is using Dreamweaver to write his blog entries, and manually uploading them to his site via FTP. You’re appalled. How do you update […]