1
我想测试我的用户会话控制器测试用户会话是先构建然后保存的。我UserSession类看起来是这样的:如何使用存根指定authlogic会话控制器?
class UserSession < Authlogic::Session::Base
end
我UserSessionsController的制作方法是这样的:
def create
@user_session = UserSession.new(params[:user_session])
if @user_session.save
flash[:notice] = "Successfully logged in."
redirect_back_or_default administer_home_page_url
else
render :new
end
end
和我的控制器的规格如下所示:
describe UserSessionsController do
it "should build a new user session" do
UserSession.stub!(:new).with(:email, :password)
UserSession.should_receive(:new).with(:email => "[email protected]", :password => "foobar")
post :create, :user_session => { :email => "[email protected]", :password => "foobar" }
end
end
我踩灭了新的方法,但我仍然遇到以下错误,当我运行测试时:
Spec::Mocks::MockExpectationError in 'UserSessionsController should build a new user session'
<UserSession (class)> received :new with unexpected arguments
expected: ({:password=>"foobar", :email=>"[email protected]"})
got: ({:priority_record=>nil}, nil)
虽然在我的控制器代码被调用之前,在UserSession上调用了新方法。调用activate_authlogic没有区别。
我看到了类似的问题,但我得到: Spec :: Mocks :: MockExpectationError'UserSessionsController POST'创建'未登录时应该启动一个新的用户会话' received:new with unexpected arguments expected:({:password =>“test” ,:login =>“quentin”}) got:([{:priority_record => nil},nil],[{:priority_record => nil},nil],[{“login”=>“quentin”密码 “=>” 测试“}]) –
graywh
2010-05-25 18:51:16