Posted in Ruby

Setting up Ruby on Rails on OS X

First thing you’re going to need: Rob Conery’s quite excellent post here. It steps the new-to-OSX developer easily through the process of getting Ruby and Rails set up on your Mac using RVM – and without the gigantically cumbersome download of Apple’s XCode you’ll find in so many other instructions on doing this.

Initialising your database

Don’t forget to initialise your database as per the instructions given to you at the end of installation: if you skip this, your database won’t work. (If you’ve closed the terminal and need to see these instructions again, you can type “brew info mysql” to have them displayed.)

Setting up your root password

Start your server by typing mysql.server start to be able to log into it, then set the password up as per the Homebrew instructions.

Once this is all working, it’s a nice idea to get the thing starting up automatically whenever you boot up. The Homebrew instructions state: “To start mysqld at boot time you have to copy support-files/mysql.server to the right place for your system”. Details on where this is/how to do it are here.

Install Autotest and integrate with Rspec2

Michael Hartl’s tutorial helps with replicating his development setup, with Autotest continuously running your tests in the background based on your file changes and, in combination with Growl, providing instant feedback as you work. Install it as follows:

$ gem install autotest -v 4.4.6
$ gem install autotest-rails-pure -v 4.1.2

Install Growl if you don’t already have it installed, then install the autotest-fsevent and autotest-growl gems.

$ gem install autotest-fsevent -v 0.2.4
$ gem install autotest-growl -v 0.2.16

To use the Growl and FSEvent gems, make an Autotest configuration file in your application root directory, (or in your home directory if you want to run autotest across all your projects):

$ mate .autotest

and fill it with the below (ta flyerhzm, here) :

# Include plugins 
require 'autotest/fsevent' 
require 'autotest/growl'   

# Skip some paths 
  Autotest.add_hook :initialize do |autotest|   
  %w{.git .DS_Store ._* vendor}.each { |exception| autotest.add_exception(exception) }     

To get autotest picking up your rspec tests, create a directory “autotest” in your application root, add a directory called ‘autotest’ to the root of your application, and in it a file called “discover.rb” containing the following text:

Autotest.add_discovery { "rspec2" }

After that you should be able to run “autotest” from the root directory of your application and see your tests run.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s