Forum: RSpec MockExpectationError

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Song L. (Guest)
on 2008-12-06 07:18
no matter how I try to stub! it still showing this error

I have the following in my spec
    Profile.stub!(:new).and_return(@profile = mock_model(Profile))


(rdb:1) @profile.stub!(:user)
#<Spec::Mocks::MessageExpectation:0x9fa1c94 @at_most=nil, @sym=:user,
b:199:in `transaction'", @exception_to_raise=nil,
@actual_received_count=0, @at_
least=nil, @consecutive=false, @return_block=nil,
derGroup:0xa1b060c @ordering=[],
0xa1b0634 @opts={}, @target=#<Profile:0x50d841e @name="Profile_1300">,
@args_expectation=#<Spec::Mocks::ArgumentExpectation:0x9fa0c04 @c
nt:0x9fa0d1c>], @match_any_args=true>, @args_to_yield=[],
@method_block=nil, @sy
mbol_to_throw=nil, @expected_received_count=:any,
::ErrorGenerator:0xa1b0634 @opts={}, @target=#<Profile:0x50d841e
1300">, @name="Profile_1300">>

(rdb:1) @profile.user = 3
Spec::Mocks::MockExpectationError Exception: Mock 'Profile_1300'
received unexpe
cted message :user= with (3)

Try many variations of stub!, stub!..with, should_recieve, etc nothing
I'm using rspec and rspec-rails version 1.1.11
Mark W. (Guest)
on 2008-12-06 08:22
(Received via mailing list)
On Fri, Dec 5, 2008 at 9:18 PM, Song L. <removed_email_address@domain.invalid> 

>    Profile.stub!(:new).and_return(@profile = mock_model(Profile))
> (rdb:1) @profile.user = 3
> Spec::Mocks::MockExpectationError Exception: Mock 'Profile_1300'
> received unexpected message :user= with (3)

You're stubbing :user when you need to stub :user=

Song L. (Guest)
on 2008-12-06 08:52
yes indeed, thanks
This topic is locked and can not be replied to.