Forum: RSpec MockExpectationError

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ccdff6196651b11feab07008c035a597?d=identicon&s=25 Song Lee (songrit)
on 2008-12-06 06: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))

Then

(rdb:1) @profile.stub!(:user)
#<Spec::Mocks::MessageExpectation:0x9fa1c94 @at_most=nil, @sym=:user,
@expected_
from="D:/Songrit/_rails_apps/ului_new/app/controllers/registrations_controller.r
b:199:in `transaction'", @exception_to_raise=nil,
@actual_received_count=0, @at_
least=nil, @consecutive=false, @return_block=nil,
@order_group=#<Spec::Mocks::Or
derGroup:0xa1b060c @ordering=[],
@error_generator=#<Spec::Mocks::ErrorGenerator:
0xa1b0634 @opts={}, @target=#<Profile:0x50d841e @name="Profile_1300">,
@name="Pr
ofile_1300">>,
@args_expectation=#<Spec::Mocks::ArgumentExpectation:0x9fa0c04 @c
onstraints_block=nil,
@args=[#<Spec::Mocks::ArgumentConstraints::AnyArgsConstrai
nt:0x9fa0d1c>], @match_any_args=true>, @args_to_yield=[],
@method_block=nil, @sy
mbol_to_throw=nil, @expected_received_count=:any,
@error_generator=#<Spec::Mocks
::ErrorGenerator:0xa1b0634 @opts={}, @target=#<Profile:0x50d841e
@name="Profile_
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
works
I'm using rspec and rspec-rails version 1.1.11
48641c4be1fbe167929fb16c9fd94990?d=identicon&s=25 Mark Wilden (Guest)
on 2008-12-06 07:22
(Received via mailing list)
On Fri, Dec 5, 2008 at 9:18 PM, Song Lee <lists@ruby-forum.com> wrote:


>    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=

///ark
Ccdff6196651b11feab07008c035a597?d=identicon&s=25 Song Lee (songrit)
on 2008-12-06 07:52
yes indeed, thanks
This topic is locked and can not be replied to.