2011-03-08 2 views
1

Capybara로 이전 중입니다. 내가 가진 문제 중 하나는 PDF 단계를 마이그레이션하는 것입니다.Webrat에서 일하는 Capybara의 페이지/respone.body 설정하기

이 단계에서는 page.body를 구문 분석 된 PDF로 설정합니다. 그런 식으로 기본 오이 단계를 사용할 수 있습니다.

When 'I follow the PDF link "$label"' do |label| 
    click_link(label) 
    page.body = PDF::Inspector::Text.analyze(page.body).strings.join(" ") 
end 

예.

When I follow the PDF link "Catalogue" 
Then I should see "Cheap products" 

내가 오류이 하나입니다

undefined method `body=' for #<Capybara::`enter code here`Document> (NoMethodError) 

답변

1

는 카피 바라의 소스에 정의 된 몸에 대한 세터가 없다, 그래서 당신은 그런 외부 적으로 설정할 수 없습니다. 이 (안된) 시도 :

page.instance_variable_set(:@body, PDF::Inspector::Text.analyze(page.body).strings.join(" ")) 
+0

당신의 대답은 작동하지 않았지만 올바른 방향으로 이끌었습니다. 나는 'page'를 'page.driver'로 바꾸었다. 감사 ! –

0

이 나를 위해 일한 : 내가 위에 내 PDF 인라인

pdf = DocumentPdf.new(@document) 
send_data pdf.render, :filename => "document_#{@document.created_at.strftime("%Y-%m-%d")}", 
    :type => "application/pdf", 
    :disposition => "inline" 
2

를 제공하고 있습니다

Then /^I should be served the document as a PDF$/ do 
    page.response_headers['Content-Type'].should == "application/pdf" 
    pdf = PDF::Inspector::Text.analyze(page.source).strings.join(" ") 
    page.driver.response.instance_variable_set('@body', pdf) 
end 

Then /^I should see the document details$/ do 
    page.should have_content("#{@document.customer.name}") 
    page.should have_content("#{@document.resources.first.resource.name}") 
    page.should have_content("Document opened at #{@document.created_at.strftime("%e-%b-%4Y %r")}") 
end 

주, 당신이 같은 :js => true 설정하기 이 :

scenario 'do something', :js => true do 
    str = PDF::Inspector::Text.analyze(page.body).strings.join(" ") # or whatever string you want 
    # then just use javascript to edit or add the body 
    page.evaluate_script("document.write(#{str});") 
end 

이제 이것은 운전자에 달려 있지만, 그것은 하나의 해결책입니다 ...

+1

나는 이것이 내 첫 번째 대답이라는 것을 알고 있지만 오랫동안 숨어 있었다. 건배 – bentael