RVM, Bundler and Ruby Tracker
August 11th, 2010
Lightning Talk at rorosyd
Here are the slides from a lightning talk I gave at rorosyd last night. Having found RVM, Bundler and Ruby Tracker to be a useful set of tools this year, I thought I’d take the opportunity to share my experiences. And, as I mentioned during the talk, kudos to Mikel Lindsaar for his blog post earlier this year which alerted me to the power of creating a .rvmrc file.
Configuring CapGun
October 10th, 2009
I’ve long been a fan of Capistrano, the Ruby deployment tool that is typically used for deploying Rails applications. And I’ve also been impressed by the work of Glenn Vanderburg and his colleagues at Relevance. So I took notice when I recently read about CapGun, which is useful for sending email notifications whenever a project is deployed.
The point of this post is that very recently I had the opportunity to install and configure CapGun for a client. The blurb on github told me how to install and configure CapGun. Under the heading of Usage I was encouraged to read the first paragraph:
Good news: it just works.
Well, almost. CapGun does “just work” once you’ve configured it correctly. Included in the config sample to be added to deploy.rb was:
# define the options for the actual emails that go out -- :recipients is the only required option set :cap_gun_email_envelope, { :recipients => %w[joe@example.com, jane@example.com] }
Unfortunately this was not quite complete enough for CapGun to work. Instead it died deep in the bowels of net/smtp.rb:
/usr/local/lib/ruby/1.8/net/smtp.rb:930:in `check_response': 555 5.5.2 Syntax error. 7sm1592402qwb.55 (Net::SMTPFatalError) from /usr/local/lib/ruby/1.8/net/smtp.rb:899:in `getok' from /usr/local/lib/ruby/1.8/net/smtp.rb:828:in `mailfrom' from /usr/local/lib/ruby/1.8/net/smtp.rb:653:in `sendmail' from /usr/local/lib/ruby/gems/1.8/gems/actionmailer-2.3.4/lib/action_mailer/base.rb:684:in `perform_delivery_smtp' from /usr/local/lib/ruby/1.8/net/smtp.rb:526:in `start' from /usr/local/lib/ruby/gems/1.8/gems/actionmailer-2.3.4/lib/action_mailer/base.rb:682:in `perform_delivery_smtp' from /usr/local/lib/ruby/gems/1.8/gems/actionmailer-2.3.4/lib/action_mailer/base.rb:523:in `__send__' from /usr/local/lib/ruby/gems/1.8/gems/actionmailer-2.3.4/lib/action_mailer/base.rb:523:in `deliver!' from /usr/local/lib/ruby/gems/1.8/gems/actionmailer-2.3.4/lib/action_mailer/base.rb:395:in `method_missing' from ./vendor/plugins/cap_gun/lib/cap_gun.rb:70
The lesson was that the :cap_gun_email_envelope needed to be configured with :from as well as :recipients. And the good news is that the people at Relevance have just accepted my documentation patch.
And the even better news is that now CapGun does “just work”. It’s a very handy tool for keeping everyone in a team informed about deployments in an automated and timely manner.
Inspirations for a Ruby DSL
September 6th, 2009
Recently, during discussions with a client about reducing the amount of boilerplate coding that recurs from time to time in the project, the idea of developing a Domain Specific Language (DSL) arose. If you’re wondering what a DSL is, here is what Martin Fowler has to say. Or, you may prefer this cheeky piece from Dr Nic Williams.
I’ve been intrigued by DSLs for some time but not had the motivation to develop one until now.
In preparation, I’ve gathered a list of resources for writing a DSL in Ruby.
Tutorials
- Russ Olsen’s two part article
- Chapter 16 on DSLs in Russ Olsen’s “Design Patterns in Ruby” book
- Mischa Fierer’s three part article about writing a clean Ruby DSL
Examples
- Pete Yandell’s machinist
- Javan Makhmali’s whenever, which provides a clean Ruby syntax for defining cron jobs
- Ben Schwarz’s smoke (also see this video)
- Marcus Crafter’s sprinkle (also see this presentation)
- Cucumber, the behaviour driven development DSL
I’m happy with that list of resources but if anyone has any other suggestions please feel free to comment.
My next challenge is to think about the problem domain and design an elegant syntax.
Rails Camp 5 and Sydney RORO Meetup
June 11th, 2009
I think it’s time I gave a brief update about a couple of professional events within the Australian Ruby community that I’ve recently enjoyed.
Rails Camp 5
Last month over an extended weekend the fifth Australian Rails Camp was held in the Queensland Gold Coast Hinterland. The venue was superb, much fun was had and a great deal of thanks is due to the Brisbane contingent who organised the event.
Having started the weekend working on my own to improve my iPhone development skills, particularly with respect to using ObjectiveResource to integrate an iPhone app with a Rails backend, I was actually very pleased that I didn’t continue on this path beyond Saturday afternoon. From Saturday evening onwards I teamed up with Martin Stannard and Michael Koukoullis to develop a Heroku-like tool called Bivouac. I thoroughly enjoyed our collaboration and learnt much from it. For anyone else considering attending a future Rails Camp I thoroughly recommend getting involved in a team project rather than working alone.
More on Bivouac in a later post. Meanwhile, you can find the source on github.
Sydney June RORO Meeting
Earlier this week the monthly Sydney RORO (Ruby on Rails Oceania) meeting featured a dozen lightning talks. In one of my talks I shared a technique for providing XML in a legacy format via REST, XML Builder and a presenter object. Whilst the example is contrived, the technique is one that I used to handle a requirement for a client recently.
Here are the slides:
In fairness, I must give credit to Obie Fernandez for his coverage of XML Builder in his book, The Rails Way, which gave me a head start.
Impressed with Prawn for PDF Generation
April 5th, 2009
I’ve been aware of Prawn, the Ruby PDF generation library for some time. Today was the first occasion I had an opportunity to utilise it and I was delighted with how easy it was to use.
My Ruby application needed to generate some tabular PDF reports so I installed the prawn gem and, with a little help from the examples on the Prawn home page and the core and layout documentation, I was off and running.
An example of using prawn via a rake task follows:
require 'rubygems' require 'prawn' require 'prawn/layout' namespace :report do desc "Generate top 10 points getters report" task :top10 => :environment do Prawn::Document.generate("reports/top10.pdf") do font "#{Prawn::BASEDIR}/data/fonts/DejaVuSans.ttf" font_size 14 text "Top 10 Points Getters" text " " # fetch two-dimensional array of data for the table data = Player.top10_data table data, :font_size => 9, :position => :center, :headers => ["#", "Player", "Points"], :row_colors => ["ffffff", "eeeeee"] end end end
Generating the report was then as simple as running:
rake report:top10
I’m looking forward to using other features of Prawn such as image embedding and content positioning. At the time of writing prawn itself is version 0.4.1 and prawn-layout is 0.1.0. Hopefully James Healy, an Australian noted as “instrumental to the forward development of the library”, is coming to Railscamp 5 next month. Then I can pick his brains about what other features are in the pipeline.
Automated Testing with Ruby
December 8th, 2008
The fifth Australian Open Source Developers’ Conference was held last week in Sydney. In addition to helping organise the conference, I was fortunate enough to be one of the Ruby presenters.
Naturally, these slides were designed to assist my presentation rather than contain all the content. Indeed, the inclusion of some of the slides may beg some questions so I thought it may be helpful to add some explanation here.
Reminiscing about Testing
Each of us programmers is on a specific journey, especially when it comes to testing. Early in my professional career I was taught how to unit test program modules written in PL/I. However, the drivers for those tests had to be written in Job Control Language (JCL) – an experience I am not in a hurry to repeat.
Many years later, having escaped from working on mainframes, I discovered JUnit. This was a fundamental tool in my early experience of test driven development and refactoring. When I began exploring Ruby and Rails, I was eventually introduced to autotest, which I considered another quantum leap forward in the realm of automated testing.
Testing Tools
In 25 minutes there was obviously a limit to the number of Ruby testing tools I could cover. So, having quickly explained the benefit of autotest and touched upon Test::Unit, I moved on to describe some tools that I have used in the last year.
RSpec
To make sure the audience was still awake, at this point I showed a cute photo of our family dog. My lame excuse was that he exhibits a wide range of behaviours and RSpec is all about specifying behaviour. My main example of using RSpec was for specifying a controller. This led on to a brief digression into consider what makes a good test and the use of mock objects to isolate unit tests and make them faster by avoiding unnecessary database I/O.
Integration Testing with Cucumber, Webrat and Selenium
I was pleased to be able to include Cucumber, Webrat and Selenium in my talk. It’s only fairly recently that I started using Cucumber in conjunction with Webrat or Selenium and I’m impressed. As Mike Koukoullis showed in his subsequent talk, developing with Cucumber is a very powerful approach, which fosters clear description of intent before development of any feature.
Speaking of other talks, Alister Scott used a lightning talk to share his enthusiasm for Watir, which looks like a good alternative to Selenium.
Test Data with Machinist
After briefly relating the motivation for developing alternatives to relying on fixtures for test data, I described Machinist, an elegant tool recently developed by Pete Yandell. When used in conjunction with Sham, Machinist provides a neat way of generating “blueprints” that can be used in Cucumber steps.
Other Tools
I briefly mentioned JavaScript unit testing tools that are the subject of a blog post by Dr Nic as well as touching upon Shoulda, which is well written up by Dave Thomas.
Philosophy
To round out my talk, I thought it was important to offer a few philosophical thoughts. In a nutshell my view is that, whilst it is important to remember that automated testing is just one of many error removal approaches, we can all benefit from investing in automated testing.
In my case, as well as practicing using these tools, I’m also looking forward to reading the upcoming title The RSpec Book by David Chelimsky and others.
Code Syntax Highlighting
October 17th, 2008
Having just implemented code syntax highlighting in this blog in addition to Textile formatting, I thought I’d share how I did it.
After a little research, I decided that Arya Asemanfar’s tm_syntax_highlighting plugin looked the most promising. Arya’s blog post about it was particularly helpful.
Prerequisites
Install the oniguruma system library (see link in the plugin README).
Install the ultraviolet gem, which will also install the textpow and oniguruma gems.
sudo gem install ultraviolet
1. Install the Plugin
./script/plugin install git://github.com/arya/tm_syntax_highlighting
2. Copy all themes from ultraviolet:
./script/generate syntax_css
3. Create defaults initializer
# config/initializers/tm_syntax.rb TmSyntaxHighlighting.defaults = {:theme => "mac_classic", :line_numbers => false, :lang => "ruby"}
4. Create an application helper method to parse the Textile and code:
Note: I have used “c0de” instead of “code” here just to enable this code to be parsed!
# app/helpers/application_helper.rb def parse_textile_and_code_syntax(text) text_pieces = text.split(/(<c0de>|<c0de lang="[A-Za-z0-9_-]+">|<c0de lang='[A-Za-z0-9_-]+'>|<\/c0de>)/) in_pre = false language = nil text_pieces.collect do |piece| if piece =~ /^<c0de( lang=(["'])?(.*)\2)?>$/ language = $3 in_pre = true nil elsif piece == "</c0de>" in_pre = false language = nil nil elsif in_pre code(piece.strip, :lang => language, :theme => "mac_classic") else RedCloth.new(piece.strip).to_html end end end
5. Use the helper in the views
<%= parse_textile_and_code_syntax(@blog_post.post) %>
6. Add CSS for horizontal scrolling
pre { margin: 10px 10px; padding: 10px 10px; line-height: 15px; overflow: auto; font-family: "Monaco", "Courier New", courier; font-size: 12px; }
Navigation
Latest Blog Posts
- 11 Aug: RVM, Bundler and Ruby Tracker
- 10 Feb: Ten Years On
- 10 Oct: Configuring CapGun
- 6 Sep: Inspirations for a Ruby DSL
- 28 Jul: At Your Service
Syndication
Tags
actionwebservice automated testing bdd blog bundler capgun capistrano collaboration css cucumber deployment dsl estimating jaoo javascript osdc osdc2008au pdf prawn rails railscamp rake rest rorosyd rspec ruby ruby tracker rvm selenium services syntax highlighting tdd technology unconference wds08 web design webrat xml xml-rpc