[rspec-users] Mocking: brittle specs and tight coupling?

Brandon Olivares programmer2188 at gmail.com
Sat Apr 11 18:59:38 EDT 2009


Hi,

I've read of complaints that mocking can make the specs very brittle, in
that if the method is changed at all, it will break the specs, even if the
behavior remains the same. Do you find this to be the case? How do you deal
with this if so?

Also, when I used to do TDD in PHP, well there wasn't the ability to modify
the class on the fly like in Ruby, so you actually had to do dependency
injection, but people generally looked at this as a good thing, for loose
coupling. So if a controller method for instance used a User model, then it
would be preferred to get that instance from somewhere, either passing it to
the method itself or calling another method to instantiate it.

I notice this isn't a concern in RSpec or in Ruby in general. Do you view
this differently, or what is the preferred way to deal with dependencies? Is
it fine just to do:

User.should_receive(:new).and_return(User.new)

Just as a very simple example?

Thanks,
Brandon

Brandon



More information about the rspec-users mailing list