2016-09-16 4 views
-1

テストファイルでRubocopに問題があります。Rubocop JSON:メソッド呼び出しのパラメータを複数の行にまたがって並べ替える場合

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全体を1行に入れることも解決策ではありません。 Rubocopがそれに満足しているように、正しいアライメントがどのように見えるか誰でも説明できますか?

+0

'headers:@header'はJSONではありません。' {:headers => @header} 'に相当するRubyハッシュで、ゲット。 –

答えて

0

変更し、それに

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 headers: @headerを得るためにあなたの最初のパラメータでは、次の3つのparamsを持って二位に適用されます

関連する問題