我在我的测试文件里遇到了鲁博克的问题。首先,这是我现在的代码:
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每次都抛出同样的错误。顺便提一下,把整个JSON放在一行也不是解决方案。有人能解释一下,正确的排列方式是什么样子,所以鲁博克对此很满意吗?
发布于 2016-09-16 11:27:10
把它改成
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解释:
由于user_url(@user)是您获得第二个param的第一个param,所以headers: @header应该与它对齐。
同样的情况也适用于第二名,你有三个配对。
https://stackoverflow.com/questions/39530324
复制相似问题