Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on May 13th, 2010  |  syntax: Ruby  |  size: 1.12 KB  |  views: 102  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. # truck.rb
  2. class Truck
  3.  
  4.   def initialize(cyliders = 6, litres =  3.2)
  5.     @litres =  litres
  6.     @cyliders = cyliders
  7.     @passengers = []
  8.   end
  9.  
  10.   def add_passengers(person)
  11.     @passengers << person
  12.     @passengers.flatten!
  13.   end
  14.  
  15.   alias :add_passenger :add_passengers
  16.  
  17.   def number_of_passengers
  18.      @passengers.length
  19.   end
  20.  
  21.   def has_big_engine?
  22.     @litres > 3.1
  23.   end
  24.  
  25.   def has_v6_engine?
  26.     @cyliders == 6
  27.   end
  28. end
  29.  
  30. #################################################
  31. # truck_spec.rb
  32.  
  33. require File.join(File.dirname(__FILE__),'truck')
  34.  
  35. describe Truck do
  36.  
  37.   # Need to return object
  38.   # Should be uses the object_id
  39.   subject do
  40.     foo = Truck.new()
  41.     foo.add_passengers(['James','Kelly','Vic','Foo'])
  42.     foo
  43.   end
  44.  
  45.  
  46.   it "should have four passengers" do
  47.     pending("Working on better test")
  48.     @foo.passenger_number.should == 4
  49.   end
  50.  
  51.   it "should have four passengers" do
  52.      should have(4).number_of_passengers
  53.   end
  54.  
  55.  
  56.  
  57.   it "should have v6 engine" do
  58.     should have_v6_engine
  59.   end
  60.  
  61.   it "should have a big engine" do
  62.     should have_big_engine
  63.   end
  64. end