Typography is the craft of endowing human language with a durable visual form, and thus with an independent existence. (...) Typography remains a source of true delight, true knowledge, true surprise.

Robert Bringhurst, The Elements of Typographic Style

The to_sentence method is nothing terribly new – just another reason why one would want to work with Ruby on Rails:

irb(main):005:0> require 'rubygems'
=> true
irb(main):006:0> require 'activesupport'
=> true
irb(main):007:0> ['John', 'Paul', 'George', 'Ringo'].to_sentence
=> "John, Paul, George, and Ringo"

Ok, this was easy. Some googling revealed the reason that none of my generated rspec tests would ever be picked up by autotest. You apparently have to export RSPEC=true in your shell, prior to starting autotest. So here is the getting started list:

  • Install gems rspec, rspec-rails, ZenTest, redgreen
  • generate scafffolds/models/controllers with the rspec method (installing the gems gives you, among others, the additional generator targets rspec_controller, rspec_model, rspec_scaffold)
  • export RSPEC=true and start autotest

One quote from my first autotest run:

Finished in 0.963479 seconds
400 examples, 400 failures

January 21, 2009

RSpec

1 comment

While being all convinced of and impressed with all the advantages of developing with RSpec, cucumber and autotest, I have yet to find the time to actually start doing it. And there is not that much information out there (the bigger pieces probably being the screencasts on peepcode.com). I will try and document some of the more interesting findings as a convert. Right now, my rails project has reached its first milestone and is (or appears to be) functionally stable. Even if this was the case (which I do not really believe), keeping it that way would be worth writing tests.

August 6, 2008

Ruby on Rails

(No comments)

Just in case you have not noticed yet: www.nomedojogo.com. The pdf file is a “What’s new in RoR 2.1″ compilation, thankfully often times being more elaborate than the usual bullet lists. Thanks!

is “The Rails Way” by Obie Fernandez. Trying to learn RoR in my spare time over the past 12 months, I have to say that it is a lot of fun and easy to learn (as the frameworks advocates say) and that it can be hard for beginners sometimes, as the critics claim. This is the most readable reference book I have seen so far, it covers Rails 2 and on several occasions I was able to solve problems by looking them up in the book. Money well spent, probably too much details for the absolute beginner.

April 19, 2008

Ruby on Rails

(No comments)

The example on custom textile tags, given at the nubyonrails page is very well written, but left some individuals with the question, how to do custom inline tags. After some searching I found at least one reference in some forum, which I used to build the following code. What would one need a custom inline tag for, you might ask? In my case, I wanted a very simple way of referring to pages in a RoR mini-CMS I had built. To make abbreviated link names possible, a search action seemed appropriate. This means that something like ?"Lot 5"? would translate into <a href=”/titlesearch?searchterm=Lot 5″>Lot 5</a>. Using a class extending RedCloth already, all I had to do was to add the following lines of code:

RULES = [:inline_textile_search, :refs_textile, :block_textile_table,
:block_textile_lists, :block_textile_prefix, :inline_textile_image,
:inline_textile_link, :inline_textile_code, :inline_textile_span,
:glyphs_textile ]

# render internal links as title search links

def inline_textile_search(text)
    text.gsub!(/(?"?)([w|s]+?)("?)/) do |m|
        content = $~[2]
        "<a href="/titlesearch?searchterm=#{content}">#{content}</a>"
    end
end

def to_html
    super(*RULES)
end

I should mention that this solution is far from being perfect (I am overwriting the RULES, taken from the current version of RedCloth, to add my tag method). At the same time, it works the way I wanted it to.