2014-08-28 3 views
0

권장 레일북 (agile-web-development-with-rails-4_p2_0.pdf)을 읽고 있는데 아래 코드에 대한 간단한 질문이 있습니다.레일 4 컨트롤러 테스트 - get : index에서 html을 선택하는 방법은 무엇입니까?

class StoreControllerTest < ActionController::TestCase 
    test "should get index" do 
    get :index 
    assert_response :success 
    assert_select '#columns #side a', minimum: 4 
    assert_select '#main .entry', 3 
    assert_select 'h3', 'Programming Ruby 1.9' 
    assert_select '.price', /\$[,\d]+\.\d\d/ 
    end 

end 

주장의 노하우가 매개 변수로 해당 데이터를 사용하여 어떻게 get :index 방법을 판매? ActionController :: TestCase의 뒤에서 어떤 종류의 마법이 발생합니까? 내부적으로

답변

1

기능 테스트에서 "get"또는 "post"메소드를 사용하면 테스트 관련 변수가 채워집니다. 예를 들어, Assert-response는 @response 변수를보고 있는데, GET 요청에 대한 서버의 응답 텍스트가 포함되어 있으며 기능 테스트에서 get 또는 post을 호출 할 때마다 채워집니다.

2

assert_select 그냥에 대한 요청을 한 후 생성 @response 변수 클래스에 액세스하고 @response.body을 호출하고 테스트 response_from_page_or_css

에게 전화를한다.

어떻게 구현되는지 보려면 apidock.com 페이지에서 "Show Source"링크를 클릭하십시오.

관련 문제