Ruby on rails 4 测试生成的对虾pdf是否没有错误
使用rails minitest和capybara如何测试pdf页面是否创建时没有错误?我认为检查状态代码是最简单的,但不确定水豚是否支持这一点Ruby on rails 4 测试生成的对虾pdf是否没有错误,ruby-on-rails-4,capybara,prawn,minitest,Ruby On Rails 4,Capybara,Prawn,Minitest,使用rails minitest和capybara如何测试pdf页面是否创建时没有错误?我认为检查状态代码是最简单的,但不确定水豚是否支持这一点 scenario "opens pdf without errors" do visit progress_report_path(format: 'pdf') page.must_have_status_code(200) end 我知道水豚没有一个“必须有状态码”的方法……但是,这说明了我想要实现的目标 如何在rails minitest
scenario "opens pdf without errors" do
visit progress_report_path(format: 'pdf')
page.must_have_status_code(200)
end
我知道水豚没有一个“必须有状态码”的方法……但是,这说明了我想要实现的目标
如何在rails minitest capybara中测试状态代码?或者,我如何测试pdf页面是否由prawn生成且没有错误?我已使用此测试pdf下载:
visit '/reports/summary.pdf'
page.status_code.must_equal 200
content_disposition = page.driver.response.headers['Content-Disposition']
content_disposition.must_include 'filename="summary.pdf"'
# the following assertions are mostly equivalent, pick what suits your style best
# I benchmarked them each 5 million times with a small pdf:
# starts_with, ends_with: 0.000046
# must_includes: 0.000080
# regex 0.000111
assert page.body.starts_with? "%PDF-1.4"
assert page.body.ends_with? "%EOF\n"
page.body.must_include '%PDF-1.4'
page.body.must_include '%EOF'
page.body.must_match /\A%PDF-1\.4.*%EOF\n\z/m