3

Hi I'm using Mocha for a Rails project. I'm new to TDD so please forgive me if this is a stupid question.

If I have this

@client.expects(:create_config).once.returns(true)

then am I right in assuming that the code in create_config() won't be run and instead true will just be returned?

Vega
  • 27,856
  • 27
  • 95
  • 103
robodisco
  • 4,162
  • 7
  • 34
  • 48

2 Answers2

1

Never used mocha, but this is indeed the case for all mocking frameworks i've worked with

Mel Gerats
  • 2,234
  • 1
  • 16
  • 33
  • 1
    Never used mocha, but that behavior is kind of the entire *point* of mock objects... – kyoryu Feb 27 '10 at 09:53
  • I wasnt sure if mocks just asserted whether or not a certain method was called or not or if they also bypassed the actual methods code as well. I knew stubs existed to do the latter so thought perhaps mocks didnt do that. – robodisco Feb 28 '10 at 11:36
0

Both expects and stubs prevent execution of the specified method. The difference is that expects creates an assertion that causes the test to fail if the method isn't called, and stubs doesn't create any assertion.

Jim Stewart
  • 16,964
  • 5
  • 69
  • 89