2014-09-29 3 views
1

Capybara 및 Rspec에서 best_in_place 필드를 테스트하려면 어떻게합니까? 나는 이것에 처음이에요.통합 테스트 : Best in Place, Capybara & RSpec

<span 
    class='best_in_place' 
    id='best_in_place_user_233952_name' 
    data-url='/users/233952' 
    data-object='user' 
    data-attribute='name' 
    data-nil='User Name' 
    data-type='textarea' 
    data-original-content=''> 
</span> 

이름이 적힌 텍스트 영역을 가장 잘 기입하고 싶습니다.

RSpec.configure do |config| 
    config.include BestInPlace::TestHelpers 
end 

:

나는 best in place test helpers를 사용하기 위해 내 spec_helper.rbconfig.include BestInPlace::TestHelpers를 추가했다 :

fill_in("best_in_place_user_#{user.id}_name", with: 'some text') 
page.execute_script "$('#best_in_place_user_#{user.id}_name').trigger('keyup')" 
+0

[has_css?] (http://www.rubydoc.info/gems/capybara/1.1.2/Capybara/Node/Matchers#has_css%3F-instance_method) –

답변

5

이것은 내가 그것을 해결하는 방법입니다

+2

코드 예제를 보내 주셔서 감사합니다. 이것을 읽는 다른 사람을 위해서'require 'best_in_place''&'require 'best_in_place/test_helpers''를'spec_helper.rb' 파일에 추가해야 할 수도 있습니다. 아직하지 않았다면 – Reuben

+0

저에게는이 두 가지가 있습니다 추가해야하는 행 :'require 'best_in_place/test_helpers'와 'include BestInPlace :: TestHelpers' – james

1

자바 스크립트가 활성화되어 가정 그리고 내 시험에서 나는 이것을했다 :

require 'spec_helper' 

feature 'create a new user' do 
    scenario "create user Alice", :js => true do 
     visit '/some_path' 

     click_on 'New User' 
     expect(page).to have_content 'User Name' # [1] 

     user = User.order(:created_at).last 
     bip_area user, :name, 'Alice' 

     expect(page).to have_content 'Alice' 
    end 
end 

[1]은 JS가 필드를로드 할 때까지 대기하므로 중요합니다.

+0

괜찮 았지만 여기에 올바른 ID를 얻는 방법 ? 233952가 동적으로 생성되기 때문입니다. – zhurora

+0

id를 문자열로 보간합니다. 이것을 보여주기 위해 예제 코드가 업데이트되었습니다. –

+0

''best_in_place_user _ # {user.id} _name "'은 올바른 id, thx를 반환합니다! 그러나'fill_in'에서 사용하면 다음과 같은 오류가 나옵니다.'Capybara :: ElementNotFound : 필드 "best_in_place_user_2_name"을 찾을 수 없습니다. ('user.id = 2'가 맞습니다. ': js => true'). – zhurora

관련 문제