首页 > 解决方案 > Rails 5 升级 - 控制器测试失败

问题描述

我对 Rails 相当陌生,并且刚刚开始从事一个需要从 Rails 4.2 更新到 Rails 5 的大型项目。我以前从未使用过很多 RSpec,并且在尝试升级时遇到了一些失败的测试。

测试的代码是:

describe "#index " do
  it 'should return all plots associated to a purchaser' do
    sign_in @user

    get purchaser_plots_path(format: :json), params: {}, flash: {'Accept' => Mime::JSON}

    _(response.status).must_equal 200
    json = JSON.parse(response.body)
    _(json.count).must_equal 2
    _(json.first['id']).must_equal @plot_2.id
    _(json.second['id']).must_equal @plot_1.id
  end

  it 'should paginate' do
    sign_in @user

    get purchaser_plots_path(format: :json), params: {page: 1, per_page: 1}, flash: {'Accept' => Mime::JSON}
    _(response.status).must_equal 200
    json = JSON.parse(response.body)
    _(json.count).must_equal 1
    _(json.first['id']).must_equal @plot_2.id

    get purchaser_plots_path(format: :json), params: {page: 2, per_page: 1}, flash: {'Accept' => Mime::JSON}
    _(response.status).must_equal 200
    json = JSON.parse(response.body)
    _(json.count).must_equal 1
    _(json.first['id']).must_equal @plot_1.id
  end
end

这给了我以下错误:

Error:
PurchaserPlotControllerTest::#index #test_0001_should return all plots associated to a purchaser:
ArgumentError: unknown keyword: flash
    test/controllers/purchaser/plots_controller_test.rb:21:in `block (2 levels) in <class:PurchaserPlotControllerTest>'

我在网上找到的所有帮助似乎都表明“flash”是一个允许的关键字参数,所以我不确定我做错了什么!

任何帮助将不胜感激。

标签: ruby-on-railstestingrspecruby-on-rails-5

解决方案


推荐阅读