2011-03-16 1 views
5

지금 테스트 중이지만 Webrat에서 올바른 필드에 있는지 확인했지만 fill_in을 사용하여 양식 필드를 찾을 수 없습니다. Webrat은 필드 이름이나 신분증으로 작동합니까? 나는 Ruby 심볼과 폼 이름을 사용하여 필드에 접근하려고 시도했지만, 두 경우 모두 작동하지 않는다. 구현시 잘못된 내용이 있습니까?레일 3 통합 테스트 - webrat fill_in을 사용하여 필드를 찾을 수 없음

오류 메시지 :

5) Forwarding should forward the user to the requested page after signin 
    Failure/Error: integration_sign_in(user) 
    Could not find field: :email 

테스트 코드 :

it "should forward the user to the requested page after signin" do 
    user = Factory(:user) 
    visit edit_user_path(user) 

    # The test automatically follows the redirect to the signin page 
    puts current_url 
    integration_sign_in(user) 

    # The test follows the redirect again, this time to users/edit 
    response.should render_template('users/edit') 
end 

integration_sign_inspec_helper.rb

def integration_sign_in(user) 
    fill_in :email, :with => user.email 
    fill_in :password, :with => user.password 
    click_button 
end 

에서 양식 필드의 HTML입니다 :

<form action='/sessions' class='mtm' id='sign-in-form' method='post'> 
    <input name='authenticity_token' type='hidden' value='iIIqT6bUwiJkpqpgxm5sjAj3egrNcEgeXPsYmbKQ02U='> 
     <div class='landingSignInForm'> 
      <label class='mas signin-label' for='email'>E-mail:</label> 
      <input class="mls ras" id="email" name="email" placeholder="e-mail address" type="text" /> 
      <label class='mas signin-label' for='password'>Password:</label> 
      <input class="mls ras" id="password" name="password" placeholder="password" type="password" /> 
      <input checked='checked' class='mls mtm' name='remember' type='checkbox' value='permanent'> 
      <span class='remember-me-label'>Keep me signed in</span> 
      <input class='mls mvm ram medium silver button' name='submit' type='submit' value='Sign in'> 
      <a class='forgot-password' href='#'>Forget your password?</a> 
     </div> 
</form> 

답변

1

일치하는 기호를 전달하는 대신 ID 대신 CSS 선택기를 사용해 보셨습니까? 나는 내부적으로 문자열을 기호로 취급하는지 결정하기 위해 webrat 소스를 잠시 읽으려고 시도했다. 이것이 문제인지 궁금해했다. 난 단지 fill_in 'string'

이 시도 fill_in :symbol를 사용하여 webrat 구문의 예를 찾을 수 없습니다 :

def integration_sign_in(user) 
    fill_in 'email', :with => user.email 
    fill_in 'password', :with => user.password 
    click_button 
end 

또는 IDS에 대한 CSS 선택기 경로 :

def integration_sign_in(user) 
    fill_in '#email', :with => user.email 
    fill_in '#password', :with => user.password 
    click_button 
end 
+0

응답 해 주셔서 감사합니다. 불행히도 위의 작업 (기호, 이름, ID 등)이 없습니다. 나는 거의 Webrat을 포기하고 Capybara를 설치하여 Webrat 문제인지 확인하려고합니다. – iwasrobbed

+0

더 이상 도움이되지 않아서 미안 해요. 행운을 빕니다! –

+0

걱정하지 마시고 다시 한번 감사드립니다! – iwasrobbed

1

그것은 작동한다고 하나

fill_in 'email', :with => user.email # field name 

또는

fill_in 'E-mail', :with => user.email # partial label text 

자세한 내용은 webrat documentation을 참조하십시오.

또한 입력 필드 중 일부가 닫히지 않은 것으로 나타났습니다. 이것은 템플릿이 생성하는 정확한 HTML입니까?

일반적으로 나는 Capybara로 전환하는 것이 좋지만, webrat이 실제로 망가 졌는지는 의심 스럽습니다.

+0

당신은 그렇게 생각 하겠지만 주사위는 없습니다. 여기 뭔가 다른 점이 있습니다. Capybara는 같은 오류를주고 필드를 호출하고 올바른 페이지에 있는지 확인하는 모든 방법을 시도했습니다. – iwasrobbed

관련 문제