[rspec-users] Mocks and Refactoring - doing it wrong?

Sebastian W. lists at ruby-forum.com
Thu Oct 30 01:02:00 EDT 2008

Hello RSpec folks,
I've only been introduced to the world of mock objects since Wednesday
of last week, so go easy on me if I come off as ignorant. :P

So, I'm a big fan of testing, especially since it has really helped to
do refactoring in the past. But, I'm running into an issue that I'm
hoping could be cleared up. Let's say that I have some code like the

mock_engine = mock("Engine")
car = Car.new(mock_engine)

Internally, the car class calls "ignite" on the engine that was passed
to the constructor. We run the spec, everything is green. So far, so

Now, here's what I don't understand: suppose I refactor the Engine class
and rename the "ignite" method to "turn_on". If I re-run the example
from above, the test is still green - but it shouldn't be, since the
"ignite" method doesn't exist on the Engine class anymore.

So I'm wondering...what am I doing wrong? I feel like my tests should
help catch these sorts of things when I do a refactoring - my hunch is
that I'm missing a step here.

All comments are welcomed and appreciated! :)
Posted via http://www.ruby-forum.com/.

More information about the rspec-users mailing list