且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用Capybara下载CSV

更新时间:2022-01-31 05:01:49

我一直在使用 MiniTest :: Spec 并做到了webkit-driver,但应该可以毫无问题地转换为RSpec,因为它基本上只是Capybara的功​​能:

I have been using MiniTest::Spec for this and did it with the webkit-driver, but it should translate to RSpec without a problem as it is basically just Capybara functionality:

scenario "download overview" do
  within "aside#actions" do
    click_link "Download overview"
  end
  page.status_code.must_equal 200
  page.response_headers['Content-Type'].must_equal "text/csv"
  page.response_headers['Content-Disposition'].must_match /attachment; filename="Übersicht.*\.csv/
  page.must_have_content "Schubidu"
  page.must_have_content "U13"
  page.wont_have_content "5000"
end

我没有详细介绍数据的格式,但是应该有的记录在那里那些不应该被排除在外的(当然,这只是一个很小的数据集,可以使测试迅速进行。)

I did not go into details about the format of the data, but the records that should have been there were there and the ones that should not have been left out (of course this was just a small dataset to keep the tests swift).