{"action":"created","issue":{"url":"https://api.github.com/repos/nevir/rubocop-rspec/issues/149","repository_url":"https://api.github.com/repos/nevir/rubocop-rspec","labels_url":"https://api.github.com/repos/nevir/rubocop-rspec/issues/149/labels{/name}","comments_url":"https://api.github.com/repos/nevir/rubocop-rspec/issues/149/comments","events_url":"https://api.github.com/repos/nevir/rubocop-rspec/issues/149/events","html_url":"https://github.com/nevir/rubocop-rspec/issues/149","id":169092710,"number":149,"title":"Add a `OneExpectation` cop asserting no more than `expect` per test","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},"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":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2016-08-03T09:55:46Z","updated_at":"2016-08-03T19:34:57Z","closed_at":null,"body":"Aim for one assertion per test.\r\n\r\n### Bad\r\n\r\n```ruby\r\nit 'creates a new user' do\r\n  user = create_user(attributes)\r\n\r\n  expect(user.name).to eql('John')\r\n  expect(user.age).to  eql(22)\r\n  expect(user.role).to eql(:admin)\r\nend\r\n```\r\n\r\n### OK\r\n\r\n```ruby\r\nsubject { create_user }\r\n\r\nits(:name) { should eql('John') }\r\nits(:age)  { should eql(22)     }\r\nits(:role) { should eql(:admin) }\r\n```\r\n\r\n### OK\r\n\r\n```ruby\r\nit 'creates a new user' do\r\n  expect(create_user(attributes)).to have_attributes(\r\n    name: 'John',\r\n    age:  22,\r\n    role: :admin\r\n  )\r\nend\r\n```\r\n\r\n### Better\r\n\r\n```ruby\r\nit 'creates a new user' do\r\n  expect(create_user(attributes)).to eql(\r\n    User.new(\r\n      name: 'John',\r\n      age:  22,\r\n      role: :admin\r\n    )\r\n  )\r\nend\r\n```\r\n\r\nExtracted from #40 (thanks @agrimm)"},"comment":{"url":"https://api.github.com/repos/nevir/rubocop-rspec/issues/comments/237346842","html_url":"https://github.com/nevir/rubocop-rspec/issues/149#issuecomment-237346842","issue_url":"https://api.github.com/repos/nevir/rubocop-rspec/issues/149","id":237346842,"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-03T19:34:57Z","updated_at":"2016-08-03T19:34:57Z","body":"Now we could track the number of methods inside of a test that are exactly `expect` and we could have an option that also looks for methods that contain the word `expect` or `assert` (so `expect_violation` would match). Basically though I'm just noting that it is impossible to do the \"exactly one test\" check perfect but we can employ a set of hacks / heuristics like these. This is the reality of static analysis with ruby though"}}
{"actor":{"display_login":"backus"}}