【问题标题】:Run specs on axslx generated files在 axslx 生成的文件上运行规范
【发布时间】:2014-10-07 10:17:10
【问题描述】:

我的目标是对axlsx-rails gem 生成的文件运行规范,并使用我找到的自定义 rspec 匹配器 here

在我的规范示例中,我有:

describe Statistic::CompanyTableSetsController do
  login_user # this just for Devise Auth
  it "generates a proper excel sheet" do
    ...
    get "show", format: :xlsx, id: id
    response.content_type.to_s.should eq Mime::Type.lookup_by_extension(:xlsx).to_s
  end
end

但是当我运行测试时,我得到:

Failure/Error: response.content_type.to_s.should eq Mime::Type.lookup_by_extension(:xlsx).to_s

   expected: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
        got: "text/html"

当然,我无法在其他规范示例中获得工作表...

我想我在这里错过了什么,因为在我的浏览器中,Excel工作表是正常生成的。

感谢您的帮助。

【问题讨论】:

    标签: ruby-on-rails-4 rspec axlsx


    【解决方案1】:

    如果您的请求以 xlsx 格式通过,请检查您的测试日志。您的测试应该可以正常工作。

    get 是否将format 附加为查询字符串参数?也许你需要:

    get "/company_table_sets/#{id}.xlsx"
    

    你也应该可以使用:

    response.content_type.to_s.should eq Mime::XLSX.to_s
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-11
      • 1970-01-01
      • 2021-10-24
      • 1970-01-01
      相关资源
      最近更新 更多