Wednesday, December 2, 2009

Cruise control.rb refusing to build a project

I ran into an interesting problem at work today. I had a cruise control project that would not build the project after a commit was made. Other projects in CruiseControl.rb were working properly.

Here's the steps I used to debug:

Login to your Cruise Control box and cd to $BUILD_DIR/projects/$PROJ_NAME/work

Run the following command. This is how CC.rb figures out if updates have been made.

git log --pretty=raw --stat HEAD..origin/master
When I ran this command, I was getting "warning: refname 'origin/master' is ambiguous." returned. After some google searches, I landed upon some mailing list messages that pointed me towards the issue.

The reason git was complaining about origin/master being ambiguous was that someone created a tag named "origin/master" (the beating has been scheduled).

I had to delete this tag locally by running the following command.

git tag -d origin/master
Then I had to delete the remote branch by running the following.

git push origin :refs/tags/origin/master
Now the CC server is working properly.

Labels: , , , , , ,

Thursday, September 10, 2009

testing syntax highlighting

public class HelloBlogger {
public static void main(String [] args) {
System.out.println("Hello Blogger!!");
}
}

rspec file is newer than

My pair and I were working on implementing LessCSS at work this week and we ran into an interesting problem. We wanted to write RSpec tests that would figure out if the .less file was newer than the .css file, and if so provide a good error message.

We discussed this with Hosh and he suggested using a custom matcher, which we had not heard of before. In researching custom matchers, we came up with the following solution:

def be_newer_than(new_file, msg=nil, msg2=nil)
  simple_matcher do |old_file, matcher|
    old_file_mtime = File.stat(old_file).mtime
    new_file_mtime = File.stat(new_file).mtime
    matcher.description = "be newer than #{new_file.inspect}"
    matcher.failure_message = msg || "expected #{old_file.inspect} to be newer than #{new_file.inspect}"
    matcher.negative_failure_message = msg2 || "expected #{old_file.inspect} to be older than #{new_file.inspect}"

   old_file_mtime >= new_file_mtime
end
This allows you to do the following:
css_file = "site.css"
less_file = "site.less"
css_file.should be_newer_than(less_file)
This will tell you if css_file is newer than the less file.

The optional arguments allow you to pass custom error messages. For example:

  it "should be up to date" do
    output = "#{css_file} is not up to date.  Please run the following: "
    output += "\n\t lessc #{less_file}\n\n"
    css_file.should be_newer_than(less_file, output)
  end

Labels:

Thursday, August 6, 2009

Start using Mint.com to manage your money today!

"Join Mint.com!"
Why you'll love Mint.com: * Easy --set up in minutes * All your accounts in one place * Alerts for bills, fees, budgets, and low balances * Personalized savings * Complete security and privacy

Wednesday, July 22, 2009

W3C logger plugin for Rails

I just released a plugin for Rails that logs your rails requests in W3C format. Checkout http://github.com/primedia/w3c_logger/tree/master.

Friday, June 26, 2009

Installing Ruby 1.9 on Mac OS X 10.5

Tommie over at The blog with no name has written up a how-to on getting Ruby 1.9 up and running in Mac OS X 10.5.7. Check it out: http://www.tommycampbell.net/2009/06/26/ruby-1-9-on-mac-os-x

Labels:

Thursday, June 4, 2009

How to optionally load gems

I ran into an interesting problem today at work. I wanted to optionally require a ruby gem. For example, I wanted to include the metric_fu rake tasks, but if a user doesn't have metric_fu installed, it's no big deal. Here's how I implemented it. I added a method to the Kernel space (where require lives) called desire. I desire this gem to be installed, but I should just see a warning if it's not installed, instead of an error. Here's the desire method (I put this in RAILS_ROOT/Rakefile).
module Kernel
  def desire(library)
    require library
    return true
  rescue LoadError
    STDERR.puts "warning: #{library} gem desired but not found."
    return false
  end
end
And here's how I optionally include the metric_fu gem.
desire 'metric_fu'
If a user has the gem installed, rake -T will show the tasks.
jasonn:~/sources/my_files [master] $ rake -T
(in ~/sources/my_files)
rake metrics:all 
[...]
jasonn:~/sources/my_files [master] $
If the user does not have the gem installed, rake -T will show a simple warning and continue.
jasonn:~/sources/my_files [master] $ rake -T
(in ~/sources/my_files)
warning: metric_fu gem desired but not found.
[...]
jasonn:~/sources/my_files [master] $
I don't remember where I first heard the desire idea, but it works pretty well.