2012-02-12 3 views
0

Rspec에서 form_tag를 시뮬레이트 할 수 없습니다. form_tag는 해시 매개 변수를 단순 해시로 패키지하는 반면 Rspec은 다음과 같은 매개 변수가 포함 된 해시 해시로 패키지화합니다.Rspec에서 Rails form_tag 테스트

{ "session"=> { " 이메일 "=>"[email protected] ","암호 "=>"는 foobar "},"컨트롤러 "=>"세션 ","행동 "=>"생성 "} 레일 때 form_tag 대

:

{ "UTF8"=> "✓", "authenticity_token"=> "AiurjCANkzCJFl + oiJK2tQVzzxrET260bo1wxuDHB74 =", "이메일"=> "[email protected]", "암호"=> "는 foobar" "commit"=> "Sign ","액션 "=>"세션 제어부가 사용

","제어기 "=>"세션 "} 생성 :

user = User.find_by_email(params[:email]) 

이메일 파라미터를 추출. 이것은 발전을 위해 작동하지만 RSpec에 테스트를 위해 내가 사용하는 것 :

여기
user = User.find_by_email(params[:session][:email]) 

내 최신 RSpec에 테스트입니다 :

이 때문에 매개 변수의 차이로 실패합니다
describe "success" do 
before(:each) do 
    @user = Factory(:user) 
    @attr = {:email => @user.email, :password => @user.password } 
end 

it "should redirect to the user show page" do 
    #post :create, :session => @attr #same results 
    post sessions_path(:email => @user.email, :password => @user.password) 
    response.should have_selector('h1', :content => @user.full_name) 
end 
end 

위 해시 . 위에 표시된 것처럼 form_tag와 일치하는 단일 해시로 세션 컨트롤러에 매개 변수를 보내는 Rspec의 방법이 있습니까?

답변

0

당신은

describe "success" do 
before(:each) do 
    @user = Factory(:user) 
    @attr = {:email => @user.email, :password => @user.password } 
end 

it "should redirect to the user show page" do 
    post :create, :email => @user.email, :password => @user.password 
    response.should have_selector('h1', :content => @user.full_name) 
end 
end 

이 빌리 => "

{..."이메일 "로 컨트롤러에 메서드에 매개 변수를 보낼 것입니다 귀하의 테스트에서 수동으로 매개 변수를 전달하는 시도 할 수 있습니다 @ example.com ","password "=>"foobar "...}