{"action":"created","issue":{"url":"https://api.github.com/repos/bbatsov/rubocop/issues/2945","repository_url":"https://api.github.com/repos/bbatsov/rubocop","labels_url":"https://api.github.com/repos/bbatsov/rubocop/issues/2945/labels{/name}","comments_url":"https://api.github.com/repos/bbatsov/rubocop/issues/2945/comments","events_url":"https://api.github.com/repos/bbatsov/rubocop/issues/2945/events","html_url":"https://github.com/bbatsov/rubocop/issues/2945","id":140203372,"number":2945,"title":"Should Style/MultilineMethodCallIndentation allow this alignment?","user":{"login":"DMA57361","id":1375133,"avatar_url":"https://avatars.githubusercontent.com/u/1375133?v=3","gravatar_id":"","url":"https://api.github.com/users/DMA57361","html_url":"https://github.com/DMA57361","followers_url":"https://api.github.com/users/DMA57361/followers","following_url":"https://api.github.com/users/DMA57361/following{/other_user}","gists_url":"https://api.github.com/users/DMA57361/gists{/gist_id}","starred_url":"https://api.github.com/users/DMA57361/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DMA57361/subscriptions","organizations_url":"https://api.github.com/users/DMA57361/orgs","repos_url":"https://api.github.com/users/DMA57361/repos","events_url":"https://api.github.com/users/DMA57361/events{/privacy}","received_events_url":"https://api.github.com/users/DMA57361/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-03-11T14:54:20Z","updated_at":"2016-03-14T09:31:28Z","closed_at":null,"body":"## Expected behaviour\r\n\r\nWhen writing RSpec tests for a Rails app, I've written the following in a spec:\r\n\r\n```\r\nexpect { request }.to  change { SomeModel.count }.by(1)\r\n                  .and have_enqueued_job(SomeModelVerificationJob)\r\n```\r\n\r\nI have `Style/MultilineMethodCallIndentation` configured with `EnforcedStyle: aligned` and I was expecting this to be acceptable.\r\n\r\n## Actual behavior\r\n\r\nThe cop reports this line as incorrectly indented, says I should use 2 characters\r\n\r\n```\r\n~/tmp$ rubocop --only Style/MultilineMethodCallIndentation example.rb\r\nInspecting 1 file\r\nC\r\n\r\nOffenses:\r\n\r\nexample.rb:2:19: C: Use 2 (not 18) spaces for indenting an expression spanning multiple lines.\r\n                  .and have_enqueued_job(SomeModelVerificationJob)\r\n                  ^^^^\r\n\r\n1 file inspected, 1 offense detected\r\n```\r\n\r\n## Steps to reproduce the problem\r\n\r\n#### example.rb\r\n```\r\nexpect { request }.to  change { SomeModel.count }.by(1)\r\n                  .and have_enqueued_job(SomeModelVerificationJob)\r\n```\r\n#### .rubocop.yml\r\n```\r\nStyle/MultilineMethodCallIndentation:\r\n  EnforcedStyle: aligned\r\n```\r\n\r\n## RuboCop version\r\n\r\nInclude the output of `rubocop -V`:\r\n\r\n```\r\n~/tmp$ rubocop -v\r\n0.38.0\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/bbatsov/rubocop/issues/comments/196224238","html_url":"https://github.com/bbatsov/rubocop/issues/2945#issuecomment-196224238","issue_url":"https://api.github.com/repos/bbatsov/rubocop/issues/2945","id":196224238,"user":{"login":"DMA57361","id":1375133,"avatar_url":"https://avatars.githubusercontent.com/u/1375133?v=3","gravatar_id":"","url":"https://api.github.com/users/DMA57361","html_url":"https://github.com/DMA57361","followers_url":"https://api.github.com/users/DMA57361/followers","following_url":"https://api.github.com/users/DMA57361/following{/other_user}","gists_url":"https://api.github.com/users/DMA57361/gists{/gist_id}","starred_url":"https://api.github.com/users/DMA57361/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DMA57361/subscriptions","organizations_url":"https://api.github.com/users/DMA57361/orgs","repos_url":"https://api.github.com/users/DMA57361/repos","events_url":"https://api.github.com/users/DMA57361/events{/privacy}","received_events_url":"https://api.github.com/users/DMA57361/received_events","type":"User","site_admin":false},"created_at":"2016-03-14T09:31:28Z","updated_at":"2016-03-14T09:31:28Z","body":"Oh, damn, you're right. RSpec and it's fancy chaining... bah. So yes, as you say, this code is more precisely the below, and when looking at it like that it's obvious why the cop reported the layout above.\r\n\r\n    expect { request }.to( change { SomeModel.count }.by(1).and( have_enqueued_job(SomeModelVerificationJob) ) )\r\n\r\nIn that case, could you instead consider this a feature request to support this kind of layout in RSpec somehow? Not sure how you'd go about doing that reliably since it should probably be an offence elsewhere, but consider it requested.\r\n\r\n---\r\n\r\nAfter a quick poke around, it seems an alternative is to use the ampersand for compounding matchers instead of `.and`, as this is acceptable by this cop (and didn't seem to fail any others):\r\n\r\n    expect { request }.to  change { SomeModel.count }.by(1) &\r\n                           have_enqueued_job(SomeModelVerificationJob)\r\n\r\nI think I personally prefer the `.and`, so will probably just switch off this cop in the spec directory."}}