我在测试文件中遇到了 Rubocop 的问题。起初,这是我现在的代码:
should 'should show user' do
get user_url(@user),
headers: @header
assert_response :success
end
should 'should update user' do
patch user_url(@user),
params: {
data: {
attributes: {
name: @user.name
}
}
}, headers: @header
assert_response :success
end
这就是 Rubocop 错误输出:
test/controllers/users_controller_test.rb:34:9: C: Align the parameters of a method call if they span more than one line.
headers: @header
^^^^^^^^^^^^^^^^
test/controllers/users_controller_test.rb:40:9: C: Align the parameters of a method call if they span more than one line.
params: { ...
^^^^^^^^^
所以我在样式指南中搜索了 JSON 的正确对齐方式。我真的尝试了缩进和换行的每一种组合,但是 Rubocop 每次都会抛出同样的错误。Andy 顺便说一句,将整个 JSON 放在一行中也不是解决方案。任何人都可以解释一下正确的对齐方式,以便 Rubocop 对此感到满意吗?