2013-11-09 4 views
1

나는 한 데모 애플리케이션이 발견 :누군가 RSpec으로 best_in_place 테스트 헬퍼 메소드를 테스트 한 적이 있습니까?

it "should be able to use bip_text to update a text field" do 
    @user.save! 
    visit user_path(@user) 
    within("#email") do 
     page.should have_content("[email protected]") 
    end 

    bip_text @user, :email, "[email protected]" 

    visit user_path(@user) 
    within("#email") do 
     page.should have_content("[email protected]") 
    end 
    end 

https://github.com/dougc84/best_in_place/blob/master/spec/integration/js_spec.rb

쉽게 보인다. 그것은 너무 빨리 나는 거의 아무 것도 볼 수 있어요

before (:each) do 
    @report = FactoryGirl.create(:report) 
    visit report_path(@report) 
    end 
    it "name", :focus do 
    within("#name") do 
     page.should have_content @report.name 
    end 
    bip_text @report, :name, "new name" 
    visit report_path(@report) 
    within("#name") do 
     page.should have_content "new name" 
    end 
    end 

하지만 # NAME 필드 뭔가를 않는 것 같습니다 :

그래서 난 내 카피 바라 사양에 복사됩니다. 그러면 페이지가 다시로드되고 여전히 오래된 값입니다.

어떤 도움이 필요합니까?

오 btw 브라우저에서 작동합니다. 테스트를 통과 할 수 없습니다.

답변

0

sleep 1 전후에 bip_ 도우미가 추가되어 작동했습니다.

0

bip_text에 의해 실행되는 자바 스크립트는 비동기식이지만 다음 라인에서는 즉시 다른 페이지로 이동하여 자바 스크립트를 끝내지 않도록합니다. 이것이 귀하의 sleep 1에서 수정 된 이유입니다. 또한 Capybara가 visit report_path 전에 새로운 콘텐츠를 기다리게함으로써 문제를 해결할 수 있지만 성공 메시지 (예 : ajax:success JS 콜백 포함)를 페이지에 써야합니다.