Chris Lowis Blog


Syndicate content
Updated: 19 min 4 sec ago

Setting Http Proxy when using the selenium-webdriver gem and Firefox

Wed, 07/14/2010 - 00:00

I've been using the selenium-webdriver ruby gem to do some automated Cucumber testing of our application. Sadly, I'm sat behind a firewall which requires an HTTP proxy to access the outside world. Using the Chrome WebDriver bridge worked fine as it inherits the system preferences on OS X. However with Firefox I had to perform some trickery to get it to work:

require 'rubygems' require 'selenium-webdriver' include Selenium profile = WebDriver::Firefox::Profile.new profile["network.proxy.type"] = 1 profile["network.proxy.http"] = "www-cache.at.my.work.co.uk" profile["network.proxy.http_port"] = 80 driver = WebDriver.for(:firefox, :profile => profile) driver.navigate.to "http://google.com"

The []= method on Profile is setting the options that you find by typing 'about:config' in the Firefox URL bar. Take a look there in a working Firefox profile to see what variables you should set for your webdriver-specific profile in the code above.

Categories: Semantic Web

Growl notifications from Ruby on OS X

Tue, 07/06/2010 - 00:00

I wanted to generate Growl notifications from a Ruby script on OSX and had a bit of trouble getting it to work. To save you the same hassle, here's the steps I took:

Install growl

Install Growl if you haven't already. I used version 1.2.

Set some growl preferences

In the growl preference plane (find it under System Preferences)

  • under network check "Listen for incoming notifications" and "Allow remote application registration"
  • restart growl
Install the ruby-growl gem

There's a couple of different ruby bindings for Growl but ruby-growl seemed to work for me

gem install ruby-growl Send a growl notification from your Ruby script

You can now send notifications from Ruby

require 'rubygems' require 'ruby-growl' g = Growl.new "127.0.0.1", "ruby-growl", ["ruby-growl Notification"] g.notify "ruby-growl Notification", "It Came From Ruby-Growl", "Greetings!"

Categories: Semantic Web

Open-source rails apps to study and learn from

Mon, 05/31/2010 - 00:00

If, like me, you learn best by studying other code here's five some open-source rails apps with something to teach. They're a great resource to study and improve your own code, or to use as the starting point for your own applications. All of these applications use Rails 2 but as they are open-source they are a great opportunity to get your feet wet in the Rails 3 world by helping to port them across.

Update: Thanks to the comments here and over on Hacker News, I've added two more applications and made some comments on the non-standard nature of the Loved by Less application code.

Gemcutter

A site familiar to all Ruby developers is Gemcutter - the recent replacement for the venerable Rubyforge. I wasn't aware that the source code of the site was open source until danieldon pointed it out to me, but you can study the code on github. The Gemcutter source is written in a very modern way featuring examples of using Cucumber for integration testing, a simple Rack middleware example and an interesting routes.rb file showing how to cleanly version an API.

Features
  • A very modern Rails application featuring the latest best practices.
  • Examples of metal and rack middleware.
Spot Us

Spot Us is a website that allows individuals to commission freelance journalists. It has many social-network type features which make the source code interesting reading.

The comprehensive test suite is written with rspec and the ruby-like templating system HAML is used for the views. It's also an example of how to use jQuery in a rails app instead of the default prototype through the use of the jrails plugin.

Features
  • Haml
  • rspec
  • jquery with the jrails plugin.
Loved by Less

Loved By Less is an open-source social network. I think many Rails freelancers have been asked to create a site with social network features - profiles, 'friending', photo sharing etc. Less Everything were no different and created this open-source platform to help ease the pain of getting started. The source code is available on github. It's unlikely that simply cloning the app will give you everything you need, but it's an amazing resource to read through and take the bits you need for your project.

The loved by less source code is starting to show it's age a bit, and does include some pretty extensive monkey patching which may confuse a newcomer. While I don't think this is bad in itself (it shows the flexibility of Ruby, and also the dangers of not following Rails conventions), it's something to be aware of. I think porting this to Rails 3 would give newcomers to Rails a great resource to learn from.

Features
  • Search with Thinking Sphinx
  • Flickr integration
  • Comprehensive email support
  • Paperclip for attachments
Saasy

If you're working on a Software as a Service application, take a look at Saasy . It's a template application designed to do billing and authentication tasks 'so you don't have to'.

Studying the code base, you'll see examples of using SSL security and ActiveMerchant. I was also interested in the accounts model which uses the acts_as_state_machine plugin to simplify some of the logic.

Features
  • acts_as_state_machine
  • ActiveMerchant
Simply Agile

Simply Agile by Andrew Bruce is an open source agile software project management application. Think of a simple version of Pivotal Tracker. You can add story cards to a backlog, and then assign each card to a sprint. Each time a card is completed you can drag and drop it to the appropriate column in the Simply Agile task board. Andrew has a very dedicated approach to test-driven development and as a result the application is well covered by cucumber and rspec tests. The javascript in this application is written in an unobtrusive style and is a good example of using jQuery for "progressive enhancement". The app is fully functional in browsers without javascript, but where javascript is available so is the drag-and-drop interface.

Features
  • Cucumber integration tests
  • rspec coverage
  • Drag and drop interface powered by jQuery.
Typo

Typo is "the oldest and most powerful Ruby on Rails blogware" and is still under active development. While the 15 minute blog is still a fantastic demonstration of how powerful Rails is for rapid application development, anyone who has decided to take the project further and create their own fully-featured blog system will know how much extra work is needed. From comment systems, to anti-spam protection, restful routing to upload support there are many features that need to be added. Thankfully Typo has already implemented these and many other features, and the source code is available to help you learn how to do the same.

Features
  • rspec for testing
  • internationalisation support
  • email notification
  • admin and public-facing interfaces
Open Source Rails

Open source rails is a gallery of open-source rails projects. I selected this project for this list because although the code itself isn't well documented or tested, in many ways this is illustrates a great strenght of the Rails framework. It is a good project to study to realise how much can be achieved with a small amount of code and a handful of powerful plugins (not that I'd recommend starting your next Rails project without tests, of course!).

Features
  • OpenID integration
  • Paperclip for file uploads
  • A simple set of routes.
Conclusion

I hope you enjoyed this selection of Rails projects. This is far from a definitive list, and I encourage you to read some of the suggestions of other apps in the comments below and on the discussion over on Hacker News. With the upcoming Rails 3 release I think it's a good time to reflect how far the Rails framework has come, and also to remember to cater for people who are learning Rails for the first time - studying open-source code is a great way to learn.

Do you have a favourite open-source Rails project? Share it in the comments below.

Categories: Semantic Web

FOAF file linkedinqdostwitter logolast.fm soundcloud logo