Problem with rspec mock object


#1

I have perhaps the simplest mock object ever - it doesn’t do anything.
However when I use it, it gives me an error. Here’s the full code,
along with the error:

require “rental”

context “A new rental” do
setup do
@movie = mock(“Movie”)
@rental = Rental.new(@movie, 3)
end

specify “should have a movie and rental length” do
@rental.movie.should_equal @movie
@rental.days_rented.should_be 3
end
end

class Rental
attr_reader :movie, :days_rented

def initialize(movie, days_rented)
@movie = movie
@days_rented = days_rented
end

def get_charge
movie.get_charge days_rented
end

def get_frequent_renter_points
movie.get_frequent_renter_points days_rented
end
end

MockExpectationError in ‘A new rental should have a movie and rental
length’
Mock ‘Movie’ received unexpected message ‘to_s’ with []
./specs/rental_spec.rb:10:in `should have a movie and rental length’

So when I’m calling @rental.movie.should_equal @movie, it’s blowing
up. I have no clue what’s going on. After doing some googling and
looking at the source, all I know is that to_s is undefined on my mock
object - I don’t know why it’s being called though.

Pat