Archive for the ‘Ruby’ category

Using rvm in conjunction with bundler

November 16th, 2011

I’m starting to use rvm with my rails projects and am wondering how to be use it in conjunction with bundler, as bundler already does a good job of managing the gems i need in my project.

To keep things simple for now, i’ve decided to keep bundler doing what it’s been doing (managing the project gems), and use rvm to simply specify the versions of ruby and bundler to use within the project.

So, in my project folder, i have 2 files, 1 for rvm and 1 for bundler:

  • .rvmrc
    This includes only the following:
    rvm use 1.9.2@development –create
  • Gemfile
    Includes all gems need within the project

The @development specifies that the app is using this rvm gemset, meaning that if i wish, i could have multiple gemsets and switch between them. As i’m currently handing off most of the gem management responsibility to bundler, this doesn’t makes sense at the moment, but could be useful later as i possibly migrate further responsibility over to rvm over time.

Making rvm gemsets work under OS X Lion with XCode 4.2

November 16th, 2011

Running Xcode 4.2 on OS X will cause issues with RVM. Here are details of the issues and fix.The process takes no more than 5 minutes in total.

Issue

gem install bundler
/Users/me/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/1.8/timeout.rb:60: [BUG] Bus Error
ruby 1.8.7 (2011-06-30 patchlevel 352) [i686-darwin11.1.0]

Abort trap: 6

Fix

  1. Install Xcode 4.2
  2. Install the gcc standalone compiler from https://github.com/kennethreitz/osx-gcc-installer (which replaces Xcode)
  3. Add “export CC=gcc-4.2″ to your ~/.bash_profile or equivalent (don’t forget to reload it)
  4. Run “rvm implode” then re-install rvm http://beginrescueend.com/

Getting up and running with Git and Rails on EC2

November 6th, 2011

Here’s a short list of things to do to get Git and Rails running on EC2:

Install Git

sudo yum install -y git
  • sudo yum install -y git

Install Rails

  • sudo yum install -y rubygems ruby-devel gcc libxml2 libxml2-devel libxslt libxslt-devel mysql mysql-devel
  • sudo gem update –system
  • sudo gem install rails

Merb Gem Cleanup

November 25th, 2009

It seems to be a common issue for us Merbists, who depend on multiple Gems for merb to play nicely to get into a bit of a mess as gems are updated.

So, at times a cleanup is in order. Here is what i’ve done to cleanup my merb setup:

$ sudo gem update --system
$ gem search --no-version merb | grep merb | xargs sudo gem uninstall -a # NOTE: removes all old version of merb
$ gem search --no-version dm | grep dm | xargs sudo gem uninstall -a # NOTE: removes all old version of data_mapper
$ gem search --no-version data_objects | grep data_objects | xargs sudo gem uninstall -a # NOTE: removes all old version of data_objects
$ sudo gem sources -c
$ sudo rm PATH_TO_GEMS/cache/merb* # PATH_TO_GEMS is the path to your rubygems install.  Mine is /usr/lib/ruby/gems/1.8
$ sudo rm PATH_TO_GEMS/cache/dm*
$ sudo gem install -r merb

This was taken from the meb installation instructions at: http://wiki.merbivore.com/howto/installation/gems

Using Cucumber, Webrat and Selenium to test ajax form field validations

September 4th, 2009

I have an app that fires an ajax request on a form field to validate its contents when I take focus off the field.

I am also using Cucumber, Webrat and Selenium for my integration tests.

I needed my integration tests to test the Ajax responses and the tests weren’t receiving a response from the Ajax requests.

The Problem

I found that by simply completing the web form, the ajax request was not being fired and my test was therefore failing when i checked for the existance of the Ajax response. It soon became clear that selenium doesn’t really interact with the form in the sense of selecting fields and entering values; It simply enters values. As such, the Ajax request was not firing and my test was failing.

The Solution

The solution is Selenium’s fireEvent method, which you can pass a form field id and the blur method:

selenium_session.fireEvent(”field”, “blur”);

In Webrat, this is ever simpler:

fire_event(”field”,”blur”)

On using this in a Cucumber step, the ajax is fired as the blur command tells the browser to take focus off the field.

Lovely!