{"action":"opened","issue":{"url":"https://api.github.com/repos/SciMed/style-guide/issues/63","repository_url":"https://api.github.com/repos/SciMed/style-guide","labels_url":"https://api.github.com/repos/SciMed/style-guide/issues/63/labels{/name}","comments_url":"https://api.github.com/repos/SciMed/style-guide/issues/63/comments","events_url":"https://api.github.com/repos/SciMed/style-guide/issues/63/events","html_url":"https://github.com/SciMed/style-guide/issues/63","id":340360858,"node_id":"MDU6SXNzdWUzNDAzNjA4NTg=","number":63,"title":"New classes in specs","user":{"login":"andycandrea","id":5621517,"node_id":"MDQ6VXNlcjU2MjE1MTc=","avatar_url":"https://avatars0.githubusercontent.com/u/5621517?v=4","gravatar_id":"","url":"https://api.github.com/users/andycandrea","html_url":"https://github.com/andycandrea","followers_url":"https://api.github.com/users/andycandrea/followers","following_url":"https://api.github.com/users/andycandrea/following{/other_user}","gists_url":"https://api.github.com/users/andycandrea/gists{/gist_id}","starred_url":"https://api.github.com/users/andycandrea/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andycandrea/subscriptions","organizations_url":"https://api.github.com/users/andycandrea/orgs","repos_url":"https://api.github.com/users/andycandrea/repos","events_url":"https://api.github.com/users/andycandrea/events{/privacy}","received_events_url":"https://api.github.com/users/andycandrea/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-07-11T18:44:21Z","updated_at":"2018-07-11T18:44:21Z","closed_at":null,"author_association":"MEMBER","body":"Occasionally, I'll come across something like:\r\n\r\n```ruby\r\nclass SomeThingForTests\r\n  ...\r\nend\r\n```\r\n\r\nin specs. We're good about prefixing them with a namespace or prefix to minimize the likelihood of colliding with an object defined in the app, but, as we're still adding a new named class, the possibility of a collision, however slight, does still exist. A few approaches I've thought of that might be good:\r\n\r\n1. Use anonymous classes, e.g.\r\n\r\n```ruby\r\n# Bad\r\nclass SomeThingForTests; end\r\n\r\n# Good\r\nlet(:some_thing_for_tests) { Class.new }\r\n```\r\n\r\n2. Use `OpenStruct`\r\n\r\n```ruby\r\n# Bad\r\nclass SomeThing\r\n  def self.some_method\r\n    'foo'\r\n  end\r\nend\r\n\r\n# Good\r\nlet(:some_thing) { OpenStruct.new(some_method: 'foo') } \r\n```\r\n\r\n3. Use `instance_double`\r\n\r\n```ruby\r\n# Bad\r\nclass SomeThing; end\r\n\r\n# Good\r\nlet(:some_thing) { instance_double 'Class' }\r\n```\r\n\r\nAny preferences/thoughts?"}}
{"actor":{"display_login":"andycandrea"}}