[rspec-users] Problem testing method

Matt Wynne matt at mattwynne.net
Thu Sep 25 07:44:49 EDT 2008


On 25 Sep 2008, at 11:51, Carlos Rafael Belizón Ibáñez wrote:
> And I got this error:
>
> 4)
> Spec::Mocks::MockExpectationError in 'Alineado.cambiar_por with the  
> game
> in play and sustitutions aviable should decrement in one the
> sustitutions aviables'
> Mock 'Partido_1004' received unexpected message :cambios_visitante=  
> with
> (2)
> /home/carlos/NetBeansProjects/ofs/app/models/alineado.rb:53:in
> `cambiar_por'
> spec/models/alineado_spec.rb:263:
> spec/models/alineado_spec.rb:193:
>
> And I don't know how fix this error. It's possible test this?
>
> P.D.: Sorry for my english.
>
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users


Have a look at this:
http://gist.github.com/12805

When you call foo -= 1, ruby does two things:

(1) asks foo for its value
(2) tells foo to have a new value, one less than the answer it got  
back from the first question.

If you re-write more verbosely, you'll see what I mean:

foo = foo - 1

Two operations are being done to foo. So if you want to mock out foo,  
you have to mock out both those operations.

Make sense?

cheers,
Matt
----
http://blog.mattwynne.net
http://songkick.com

In case you wondered: The opinions expressed in this email are my own  
and do not necessarily reflect the views of any former, current or  
future employers of mine.





More information about the rspec-users mailing list