【发布时间】:2015-08-11 20:25:52
【问题描述】:
知道如何为从 xlsx gem 生成的 xlsx 文件编写视图规范(是否存在标题、行等)?不确定我是否一开始就做对了,但这就是我目前所拥有的
RSpec.describe "spreadsheet.xlsx.axlsx", :type => :view do
...
it "should have header Books" do
assign(:spreadsheet, spreadsheet)
render
# rendered.rows[0].cells.map(&:value).should include "Books"
end
end
在窥探中,rendered 在一个 utf-8 编码的字符串中,我不确定如何解析标头等。
=> "PK\u0003\u0004\u0014\u0000\u0000\u0000\b\u0000\u0000\u0000!\xECc8k\xD4\
有没有办法像测试 html 视图一样测试生成的 xlsx 文件?
类似...
it "has header Books" do
assign(:worksheet, worksheet)
render
expect(rendered).to have_xpath("(//table)[1]/thead/tr/td", :text => "Books")
end
提前致谢!
【问题讨论】:
标签: ruby-on-rails ruby excel rspec axlsx