# Mocha: does\_not\_expect

**URL:** <https://www.ruby-forum.com/t/mocha-does-not-expect/165790>\
**Category:** Ruby\
**Created:** [April 17, 2009, 2:09pm UTC](https://www.ruby-forum.com/t/mocha-does-not-expect/165790 "2009-04-17T14:09:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![fipa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/9e8a1a/32.png) [@fipa](https://www.ruby-forum.com/u/fipa)\
**Post date:** [April 17, 2009, 2:09pm UTC](https://www.ruby-forum.com/t/mocha-does-not-expect/165790/1 "2009-04-17T14:09:33Z")

</div>

Hi,

I am writing tests for a Rails app using Test::Unit and Mocha. expects  
does a great job to make sure a method is called. But how to handle the  
fact that a method shouldn’t be called?

I have a before filter that protects the call to a given restricted  
method, and how to make sure that this method doesn’t get called  
unexpectedly?

---

<div class="post-metadata">

**Author:** ![fipa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/9e8a1a/32.png) [@fipa](https://www.ruby-forum.com/u/fipa)\
**Post date:** [April 17, 2009, 2:24pm UTC](https://www.ruby-forum.com/t/mocha-does-not-expect/165790/2 "2009-04-17T14:24:48Z")

</div>

On Fri, Apr 17, 2009 at 1:09 PM, Fernando P.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)wrote:

> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

some\_object.expects(:expected\_method).never

Regards,  
Ben

---

<div class="post-metadata">

**Author:** ![fipa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/9e8a1a/32.png) [@fipa](https://www.ruby-forum.com/u/fipa)\
**Post date:** [April 17, 2009, 2:34pm UTC](https://www.ruby-forum.com/t/mocha-does-not-expect/165790/3 "2009-04-17T14:34:30Z")

</div>

> some\_object.expects(:expected\_method).never

Damnd I never thought about such method while reading the API.

Thank you very much.

---

<div class="post-metadata">

**Author:** ![fipa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/9e8a1a/32.png) [@fipa](https://www.ruby-forum.com/u/fipa)\
**Post date:** [April 17, 2009, 2:41pm UTC](https://www.ruby-forum.com/t/mocha-does-not-expect/165790/4 "2009-04-17T14:41:12Z")

</div>

On Fri, Apr 17, 2009 at 1:34 PM, Fernando P.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)wrote:

> > some\_object.expects(:expected\_method).never
> 
> Damnd I never thought about such method while reading the API.
> 
> Thank you very much.

Yeah I missed it first time round too 🙂

Ben
