# Problem with rspec mock object

**URL:** <https://www.ruby-forum.com/t/problem-with-rspec-mock-object/94835>\
**Category:** Ruby\
**Created:** [May 16, 2006, 4:52am UTC](https://www.ruby-forum.com/t/problem-with-rspec-mock-object/94835 "2006-05-16T04:52:45Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![pergesu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/22d042/32.png) [@pergesu](https://www.ruby-forum.com/u/pergesu)\
**Post date:** [May 16, 2006, 4:52am UTC](https://www.ruby-forum.com/t/problem-with-rspec-mock-object/94835/1 "2006-05-16T04:52:45Z")

</div>

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
