Rspec Testing

Hi, I am currently learning Ruby as much as i can (non rails usage) and
have a quick question about Rspec (and it is properly a more general TDD
question).

If you have class for example:

class MyClass

def foo(value)
#do someting
end

def bar(value)
#do something
end

def spam
a = foo(“value”)
b = bar(“value”)
end

end

If you were testing this class how would you go about it?

In my mind i would test foo and make sure it returns what i expect
I would also test bar to make sure it returns what i expect.

But also in my mind, i feel like when i test spam, that it calls out to
foo and bar.

Am I getting this wrong? should i be testing spam to also make sure that
it returns what i expect, regardless of wether it has made a call to foo
or bar?

I know i can stub the foo and bar methods for the test of spam to
control what spam can and wont return.

If anyone could help me get past this “final” hurdle in my understanding
of testing, and TDD i would be most grateful.

Thanks

Ps: i couldnt work out how to format my message sorry!

I was reading various articles about this topic this past weekend.

There is a debate. I would start with Martin’s paper:

The way I found that paper was I was looking at Better Specs “Mock or
not to mock”

and that pointed me to this which is also interesting I thought:

http://myronmars.to/n/dev-blog/2012/06/thoughts-on-mocking

IF you do want to test to see if spam calls out to foo and bar,
you do that with RSpec::Mocks

https://www.relishapp.com/rspec/rspec-mocks/docs

HTH,
Perry