Forum: Ruby Problem with rspec mock object

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Pat M. (Guest)
on 2006-05-16 06:52
(Received via mailing list)
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 =, 3)

  specify "should have a movie and rental length" do @movie
    @rental.days_rented.should_be 3

class Rental
  attr_reader :movie, :days_rented

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

  def get_charge
    movie.get_charge days_rented

  def get_frequent_renter_points
    movie.get_frequent_renter_points days_rented

MockExpectationError in 'A new rental should have a movie and rental
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 @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.

This topic is locked and can not be replied to.