{"action":"created","comment":{"url":"https://api.github.com/repos/thoughtbot/factory_bot/pulls/comments/217755977","pull_request_review_id":155551891,"id":217755977,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIxNzc1NTk3Nw==","diff_hunk":"@@ -167,7 +167,9 @@\n \n   context \"factory outside of scope\" do\n     subject     { FactoryBot.create(:user_without_admin_scoping) }\n-    it { expect { subject }.to raise_error(ArgumentError, \"Trait not registered: admin_trait\") }\n+    it {\n+      expect { subject }.to raise_error(KeyError, \"Trait not registered: admin_trait\")","path":"spec/acceptance/traits_spec.rb","position":6,"original_position":6,"commit_id":"3a78043157d1b20c76c7f2d26cb3958222625993","original_commit_id":"3a78043157d1b20c76c7f2d26cb3958222625993","user":{"login":"houndci-bot","id":6697940,"node_id":"MDQ6VXNlcjY2OTc5NDA=","avatar_url":"https://avatars0.githubusercontent.com/u/6697940?v=4","gravatar_id":"","url":"https://api.github.com/users/houndci-bot","html_url":"https://github.com/houndci-bot","followers_url":"https://api.github.com/users/houndci-bot/followers","following_url":"https://api.github.com/users/houndci-bot/following{/other_user}","gists_url":"https://api.github.com/users/houndci-bot/gists{/gist_id}","starred_url":"https://api.github.com/users/houndci-bot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/houndci-bot/subscriptions","organizations_url":"https://api.github.com/users/houndci-bot/orgs","repos_url":"https://api.github.com/users/houndci-bot/repos","events_url":"https://api.github.com/users/houndci-bot/events{/privacy}","received_events_url":"https://api.github.com/users/houndci-bot/received_events","type":"User","site_admin":false},"body":"Metrics/LineLength: Line is too long. [86/80]","created_at":"2018-09-14T15:40:38Z","updated_at":"2018-09-14T15:40:38Z","html_url":"https://github.com/thoughtbot/factory_bot/pull/1191#discussion_r217755977","pull_request_url":"https://api.github.com/repos/thoughtbot/factory_bot/pulls/1191","author_association":"NONE","_links":{"self":{"href":"https://api.github.com/repos/thoughtbot/factory_bot/pulls/comments/217755977"},"html":{"href":"https://github.com/thoughtbot/factory_bot/pull/1191#discussion_r217755977"},"pull_request":{"href":"https://api.github.com/repos/thoughtbot/factory_bot/pulls/1191"}}},"pull_request":{"url":"https://api.github.com/repos/thoughtbot/factory_bot/pulls/1191","id":214454501,"node_id":"MDExOlB1bGxSZXF1ZXN0MjE0NDU0NTAx","html_url":"https://github.com/thoughtbot/factory_bot/pull/1191","diff_url":"https://github.com/thoughtbot/factory_bot/pull/1191.diff","patch_url":"https://github.com/thoughtbot/factory_bot/pull/1191.patch","issue_url":"https://api.github.com/repos/thoughtbot/factory_bot/issues/1191","number":1191,"state":"open","locked":false,"title":"Raise KeyError instead of ArgumentError in Registry","user":{"login":"ChrisBr","id":3799140,"node_id":"MDQ6VXNlcjM3OTkxNDA=","avatar_url":"https://avatars1.githubusercontent.com/u/3799140?v=4","gravatar_id":"","url":"https://api.github.com/users/ChrisBr","html_url":"https://github.com/ChrisBr","followers_url":"https://api.github.com/users/ChrisBr/followers","following_url":"https://api.github.com/users/ChrisBr/following{/other_user}","gists_url":"https://api.github.com/users/ChrisBr/gists{/gist_id}","starred_url":"https://api.github.com/users/ChrisBr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ChrisBr/subscriptions","organizations_url":"https://api.github.com/users/ChrisBr/orgs","repos_url":"https://api.github.com/users/ChrisBr/repos","events_url":"https://api.github.com/users/ChrisBr/events{/privacy}","received_events_url":"https://api.github.com/users/ChrisBr/received_events","type":"User","site_admin":false},"body":"to make use of did_you_mean gem for better error messages.\r\n\r\nThis will partially fix #992.\r\n\r\nHowever, there is one issue we might need consider with this solution. The did_you_mean gem only supports three different types of errors:\r\n\r\n* NotMethodError\r\n* NameError\r\n* KeyError\r\n\r\n``NoMethodError`` does not make sense. \r\n\r\nIn #992 it was discussed to use ``NameError``, however, when using a ``NameError`` it is not possible to use a customized error message like 'Factory not registered: :foobar' because did_you_mean initialized the [SpellChecker](https://github.com/yuki24/did_you_mean/blob/master/lib/did_you_mean/spell_checkers/name_error_checkers.rb#L7) depending on the error message. I think that a customized error message is essential! \r\n\r\nThis leaves us with ``KeyError`` (which I think also matches the error).\r\n\r\nBut only raising this ``KeyError`` is not enough as the did_you_mean gem makes heavily use of the ``receiver`` attribute (and for ``KeyError`` also the ``key`` attribute) to calculate the corrections (see e.g. https://github.com/yuki24/did_you_mean/blob/master/lib/did_you_mean/spell_checkers/key_error_checker.rb#L7). Unfortunately in Ruby <= 2.5 it is not possible to set the ``receiver`` and ``key`` attributes. This will be possible from Ruby 2.6 on (see https://bugs.ruby-lang.org/issues/14313).  So the only possibility I currently see is to also monkey patch the ``KeyError`` class :cry: \r\n\r\nSee my PR for a possible solution. The solution is far from perfect but a starting point for discussion. I'm also not sure if we should really monkey patch the ``KeyError`` class for better error messages (although I would like to have better error messages).\r\n\r\nHere is also an example application to demonstrate the issue:\r\n```\r\nrequire 'factory_bot'\r\n\r\nclass User\r\n  attr_accessor :name, :admin\r\n\r\n  def save!\r\n  end\r\nend\r\n\r\nFactoryBot.define do\r\n  factory :user do\r\n    name { \"John\" }\r\n    admin { false }\r\n\r\n    trait :admin do\r\n      admin { true }\r\n    end\r\n\r\n  factory :admin_user,                 :traits => [:admin]\r\n  end\r\nend\r\n\r\ndef do_with_rescue\r\n  begin\r\n    yield\r\n  rescue KeyError => e\r\n    puts e.message\r\n    puts \"===\"\r\n  end\r\nend\r\n\r\n\r\ndo_with_rescue { user = FactoryBot.create(:use) }\r\ndo_with_rescue { user = FactoryBot.create(:admin_use) }\r\ndo_with_rescue { user = FactoryBot.create(:user, :admi) }\r\n\r\n# Factory not registered use\r\n# Did you mean?  :user\r\n# ===\r\n# Factory not registered admin_use\r\n# Did you mean?  :admin_user\r\n# ===\r\n# Trait not registered admi\r\n# ===\r\n```\r\n\r\nAs you can also see, the solution only works for factories so far but not for traits. The problem with traits is that it seems to use a complete different code path and the items hash does not contain the traits but the strategies (like create, build etc.). I would need some hints how to implement this for traits as well. \r\n","created_at":"2018-09-10T21:50:25Z","updated_at":"2018-09-14T15:40:38Z","closed_at":null,"merged_at":null,"merge_commit_sha":"009eb134bba159f65aeceec56701c9e0dddef1d6","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/thoughtbot/factory_bot/pulls/1191/commits","review_comments_url":"https://api.github.com/repos/thoughtbot/factory_bot/pulls/1191/comments","review_comment_url":"https://api.github.com/repos/thoughtbot/factory_bot/pulls/comments{/number}","comments_url":"https://api.github.com/repos/thoughtbot/factory_bot/issues/1191/comments","statuses_url":"https://api.github.com/repos/thoughtbot/factory_bot/statuses/3a78043157d1b20c76c7f2d26cb3958222625993","head":{"label":"ChrisBr:feature/did_you_mean","ref":"feature/did_you_mean","sha":"3a78043157d1b20c76c7f2d26cb3958222625993","user":{"login":"ChrisBr","id":3799140,"node_id":"MDQ6VXNlcjM3OTkxNDA=","avatar_url":"https://avatars1.githubusercontent.com/u/3799140?v=4","gravatar_id":"","url":"https://api.github.com/users/ChrisBr","html_url":"https://github.com/ChrisBr","followers_url":"https://api.github.com/users/ChrisBr/followers","following_url":"https://api.github.com/users/ChrisBr/following{/other_user}","gists_url":"https://api.github.com/users/ChrisBr/gists{/gist_id}","starred_url":"https://api.github.com/users/ChrisBr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ChrisBr/subscriptions","organizations_url":"https://api.github.com/users/ChrisBr/orgs","repos_url":"https://api.github.com/users/ChrisBr/repos","events_url":"https://api.github.com/users/ChrisBr/events{/privacy}","received_events_url":"https://api.github.com/users/ChrisBr/received_events","type":"User","site_admin":false},"repo":{"id":146893917,"node_id":"MDEwOlJlcG9zaXRvcnkxNDY4OTM5MTc=","name":"factory_bot","full_name":"ChrisBr/factory_bot","owner":{"login":"ChrisBr","id":3799140,"node_id":"MDQ6VXNlcjM3OTkxNDA=","avatar_url":"https://avatars1.githubusercontent.com/u/3799140?v=4","gravatar_id":"","url":"https://api.github.com/users/ChrisBr","html_url":"https://github.com/ChrisBr","followers_url":"https://api.github.com/users/ChrisBr/followers","following_url":"https://api.github.com/users/ChrisBr/following{/other_user}","gists_url":"https://api.github.com/users/ChrisBr/gists{/gist_id}","starred_url":"https://api.github.com/users/ChrisBr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ChrisBr/subscriptions","organizations_url":"https://api.github.com/users/ChrisBr/orgs","repos_url":"https://api.github.com/users/ChrisBr/repos","events_url":"https://api.github.com/users/ChrisBr/events{/privacy}","received_events_url":"https://api.github.com/users/ChrisBr/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ChrisBr/factory_bot","description":"A library for setting up Ruby objects as test data.","fork":true,"url":"https://api.github.com/repos/ChrisBr/factory_bot","forks_url":"https://api.github.com/repos/ChrisBr/factory_bot/forks","keys_url":"https://api.github.com/repos/ChrisBr/factory_bot/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ChrisBr/factory_bot/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ChrisBr/factory_bot/teams","hooks_url":"https://api.github.com/repos/ChrisBr/factory_bot/hooks","issue_events_url":"https://api.github.com/repos/ChrisBr/factory_bot/issues/events{/number}","events_url":"https://api.github.com/repos/ChrisBr/factory_bot/events","assignees_url":"https://api.github.com/repos/ChrisBr/factory_bot/assignees{/user}","branches_url":"https://api.github.com/repos/ChrisBr/factory_bot/branches{/branch}","tags_url":"https://api.github.com/repos/ChrisBr/factory_bot/tags","blobs_url":"https://api.github.com/repos/ChrisBr/factory_bot/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ChrisBr/factory_bot/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ChrisBr/factory_bot/git/refs{/sha}","trees_url":"https://api.github.com/repos/ChrisBr/factory_bot/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ChrisBr/factory_bot/statuses/{sha}","languages_url":"https://api.github.com/repos/ChrisBr/factory_bot/languages","stargazers_url":"https://api.github.com/repos/ChrisBr/factory_bot/stargazers","contributors_url":"https://api.github.com/repos/ChrisBr/factory_bot/contributors","subscribers_url":"https://api.github.com/repos/ChrisBr/factory_bot/subscribers","subscription_url":"https://api.github.com/repos/ChrisBr/factory_bot/subscription","commits_url":"https://api.github.com/repos/ChrisBr/factory_bot/commits{/sha}","git_commits_url":"https://api.github.com/repos/ChrisBr/factory_bot/git/commits{/sha}","comments_url":"https://api.github.com/repos/ChrisBr/factory_bot/comments{/number}","issue_comment_url":"https://api.github.com/repos/ChrisBr/factory_bot/issues/comments{/number}","contents_url":"https://api.github.com/repos/ChrisBr/factory_bot/contents/{+path}","compare_url":"https://api.github.com/repos/ChrisBr/factory_bot/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ChrisBr/factory_bot/merges","archive_url":"https://api.github.com/repos/ChrisBr/factory_bot/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ChrisBr/factory_bot/downloads","issues_url":"https://api.github.com/repos/ChrisBr/factory_bot/issues{/number}","pulls_url":"https://api.github.com/repos/ChrisBr/factory_bot/pulls{/number}","milestones_url":"https://api.github.com/repos/ChrisBr/factory_bot/milestones{/number}","notifications_url":"https://api.github.com/repos/ChrisBr/factory_bot/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ChrisBr/factory_bot/labels{/name}","releases_url":"https://api.github.com/repos/ChrisBr/factory_bot/releases{/id}","deployments_url":"https://api.github.com/repos/ChrisBr/factory_bot/deployments","created_at":"2018-08-31T13:12:57Z","updated_at":"2018-08-31T13:13:00Z","pushed_at":"2018-09-14T15:40:17Z","git_url":"git://github.com/ChrisBr/factory_bot.git","ssh_url":"git@github.com:ChrisBr/factory_bot.git","clone_url":"https://github.com/ChrisBr/factory_bot.git","svn_url":"https://github.com/ChrisBr/factory_bot","homepage":"https://thoughtbot.com/open-source","size":2037,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"thoughtbot:master","ref":"master","sha":"4888e1d4ac839229a77343f314b2a2ed3f1cd5c2","user":{"login":"thoughtbot","id":6183,"node_id":"MDEyOk9yZ2FuaXphdGlvbjYxODM=","avatar_url":"https://avatars3.githubusercontent.com/u/6183?v=4","gravatar_id":"","url":"https://api.github.com/users/thoughtbot","html_url":"https://github.com/thoughtbot","followers_url":"https://api.github.com/users/thoughtbot/followers","following_url":"https://api.github.com/users/thoughtbot/following{/other_user}","gists_url":"https://api.github.com/users/thoughtbot/gists{/gist_id}","starred_url":"https://api.github.com/users/thoughtbot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thoughtbot/subscriptions","organizations_url":"https://api.github.com/users/thoughtbot/orgs","repos_url":"https://api.github.com/users/thoughtbot/repos","events_url":"https://api.github.com/users/thoughtbot/events{/privacy}","received_events_url":"https://api.github.com/users/thoughtbot/received_events","type":"Organization","site_admin":false},"repo":{"id":21829,"node_id":"MDEwOlJlcG9zaXRvcnkyMTgyOQ==","name":"factory_bot","full_name":"thoughtbot/factory_bot","owner":{"login":"thoughtbot","id":6183,"node_id":"MDEyOk9yZ2FuaXphdGlvbjYxODM=","avatar_url":"https://avatars3.githubusercontent.com/u/6183?v=4","gravatar_id":"","url":"https://api.github.com/users/thoughtbot","html_url":"https://github.com/thoughtbot","followers_url":"https://api.github.com/users/thoughtbot/followers","following_url":"https://api.github.com/users/thoughtbot/following{/other_user}","gists_url":"https://api.github.com/users/thoughtbot/gists{/gist_id}","starred_url":"https://api.github.com/users/thoughtbot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thoughtbot/subscriptions","organizations_url":"https://api.github.com/users/thoughtbot/orgs","repos_url":"https://api.github.com/users/thoughtbot/repos","events_url":"https://api.github.com/users/thoughtbot/events{/privacy}","received_events_url":"https://api.github.com/users/thoughtbot/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/thoughtbot/factory_bot","description":"A library for setting up Ruby objects as test data.","fork":false,"url":"https://api.github.com/repos/thoughtbot/factory_bot","forks_url":"https://api.github.com/repos/thoughtbot/factory_bot/forks","keys_url":"https://api.github.com/repos/thoughtbot/factory_bot/keys{/key_id}","collaborators_url":"https://api.github.com/repos/thoughtbot/factory_bot/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/thoughtbot/factory_bot/teams","hooks_url":"https://api.github.com/repos/thoughtbot/factory_bot/hooks","issue_events_url":"https://api.github.com/repos/thoughtbot/factory_bot/issues/events{/number}","events_url":"https://api.github.com/repos/thoughtbot/factory_bot/events","assignees_url":"https://api.github.com/repos/thoughtbot/factory_bot/assignees{/user}","branches_url":"https://api.github.com/repos/thoughtbot/factory_bot/branches{/branch}","tags_url":"https://api.github.com/repos/thoughtbot/factory_bot/tags","blobs_url":"https://api.github.com/repos/thoughtbot/factory_bot/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/thoughtbot/factory_bot/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/thoughtbot/factory_bot/git/refs{/sha}","trees_url":"https://api.github.com/repos/thoughtbot/factory_bot/git/trees{/sha}","statuses_url":"https://api.github.com/repos/thoughtbot/factory_bot/statuses/{sha}","languages_url":"https://api.github.com/repos/thoughtbot/factory_bot/languages","stargazers_url":"https://api.github.com/repos/thoughtbot/factory_bot/stargazers","contributors_url":"https://api.github.com/repos/thoughtbot/factory_bot/contributors","subscribers_url":"https://api.github.com/repos/thoughtbot/factory_bot/subscribers","subscription_url":"https://api.github.com/repos/thoughtbot/factory_bot/subscription","commits_url":"https://api.github.com/repos/thoughtbot/factory_bot/commits{/sha}","git_commits_url":"https://api.github.com/repos/thoughtbot/factory_bot/git/commits{/sha}","comments_url":"https://api.github.com/repos/thoughtbot/factory_bot/comments{/number}","issue_comment_url":"https://api.github.com/repos/thoughtbot/factory_bot/issues/comments{/number}","contents_url":"https://api.github.com/repos/thoughtbot/factory_bot/contents/{+path}","compare_url":"https://api.github.com/repos/thoughtbot/factory_bot/compare/{base}...{head}","merges_url":"https://api.github.com/repos/thoughtbot/factory_bot/merges","archive_url":"https://api.github.com/repos/thoughtbot/factory_bot/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/thoughtbot/factory_bot/downloads","issues_url":"https://api.github.com/repos/thoughtbot/factory_bot/issues{/number}","pulls_url":"https://api.github.com/repos/thoughtbot/factory_bot/pulls{/number}","milestones_url":"https://api.github.com/repos/thoughtbot/factory_bot/milestones{/number}","notifications_url":"https://api.github.com/repos/thoughtbot/factory_bot/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/thoughtbot/factory_bot/labels{/name}","releases_url":"https://api.github.com/repos/thoughtbot/factory_bot/releases{/id}","deployments_url":"https://api.github.com/repos/thoughtbot/factory_bot/deployments","created_at":"2008-06-03T13:55:37Z","updated_at":"2018-09-14T14:28:53Z","pushed_at":"2018-09-14T15:40:20Z","git_url":"git://github.com/thoughtbot/factory_bot.git","ssh_url":"git@github.com:thoughtbot/factory_bot.git","clone_url":"https://github.com/thoughtbot/factory_bot.git","svn_url":"https://github.com/thoughtbot/factory_bot","homepage":"https://thoughtbot.com/open-source","size":2039,"stargazers_count":6119,"watchers_count":6119,"language":"Ruby","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":1618,"mirror_url":null,"archived":false,"open_issues_count":46,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":1618,"open_issues":46,"watchers":6119,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/thoughtbot/factory_bot/pulls/1191"},"html":{"href":"https://github.com/thoughtbot/factory_bot/pull/1191"},"issue":{"href":"https://api.github.com/repos/thoughtbot/factory_bot/issues/1191"},"comments":{"href":"https://api.github.com/repos/thoughtbot/factory_bot/issues/1191/comments"},"review_comments":{"href":"https://api.github.com/repos/thoughtbot/factory_bot/pulls/1191/comments"},"review_comment":{"href":"https://api.github.com/repos/thoughtbot/factory_bot/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/thoughtbot/factory_bot/pulls/1191/commits"},"statuses":{"href":"https://api.github.com/repos/thoughtbot/factory_bot/statuses/3a78043157d1b20c76c7f2d26cb3958222625993"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"houndci-bot"}}