• RSS Feed
  • Categories

Uninstall all of my system gems

November 17th, 2011 by Ben Wagaman.
Categorized as bash, Ruby on Rails.

I needed to uninstall all of my system ruby gems, but I didn’t want to go through line by line removing them. This script removes them all using some scripting.

Core of the Core: Reflection Talk

May 17th, 2010 by Ben Wagaman.
Categorized as programming, Ruby on Rails.

ruby reflectionTonight at the Columbus Ruby Brigade meeting, I gave part two of my “Core of the Core” speaking series.

Part two was on Reflection in Ruby.

Core of the Core: Reflection Presentation

Core of the Core: Class Class

April 19th, 2010 by Ben Wagaman.
Categorized as programming, Ruby on Rails, technology.

Here is the presentation from my Class Class Talk at the Columbus Ruby Brigade tonight.

SOLID design principles

October 7th, 2009 by Ben Wagaman.
Categorized as programming, Ruby on Rails.

I’m electronifying my notes from conferences and such. Here’s my notes from Jim Weirich’s SOLID design principles in Ruby talk from eRubyCon 2009.

1.) Single Responsibility Principle
a class should have 1 reason to exist
describe the purpose of your class in a single sentence (you shouldn’t need and/or)

2.) Open/Closed Principle
you should be able to extend a class’ behavior without modifying it

3.) Liskov Substitution Priniciple
require no more, promise no less

4.) Interface Segregation Principle

5.) Dependency Inversion Principle
depend on abstractions, not concrete-tions

** Note that my notes are a little bit shotty, because the days prior to the conference I was totally totally strapped at work and thus rest-deprived.

Testing my patience. A skeptic’s thoughts on beginning to write tests

January 29th, 2009 by Ben Wagaman.
Categorized as programming, Ruby on Rails.

It’s been a long time since I posted anything in my blog, so I thought I ought to break the silence. Lately, I’ve been trying to get myself caught up on the test-driven/behavior-driven development philosophy. If you are a programmer, maybe you can relate to my struggles of learning how to get it right.

Test-Driven Development is a programming philosophy that encourages the developer to specify test test conditions before writing the code to meet the specification. To me, this is counter-intuitive. I guess I am naturally a brute and think the best way to figure something out is to play with it, and than after a while it should just work.

Ironically, the chapter on Testing in the Agile Web Development with Rails book comes well after the first attempts at hammering out Rails code for a shopping cart application. I understand why the book is written the way that it is, and am greatly appreciative of the book, but there ought to be a Test-Driven version of the same tutorial, so that people can see first-hand how to test-first in development.

It also hasn’t helped that my first attempt at writing tests have been less than perfect too. I’ll end up writing 6 or 7 lines of test code to test one case for a method. The verboseness of tests has negatively reinforced me in to thinking that testing is hard.

What’s more frustrating is that I’ve heard expert developers talk about only having a line or two of test code to test a method. This has seemed to me to be an unatainable ideal. How are you supposed to test code that is ten lines long (or more) with one or two lines of test code? That’s unpossible.

But, recently I came to the realization that if the methods I am writing are smaller and do more specific things, then they are a whole lot easier to test. This is mostly because the tests can move towards the ideal of the expert: short, meaningful, specifications. This in turn helps me to actually write the test first, because I know I can specify the behavior of code that is less complex.

Some of the recent developments in RSpec have helped this ideal even further. For instance, see David Chelimsky’s post on RSpec 1.1.12 He notes that what you could have done

In order to test this:

class Person
  validates_presence_of :email
end

You would have in previous versions of RSpec written:

describe Person do
  it "should validate presence of email" do
    person = Person.new(:email => nil)
    person.should_not be_valid
    person.should have(1).error_on(:email)
  end
end

In RSpec 1.1.12, you can reduce this down to the following:

describe Person do
  it { should validate_presence_of(:email) }
end

This is due to:

  • an implicit receiver from the describe block Person.new
  • custom matchers for validate_presence_of (which are available through plugins like rspec-on-rails-matchers or you can make your own matchers
  • self commenting specification code

Three lines of code. Three lines of test. That’s pretty darn cool. Perhaps, it’s not possible to have a line by line spec for everything, but this is a lot better than before.

I’ve still got a fair bit of inertia to overcome before I’ve got TDD under my belt. The more I tell myself that test-driven development is less about testing than it is about developing well-written code, the more motivated I am to do it. I hope this is an encouragement to unit testing newbies.

MyRubyClass.reload!

August 8th, 2008 by Ben Wagaman.
Categorized as programming, Ruby on Rails.

Today I was writing some specs with RSpec, the Ruby BDD Testing Framework. In between tests, classes aren’t reloaded by default, so I went about try to figure out how to reload a class for certain tests.

Active Support defines a method on Class called remove_class. This provides half of the equation. The other half was to reload the class again. So, I wrote a method on the Object class that should handle most cases. Note, this may not work with namespaced classes, but it did the quick and dirty job of helping my specs to reload the class.

# Call this method like
# MyRubyClass.reload!
# or
# MyRubyClass.reload!('/path/to/file/my_ruby_class.rb')
class Object
  def reload!(file = nil)
    remove_class(self)
    load(file || "#{self.to_s.underscore}.rb")
  end
end

All I needed to do was then call this method when I needed to reload the class.

MyRubyClass.reload!

RailsConf Speakers

April 30th, 2008 by Ben Wagaman.
Categorized as Ruby on Rails, technology.

Speakers for the main sessions of RailsConf 2008 are available now. A number of Columbus/Cincinnati Rubyists are showing: Jim Weirich, Joe O’Brien, Aaron Bedra, Dan Manges. I wish I could go. Oh well, maybe next year

On another note, Blip TV has a number of the keynotes from RailsConf 2007 online.

Upgrading to Rails 2.0

December 15th, 2007 by Ben Wagaman.
Categorized as how to, programming, Ruby on Rails.

With Rails 2.0 out now, it’s time to explore the new source. It’s hard to believe that it’s already been 2 years since I first checked out Rails 1.0 for the first time.

To update your Rails code, you can run
gem update rails

However, when I tried to run this command I was unfortunately greeted with a nasty error, when getting to update ActiveRecord.

Attempting remote update of activerecord
ERROR: While executing gem ... (Zlib::BufError)
buffer error

According to a Ruby Form post, I found a solution to the problem, updating ruby gems.

While you could run this line to update RubyGems to 0.9.5, I don’t recommend it.
gem update --system

Instead download rubygems-0.9.4, unzip it and then run
ruby setup.rb

This will allow you to continue to use Mongrel, because there are some incompatibilities with Mongrel running on Win32 with RubyGems 0.9.5. See the following:

and then update rails as you would expect.
gem update rails

Voila!

Next Page »