{"action":"created","issue":{"url":"https://api.github.com/repos/nevir/rubocop-rspec/issues/94","repository_url":"https://api.github.com/repos/nevir/rubocop-rspec","labels_url":"https://api.github.com/repos/nevir/rubocop-rspec/issues/94/labels{/name}","comments_url":"https://api.github.com/repos/nevir/rubocop-rspec/issues/94/comments","events_url":"https://api.github.com/repos/nevir/rubocop-rspec/issues/94/events","html_url":"https://github.com/nevir/rubocop-rspec/issues/94","id":154578103,"number":94,"title":"Cop suggestion: Detect unnecessary usage of `let!`","user":{"login":"andyw8","id":13400,"avatar_url":"https://avatars.githubusercontent.com/u/13400?v=3","gravatar_id":"","url":"https://api.github.com/users/andyw8","html_url":"https://github.com/andyw8","followers_url":"https://api.github.com/users/andyw8/followers","following_url":"https://api.github.com/users/andyw8/following{/other_user}","gists_url":"https://api.github.com/users/andyw8/gists{/gist_id}","starred_url":"https://api.github.com/users/andyw8/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andyw8/subscriptions","organizations_url":"https://api.github.com/users/andyw8/orgs","repos_url":"https://api.github.com/users/andyw8/repos","events_url":"https://api.github.com/users/andyw8/events{/privacy}","received_events_url":"https://api.github.com/users/andyw8/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/nevir/rubocop-rspec/labels/cop","name":"cop","color":"0e8a16"},{"url":"https://api.github.com/repos/nevir/rubocop-rspec/labels/enhancement","name":"enhancement","color":"84b6eb"}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":7,"created_at":"2016-05-12T20:49:22Z","updated_at":"2016-08-30T02:00:45Z","closed_at":"2016-08-07T05:21:33Z","body":"I often come across code which uses `let!(...)` for setting up state, but then never makes any direct reference them to those identifiers. This setup should be in a `before` block, or inlined into the example's `it` block:\r\n\r\n**Bad**\r\n\r\n```ruby\r\nlet!(:my_widget) { create(:widget) }\r\n\r\nit \"...\" do\r\n  expect(Widget.count).to eq(1)\r\nend\r\n```\r\n\r\n**Good**\r\n\r\n```ruby\r\nit \"...\" do\r\n  create(:widget)\r\n  expect(Widget.count).to eq(1)\r\nend\r\n```\r\n\r\n```ruby\r\nbefore { create(:widget) }\r\n\r\nit \"...\" do\r\n  expect(Widget.count).to eq(1)\r\nend\r\n```"},"comment":{"url":"https://api.github.com/repos/nevir/rubocop-rspec/issues/comments/243311529","html_url":"https://github.com/nevir/rubocop-rspec/issues/94#issuecomment-243311529","issue_url":"https://api.github.com/repos/nevir/rubocop-rspec/issues/94","id":243311529,"user":{"login":"backus","id":2085622,"avatar_url":"https://avatars.githubusercontent.com/u/2085622?v=3","gravatar_id":"","url":"https://api.github.com/users/backus","html_url":"https://github.com/backus","followers_url":"https://api.github.com/users/backus/followers","following_url":"https://api.github.com/users/backus/following{/other_user}","gists_url":"https://api.github.com/users/backus/gists{/gist_id}","starred_url":"https://api.github.com/users/backus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/backus/subscriptions","organizations_url":"https://api.github.com/users/backus/orgs","repos_url":"https://api.github.com/users/backus/repos","events_url":"https://api.github.com/users/backus/events{/privacy}","received_events_url":"https://api.github.com/users/backus/received_events","type":"User","site_admin":false},"created_at":"2016-08-30T02:00:45Z","updated_at":"2016-08-30T02:00:45Z","body":"Before I defend the cop further I'll note that these cops are supposed to be opinionated. This is why many are configurable. You're always free to disable particular cases, disable cops for a directory, or disable them entirely.\r\n\r\nConsider the following snippet of code\r\n\r\n```ruby\r\ndef write_user\r\n  user = database.persist(user_info)\r\n\r\n  do_some_work\r\n  do_some_other_work\r\n\r\n  true\r\nend\r\n```\r\n\r\nI think this is similar to the argument you are making about an unreferenced `let!`. I'd say that this local variable assignment to `user` should be removed because it isn't being used in the rest of the method. If I wanted to add some context for that write then I'd add a comment above it. \r\n\r\nLikewise, consider this spec:\r\n\r\n```ruby\r\nlet!(:user) { database.write_user(user_info) }\r\n\r\nbefore do\r\n  do_some_work\r\n  do_some_other_work\r\nend\r\n\r\nit \"asserts something\" do\r\n  expect(something_that_depends_on_db_state).to be(true)\r\nend\r\n```\r\n\r\nI think it is odd to read over this spec, see the assignment to `user` using the `let!`, but not see any usage of `user`. Just like the other example I would instead just make the side effect happen in `before` and if I wanted to give context I would write a comment"}}
{"actor":{"display_login":"backus"}}