[rspec-users] more rspec questions

Patrick J. Collins patrick at collinatorstudios.com
Tue Apr 27 19:56:48 EDT 2010

> If something in the code you are testing depends on the return value
> of a method then you would use a stub. e.g.:
Right, but what I am asking is---  if all of my "slave methods" are relying on
stored card data from the @card instance variable--  how is the best way to
have access to the variable if it's only defined in the master method?

if I have a method that does

@card.addresses.each do |address|

and I want to test that a contact does in fact get a new address created after
that method is called with a vcard that has a valid address.

I mean, one way to do this would be the getter/setter way-- have a card=/card

Another way would be to just pass card into each method

def process_addresses(card)


..  But then I start feeling like my code is going to be less-elegant due to
the fact that I am trying to write things that can be tested.  Passing in a
variable is definitely less elegant than using an instance variable, and a
getter/setter is somewhat too (in my opinion).

Patrick J. Collins

More information about the rspec-users mailing list