这是我的控制器
def log_in
admin=Admin.find_by_name(params[:name])
unless admin.nil?
admin=admin.authenticate(params[:password])
if admin==false
# wrong password,login again
# redirect_to sign_in_admins_url
else
session[:admin]=admin.name
redirect_to root_path
end
end
end
这是 rspec 代码:
describe "Post request for admins" do
it "should log_in with right name and password" do
post :log_in,name:"ryan",password:"123456"
controller.params[:name].should=="ryan"
controller.params[:password].should=="123456"
session[:admin].should eq "ryan"
end
end
而我的断言总是返回
expected 'ryan',got nil
为什么会这样?我还是 rspec 的新手......按照教程,认为它应该工作