1
사용자 세션 컨트롤러 테스트를 테스트하여 사용자 세션을 처음으로 빌드 한 다음 저장하려고합니다. 내 사용자 세션 클래스는 다음과 같습니다스텁을 사용하여 authlogic 세션 컨트롤러를 어떻게 스펙 아웃 할 수 있습니까?
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
내가 밖으로 스텁 :
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
내 컨트롤러의 사양은 다음과 같습니다
이class UserSession < Authlogic::Session::Base
end
내 UserSessionsController의 작성 방법은 다음과 같습니다 새로운 방법을 사용했지만 테스트를 실행할 때 여전히 다음과 같은 오류가 발생합니다.
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 in 'UserSessionsController POST'새로운 사용자 세션을 시작해야 할 때 '로그인하지 않을 때 생성' 수신 됨 : 예상치 못한 인수가있는 새로운 메시지 예상 됨 : ({: password => "test" , : {login : = "quentin"}) got : ({{: priority_record => nil}, nil}, [{: priority_record => nil}, nil], [{ "로그인"=> "quentin" 암호 "=>"시험 "}]) –
graywh