janvier 2011Monthly :

Gemsets and .rvmrc – Ruby Gem Management Made Easy

RVM is a tool that automatically manage your ruby versions. You can make 1.8.7 and 1.9.2 live together without issues. The installation process is a bit lacking – bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install-head ) is not really a command that looks safe at first sight. Blindly executing code from the Internet is not for the faint of heart but yep, rvm is really that useful.

I especially love gemsets. They allow you to completely separate your various development environments for each of your projects. Gem conflicts are a lot less common.

You can even automatically change to a gemset for each of your project by using the an .rvmrc file. I use ruby 1.9.2 by default but I have one project that uses ruby 1.8.7. I use a separate gemset called ‘mygemset’.

# create the gemset if it does not exist
rvm_gemset_create_on_use_flag=1
# switch to default ruby version when exiting directory
rvm_project_rvmrc_default=1
# use ruby 1.8.7 with a specific gemset
rvm ruby-1.8.7-p302@mygemset

Pretty neat. Since this file is committed, it also means everyone on the team has the same setup.

Dependency Injection in Ruby Without a Framework

Lately,
I’ve been toying around with native Android application development using Java.

It got me hooked on using RoboGuice and Google Guice. Coming from a dynamic language background, it got me thinking as to why I never felt the need for a dependency injection framework before. Guess what? Ruby and Python both come with their own built-in dependency injection framework! Heresy?

Well let’s check out this small example and see if it’s the case or not.

Let’s say you have a small application that allows you to display all the books present in your database.

Let’s say your Book class looks a little something like this :

class Book
  attr_reader :title, :author

def initialize(title, author)
@title = title
@author = author
end

end

and that the class that allows you to visualize your Books looks a little something like this :

class VisualBookListing

def initialize(booksCollection = RubyBooksCollection)
@books_collection = booksCollection.new
end

def display
@books_collection.get_all_books.each{ |book|
puts “%s written by : %s ” %[book.author, book.title]
}
end

end

By using RubyBooksCollection as the default parameter value, it becomes the default implementation of the BooksCollection your BookListing’s class is expecting to receive.

This would take the place of the following line you would often see in a Google Guice module

bind(BooksCollection.class).to(RubyBooksCollection.class);

Although, unlike in Java, you do not have the advantages and disadvantages associated with the declaration of your interface.

Unfortunately, the default implementation of our RubyBooksCollection is this :

class RubyBooksCollection

def get_all_books
return Database.get_ruby_books
end

end

When we’ll want to write a unit test for our VisualBookListing, this means we’ll have to setup a database. Our test is now an integrated instead of being a unit test.

Our VisualBooksListing could not care less whether or not our data comes from a database, a text file or holy intervention.

Plus we get the hassle of setting up a database with the added bonus of making our test slower.

What to do then ? One solution could be to write a mocked BooksCollection to use instead of our RubyBooksCollection. It should be pretty easy to pass around since the dependency is injected through the constructor.

How could we do this ? You could use one of the many awesome mocking framework. Here’s an example I came up with without the use of any framework :

class MockedBooksCollection
   def get_all_books
      growing_object_oriented_software = Book.new "Growing OO Software", "Steve Freeman"
      domain_driven_design = Book.new "Domain Driven Design", "Eric Evans"
      return [growing_object_oriented_software, domain_driven_design]
  end
end

In your test, you would simply do assertions based on the result of this call to the VisualBookListing :

testBookListingDisplay = VisualBookListing.new library = MockedBooksCollection
testBookListingDisplay.display

whereas in prod, you would do a little something like this

productionBookListing = VisualBookListing.new
productionBookListing.display

This make it a little simpler than with Guice, where you would have to create a new context for your tests**.

So there you go, dependency injection in Ruby, without the need for a framework, and all the added benefits.

-Nicholas Lemay of team Sosoft.

**If you are interested, there is a nice little library called MycilaTesting written by Mathieu Carbou that facilitates testing context creation. The syntax of the tests produced look a little like this :

@GuiceContext(LibraryTests.LibraryTestsModule.class)
public class LibraryTests extends MycilaJunit4Test{

@Inject SomeLibraryDependency someLibraryDependency;
//You write your tests here

public static final class LibraryTestsModule extends AbstractModule {

protected void configure() {
bind(SomeLibraryDependency.class).to(MockedLibraryDependency.class);
}
}
}

“… awesome Scrum experience for TFS” – Brian Harry

Yesterday, we got a Christmas present from Brian Harry, the Product Unit Manager for Team Foundation Server and a Microsoft Technical Fellow. He wrote a blog where he praises Urban Turtle.

Urban Turtle is a TFS add-on built by Pyxis Technologies and it provides an awesome Scrum experience for TFS. For 10 years, Pyxis has been at the forefront of the evolving Agile development practices and has been helping companies transform their development process to be more Agile and more effective. We were thrilled when they decided to take that expertise and create a top notch Scrum experience for TFS.

You can read the full story here: Urban Turtle for Scrum and TFS

Agile for managers – Challenges, operation, and impact on leaders

After giving this introduction training to over a hundred people managers, I have decided to make the presentation material available to the general public in an attempt to help organizations successfully transition to Agile.

This presentation is introductory level as it introduces some of the most common reasons why organizations choose to adopt Agile approaches. It presents some high level statistics on software development project success (and failure) to demonstrate why the traditional project management approach may not always be the best approach to successfully deliver projects.

The presentation introduces what Agile is (and isn’t) and the reasons justifying its adoption. Once the Agile concepts have been presented, the material introduces the Scrum approach by giving a walk through of a typical process.

The presentation ends with the main impacts on people managers within organizations who are adopting Agile.

I hope you will find the presentation useful to help you move your transition in the right direction. Feel free to circulate the material.

Benefits associated with an Agile Transition – What can Scrum do for you?

Image by USACEpublicaffairsWondering what are the benefits of an Agile Transition. One of our client recently published a few good points:

  • Scrum exposes and makes visible the organizational issues in project delivery, which are not necessarily exclusive to agility (non-dedicated projects resources, difficulty of co-locating project members, etc.);
  • Positive impact on the role of the managers by moving from a command-and-control mode to coach-leader mode;
  • Not just doing things right but doing the right things;
  • Increased mobilization of project participants;
  • Better team synergy – increased synergy between Business and IT;
  • Puts the business needs at the center of the project team’s focus – business needs understood and shared by the team members;
  • Brings back the “common sense” in carrying out the project;
  • Better communication and transparency within teams;
  • Better visibility on the business value generated by the project;
  • Optimization of the investment;
  • Ability to “test” the feasibility before fully developing the solution.

These are only a handful of benefits. What benefits have your team witnessed since starting Scrum?