Monday, October 31, 2011

Forcing the system update command for ruby gems on Ubuntu 11.04

If you try run Ruby Gem's command to update itself ($ sudo gem update --system) on Ubuntu you get a pretty stern warning that it's not recommended, and you might have issues blah blah blah.

There's a bunch of gems which complain if your gem version is out of date (and the default version with Ubuntu is), and I don't know when the official package will be updated.

Just so I know for next time, the command to force it to upgrade (at your own risk) is:
$ sudo REALLY_GEM_UPDATE_SYSTEM=1 gem update --system

I haven't had any problems from this on 11.04, but as always YMMV.

Sunday, October 30, 2011

Getting VCR to work with Rspec

I'm writing an SOAP API wrapper in Ruby, and there's no test system to use during development. Being about to use something like VCR to record the request/response from the service is great, because I can do it a controlled fashion the first time (and record it), and then do stupid things to it without getting in to trouble. It also helps my features and tests run much faster than if I had to actually ping the server every time.

I found Cucumber and VCR's official documentation good, but over-complicated for what I wanted to do. Here are the steps it actually took me to get it working quickly and simply in my features (using fakeweb).
  1. Create the file 'features/support/vcr.rb' with the following contents:
  2. require 'vcr'

    VCR.config do |c|
      c.stub_with :fakeweb
      c.cassette_library_dir = 'features/cassettes'
  3. Inside the step definitions (in my steps files under 'features/steps/'):
  4. VCR.use_cassette 'name' do
This will create the cassette file 'name' in the 'features/cassettes' directory. After recording your request/response the first time, any additional communications will be stopped by VCR, because the default options for VCR sets record to 'new episodes'.