ruby-on-rails – Rspec 3.6,Rails 5错误:`post`请求的参数数量错误(给定2,预期1)

栏目: Ruby · 发布时间: 7年前

内容简介:翻译自:https://stackoverflow.com/questions/44169583/rspec-3-6-rails-5-error-wrong-number-of-arguments-given-2-expected-1-for-p

我刚刚在Rails 5中开始了一个新项目(我的第一个,虽然我在Rails 4.x中有几个项目)并且我在控制器规格方面遇到了麻烦.

describe RequestsController, :type => :controller do

  it "receives new request" do
    post :accept_request, my_params
  end

end

返回错误:

Failure/Error: post :accept_request, my_params

 ArgumentError:
   wrong number of arguments (given 2, expected 1)

据我所知,对于带有Rails 5的控制器的首选测试策略已经发生了转变,如 Everyday Rails 所述,具体而言,将控制器测试转换为请求规范,但没有说明这种控制器测试基本方法的变化.

似乎Rails 5需要关键字参数而不是散列参数,这是对以前版本的改变.此外,第一个参数是URL而不是操作.尝试
post some_url, params: some_hash

翻译自:https://stackoverflow.com/questions/44169583/rspec-3-6-rails-5-error-wrong-number-of-arguments-given-2-expected-1-for-p


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Probability and Computing: Randomization and Probabilistic Techn

Probability and Computing: Randomization and Probabilistic Techn

Michael Mitzenmacher、Eli Upfal / Cambridge University Press / 2017-7-3 / USD 62.23

Greatly expanded, this new edition requires only an elementary background in discrete mathematics and offers a comprehensive introduction to the role of randomization and probabilistic techniques in m......一起来看看 《Probability and Computing: Randomization and Probabilistic Techn》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具