[rspec-users] more rspec questions

Patrick J. Collins patrick at collinatorstudios.com
Tue Apr 27 19:02:08 EDT 2010


> Based on the above I think the Vcard is a good opportunity for a mock.
> That would most likely imply that you create the Vcard somewhere else
> and pass it into this method. Also, you should directly test the

Ok, and regarding mocking--  Something that is still very unclear to me is how
can I affect instance variables through mocking?  If I do:


def master_method
  @foo = "foo"

  slave_method
end

def slave_method

  @foo

end

..

it "should be foo" do

  foo = mock_model(Foo)

  foo.slave_method.should == "foo"

end

...


This will be false because @foo is set in the msater method which I am
bypassing because I just want to test the slave method.  So how can I set an
instance variabel within my spec so that @foo will be properly set?  Should I
use setter/getter methods in this case??

def master_method
  foo = "foo"

  slave_method
end

def slave_method

  foo

end

def foo=(new_foo)
  @foo = new_foo
end

def foo
  @foo
end

......... ?  Is that the way to go???

Patrick J. Collins
http://collinatorstudios.com


More information about the rspec-users mailing list