Monday, January 05, 2009

The --include-activation and --aasm parameters of the Restful Authentication Rails Plugin are mutually exclusive

I was following the installation instructions for the Restful Authentication Rails plugin. So I executed:

script/generate authenticated user sessions --include-activation -—aasm --rspec

This resulted in:

premature end of regular expression: /\A

After digging into the source code, I found that the parse! method in /usr/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/rails_generator/options.rb swallowed exceptions. Here is the original code.

def parse!(args, runtime_options = {})
  self.options = {}
  @option_parser = do |opt|
    opt.banner = banner

  return args

    self.options = full_options(runtime_options)

The OptionParser initialization may cause exceptions which are not properly handled. I don't know what should be down but added the following code immediately before the ensure line at least will show the exception.

    rescue => e
    puts("I caught a #{e.class.to_s} with message #{e.to_s}")

Now that the exception is displayed, I saw one of my underlying problems:

I caught a OptionParser::InvalidOption with message invalid option: --include-activation

So I learned that when the --aasm parameter is used, then the --include-activation must not be specified.

Sunday, January 04, 2009

Using the Visualize Models plugin

This is a good plugin. It works with GraphViz to generate diagrams of your object model. After installation, I ran into a problem that Visualize::Inflector was not found. This was easily resolved by using ActiveSupport::Inflector in visualize_models.rb.

The Myth of the Hero Programmer

Fortunately, I have met few self-appointed heroic programmers over the years. However, late last year I was saddened to met another. People on truly agile teams might never have met this dying breed of programmer so let me present the archetype by borrowing from the Highlights magazine:

Goofus: Writes complex hard-to-understand code to prove superiority.
Gallant: Writes clear easy-to-understand code to enhance team dynamics.
Goofus: Writes code with side-effects to show his mastery of arcana.
Gallant: Writes simple code that is easy to maintain and debug.
Goofus: Disdains and deletes comments.
Gallant: Describes code context to aid maintenance and provide road maps for new team members.
Goofus: Speaks in imperative words and derisive tones.
Gallant: Speaks with humility and guides people to solutions.

The Ruby community should guard against any tendency towards heroic programmers to avoid some of the complaints made against the Perl community. Too many 'perlers' loved complexity for its own sake which lead to unmaintainable code and a bad reputation for the language in general.

Let's focus on the agile concepts of teamwork, shared code ownership, and collaboration. They are much healthier for the community.

What Goofus/Gallant experiences have you had?

Thursday, January 01, 2009

Avoiding the undefined method `use_transactional_fixtures=' error.

After adding rspec to my project and generating a model with rspec_model, I tried to run the generated spec test:
$ spec -cfprofile spec/
.../toshi/spec/spec_helper.rb:12: undefined method `use_transactional_fixtures=' for # (NoMethodError)
 from /usr/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/runner.rb:184:in `configure'
 from /home/medined/Workspaces/toshi/spec/spec_helper.rb:8
 from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
 from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
 from /home/medined/Workspaces/toshi/spec/models/book_spec.rb:1
After a fruitless internet search, I tried using a rake task:
$ rake spec
Finished in 0.061996 seconds
1 example, 0 failures

Adding RSPEC to a Rails Project

$ rails toshi
$ script/generate rspec
Couldn't find 'rspec' generator
$ cd toshi/vendor/plugins
$ git clone git://
$ git clone git://
$ cd ../../
$ script/generate rspec
      create  lib/tasks/rspec.rake
      create  script/autospec
      create  script/spec
      create  script/spec_server
      create  spec
      create  spec/rcov.opts
      create  spec/spec.opts
      create  spec/spec_helper.rb