ruby-on-rails - rspec rails 6 控制器
问题描述
我使用 rails 6 创建了一个新项目,但无法使用 rspec 3.8 或 3.9.0.pre 测试许多控制器,例如这个测试:
it 'OK' do
get :index
expect(response).to be_ok
end
提高
Failure/Error: render template: 'rig_masters/index'
ActionView::Template::Error:
wrong number of arguments (given 2, expected 1)
如果我有一个呈现json的控制器,它会通过,例如,如果控制器是
def index
@components = Component.recent
render json: @components
end
测试通过
但是如果我尝试渲染一个像
def index
@components = Component.recent
end
甚至
def index
@components = Component.recent
render template: 'components/index'
end
引发ActionView::Template::Error: wrong number of arguments (given 2, expected 1)
错误
任何帮助使这些测试通过将不胜感激。
解决方案
RSpec 还不兼容 Rails 6。但是,您可以使用 rspec-rails 4.0.0.beta2,它将解决此特定问题!
推荐阅读
- python-3.x - 如何修复'stderr:kivy.factory.FactoryException:未知类
' kivy-python 中的错误 - python - numpy.rint 和 numpy.round 之间的区别
- angular - 如何从AngularFire2中的列表中检索特定值
- python - OpenCV 帧与 numpy 切片不一致
- artificial-intelligence - 弧一致性的例子并不意味着可满足性
- android - 来自片段时,android工具栏颜色变为蓝色
- python - 根据先前列的集合创建多个新列(更有效)
- c# - 将字符串转换为不活动的游戏对象
- c# - Xamarin Forms - ListView 中项目上的 PanGestureRecognizer 逐步影响下一个隐藏项目
- php - Laravel 重定向到主域