How to use thor with the latest version of merb
November 26th, 2009 • Merb, programming, thor • No comments
The latest version of thor (0.12.0) doesn’t work with the latest version of merb (1.0.15).
To use thor with your merb 1.0.15 app, you need to install thor -v0.9.9 and then follow the instructions on this page: http://wiki.merbivore.com/deployment/bundling
Merb Gem Cleanup
November 25th, 2009 • DataMapper, Merb, OS X, Ruby, programming • No comments
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
Call TextMate from command line
September 7th, 2009 • Apple, Mac, TextMate, programming, software development • 2 comments
A really neat feature of TextMate is the ability to call it from the command line and pass a directory or file as the object to open. Works great.
For this to work, you need to run a quick one-liner on the command line:
sudo ln -s /Applications/TextMate.app/Contents/Resources/mate /usr/local/bin/mate
Once done, you can call mate and pass it any object you want to open, such as:
$ mate my_rails_app
and it opens the entire directory as if it were a TextMate project.
Lots more detail available here: http://manual.macromates.com/en/using_textmate_from_terminal.html
Using Cucumber, Webrat and Selenium to test ajax form field validations
September 4th, 2009 • Cucumber, Internet, JavaScript, Merb, Ruby, Webrat, programming • 2 comments
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!
Setting up Merb, Cucumber and Webrat (and friends) on Snow Leopard
September 4th, 2009 • Cucumber, Mac, Merb, OS X, Ruby, Webrat, bdd, programming, software development • 2 comments
My upgrade to Snow Leopard killed my Merb, Cucumber and Webrat setup so i had to start afresh. That was the bad. The good is that some manual hacks that were required in Leopard are no longer necessary, meaning I can rely on direct gem installations.
Here’s what i did:
- Install Ruby and Gems
Follow instructions on http://hivelogic.com/articles/compiling-ruby-rubygems-and-rails-on-snow-leopard/ - Install merb, rspec, cucumber, merb_cucumber and mongrel and dependencies
sudo gem install merb rspec cucumber roman-merb_cucumber mongrel term-ansicolor treetop diff-lcs nokogiri do_sqlite3 - Install webrat
sudo gem install hoe hpricot webrat - Fix Firefox bug with Snow Leopard
For some reason the libsqlite3.dylib library in FireFox 3.5.2 is out of date and breaks cucumber under Snow Leopard. Thankfully, it’s a simple fix:
mv /Applications/Firefox.app/Contents/MacOS/libsqlite3.dylib /Applications/Firefox.app/Contents/MacOS/libsqlite3.dylib.orig
cp /usr/lib/libsqlite3.dylib /Applications/Firefox.app/Contents/MacOS/libsqlite3.dylib - Install Selenium
sudo gem install Selenium
sudo gem install selenium-client - Install the textmate cucumber bundle
http://github.com/bmabey/cucumber-tmbundle/tree/master
Deprecated Instructions on Snow Leopard that were required on Leopard
The following ugly hacks were required on Leopard with it’s default Ruby installation. These are no longer required (at least on my machine) on Snow Leopard:
Manual hack of Selenium
http://wiki.github.com/aslakhellesoy/cucumber/setting-up-selenium
As the instructions recommended replacing the Selemium RC jar file () in the installed gem with one from the Selenium website, i had to find out where the gem had installed. Thankfully, gem -h pointed me toward gem help commands and from there i ran gem environment – This told me where gems are installed locally and i found that Selemium RC had been installed into /Library/Ruby/Gems/1.8/gems/Selenium-1.1.14/ I replaced as advised and then ran selenium from within the app root and all worked fine, using the replacement. I then downloaded and ran the test selenium code from http://github.com/aslakhellesoy/cucumber/tree/master/examples/selenium running selenium in a different console and then running cucumber examples/selenium/features/ . It worked a treat and booted up selenium as required. Great!
Manual hack installation of webrat
Download http://github.com/gwynm/webrat/tree/master tar file. Git clone doesn’t work
sudo gem install hoe hpricot
cd downloaded and untarred file
rake gem
sudo gem install pkg/webrat-0.2.1.gem