This may be a dumb noob issue, but I haven’t found any answers while
seaching
the forum–
I have a controller method
def edit
@user = User.find params[:id]
@user.password_confirmation = @user.password
end
The User class has an “attr_accessor :password_confirmation” definition
(so
“password_confirmation” doesn’t exist in the users table). My spec has
the
following
it “should find User on GET to users/edit/:id” do
User.should_receive(:find).and_return(@user)
@user.should_receive(:password_confirmation)
get ‘edit’, :id => @user.id
end
I am asking it to expect that I will be assigning something to that
attribute in the “edit” method. Unfortunately, the spec fails with
Spec::Mocks::MockExpectationError in ‘UsersController should find User
on
GET to users/edit/:id’
Mock ‘user’ received unexpected message :password_confirmation= with
(“password”)
Initially I thought that my “should_receive” expectation was incorrectly
written, but if I comment out the attribute assignment in the controller
method
…
@user = User.find params[:id]
#@user.password_confirmation = @user.password
…
then the test fails with
Spec::Mocks::MockExpectationError in ‘UsersController should find User
on
GET to users/edit/:id’
Mock ‘user’ expected :password_confirmation with (any args) once, but
received it 0 times
So, it seems to me that the expectation is written correctly, but
something
about using the attr_accessor via the mock object is causing a failure.
BTW, I am doing the following in a before(:each) block
@user = mock("user")
@user.stub!(:new_record?).and_return(false)
@user.stub!(:update_attributes).and_return(true)
@user.stub!(:password_confirmation).and_return('password')
@user.stub!(:password).and_return('password')
User.stub!(:new).and_return(@user)
Does anyone know what I’m missing here?
Thanks!
View this message in context:
http://www.nabble.com/Unexpected-message-on-%3Aattr_accessor-tf4944588.html#a14155614
Sent from the rspec-users mailing list archive at Nabble.com.