Sep 11 2007

Describing Equivalence Classes in Ruby with RSpec

dastels @ 8:45 pm

Here’s an article I wrote a while ago but didn’t get around to releasing.  Enjoy. 

Describing Equivalence Classes in Ruby with RSpec

Since writing that article, I’ve made good use of the code. Here’s an example of it in action: grouping the cards in a deck into their types. A second method then uses those groups to reassemble the cards into an ordered list.

 

  CARD_TYPES = ['basic land', 'land', 'creature', 'artifact',
                'enchantment', 'sorcery', 'instant', '']

  def maindeck_cards_grouped
    maindeck_cards.equivalence_classes(*CARD_TYPES) do |card, the_type|
      card.magic_card.card_type.downcase.include?(the_type)
    end
  end

  def maindeck_cards_ordered
    cards_by_class = maindeck_cards_grouped
    (CARD_TYPES.inject([]) {|cards, type| cards << cards_by_class[type]}).flatten
  end

Sep 11 2007

Rails Rumble project reports

dastels @ 5:18 am

The stats for our project:

 

+----------------------+-------+-------+---------+---------+-----+-------+
| Name                 | Lines |   LOC | Classes | Methods | M/C | LOC/M |
+----------------------+-------+-------+---------+---------+-----+-------+
| Controllers          |    70 |    55 |       2 |       6 |   3 |     7 |
| Helpers              |     6 |     4 |       0 |       0 |   0 |     0 |
| Models               |   891 |   734 |      13 |     110 |   8 |     4 |
| Libraries            |     0 |     0 |       0 |       0 |   0 |     0 |
| Model specs          |  2283 |  1835 |       0 |       0 |   0 |     0 |
| View specs           |     0 |     0 |       0 |       0 |   0 |     0 |
| Controller specs     |     0 |     0 |       0 |       0 |   0 |     0 |
| Helper specs         |     0 |     0 |       0 |       0 |   0 |     0 |
+----------------------+-------+-------+---------+---------+-----+-------+
| Total                |  3250 |  2628 |      15 |     116 |   7 |    20 |
+----------------------+-------+-------+---------+---------+-----+-------+
  Code LOC: 793     Test LOC: 1835     Code to Test Ratio: 1:2.3

 

A few things to notice:

  • very “rails” light… small controller… very literally a controller.. all the action happens in the models,
  • all the specs are for model classes, the controller & view do very little.. although the controller could probably do with a few specs, and
  • there’s over twice as much code in the specs than in the working classes.

The spec run:

 

$rake spec
(in /Users/dastels/Projects/Ruby-Projects/merlin/trunk)
..........................................................................
..........................................................................
..........................................................................
........................................................
Finished in 62.891545 seconds
278 examples, 0 failures

 

and the coverage report:

SafariScreenSnapz001.png
Note that echo was under development and actually didn’t get finished in time. Also we ran out of time before getting to mindbender.

Sep 11 2007

A hell of a way to spend a weekend

dastels @ 3:11 am

Rails Rumble ’07 is over.

It was a total good time.We didn’t get as much done on our app as we had hoped, but what we got done turned out as well as we could have hoped.I was on the IRC channel the whole time pretty much, which provided a nice sideline. The whole thing had a strong co-opatition feel. There was a great group of people involved.

A big THANK YOU to the sponsors, the organisers, the other teams, and mostly to my teammate, Nancy.

We ran into some interesting technical issues in the course of the 48 hours, which I’ll be writing about over the next few days.For those interested, or just with voyeristic tendancies (ain’t the web great), there’s a flickr pool, and I’ve posted some pics in my .mac gallery.