{"action":"created","issue":{"url":"https://api.github.com/repos/thoughtbot/factory_girl/issues/923","repository_url":"https://api.github.com/repos/thoughtbot/factory_girl","labels_url":"https://api.github.com/repos/thoughtbot/factory_girl/issues/923/labels{/name}","comments_url":"https://api.github.com/repos/thoughtbot/factory_girl/issues/923/comments","events_url":"https://api.github.com/repos/thoughtbot/factory_girl/issues/923/events","html_url":"https://github.com/thoughtbot/factory_girl/issues/923","id":162154801,"number":923,"title":"Documentation for running FactoryGirl.lint in before(:suite)","user":{"login":"Ross-Hunter","id":243033,"avatar_url":"https://avatars.githubusercontent.com/u/243033?v=3","gravatar_id":"","url":"https://api.github.com/users/Ross-Hunter","html_url":"https://github.com/Ross-Hunter","followers_url":"https://api.github.com/users/Ross-Hunter/followers","following_url":"https://api.github.com/users/Ross-Hunter/following{/other_user}","gists_url":"https://api.github.com/users/Ross-Hunter/gists{/gist_id}","starred_url":"https://api.github.com/users/Ross-Hunter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Ross-Hunter/subscriptions","organizations_url":"https://api.github.com/users/Ross-Hunter/orgs","repos_url":"https://api.github.com/users/Ross-Hunter/repos","events_url":"https://api.github.com/users/Ross-Hunter/events{/privacy}","received_events_url":"https://api.github.com/users/Ross-Hunter/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2016-06-24T14:04:38Z","updated_at":"2016-06-24T17:10:04Z","closed_at":"2016-06-24T14:11:58Z","body":"So it's not recommended to run `FactoryGirl.lint` in a `before :suite` because it will slow down running individual tests, but RSpec can be configured to not run linting if only running an individual test using `config.files_to_run.one?`.\r\n\r\n```ruby\r\n# spec/spec_helper.rb\r\nconfig.before :suite do\r\n  DatabaseCleaner.strategy = :transaction\r\n  DatabaseCleaner.clean_with :truncation\r\n\r\n  begin\r\n    DatabaseCleaner.start\r\n    FactoryGirl.lint unless config.files_to_run.one?\r\n  ensure\r\n    DatabaseCleaner.clean\r\n  end\r\nend\r\n```\r\n\r\nThis is simpler for my use case (and probably many others) than setting it up as a separate task. However I can only confirm that this works with the latest Rspec, while the separate task doesn't even need to be 'compatible' with a test suite.\r\n\r\nShould I try to add this to the documentation, or should I just write a blog post about it? Seems like it would be helpful to a lot of people, but it might be more confusing overall than just sticking to the separate task as the recommended linting configuration."},"comment":{"url":"https://api.github.com/repos/thoughtbot/factory_girl/issues/comments/228403841","html_url":"https://github.com/thoughtbot/factory_girl/issues/923#issuecomment-228403841","issue_url":"https://api.github.com/repos/thoughtbot/factory_girl/issues/923","id":228403841,"user":{"login":"myronmarston","id":49391,"avatar_url":"https://avatars.githubusercontent.com/u/49391?v=3","gravatar_id":"","url":"https://api.github.com/users/myronmarston","html_url":"https://github.com/myronmarston","followers_url":"https://api.github.com/users/myronmarston/followers","following_url":"https://api.github.com/users/myronmarston/following{/other_user}","gists_url":"https://api.github.com/users/myronmarston/gists{/gist_id}","starred_url":"https://api.github.com/users/myronmarston/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/myronmarston/subscriptions","organizations_url":"https://api.github.com/users/myronmarston/orgs","repos_url":"https://api.github.com/users/myronmarston/repos","events_url":"https://api.github.com/users/myronmarston/events{/privacy}","received_events_url":"https://api.github.com/users/myronmarston/received_events","type":"User","site_admin":false},"created_at":"2016-06-24T17:10:04Z","updated_at":"2016-06-24T17:10:04Z","body":"FWIW, `config.files_to_run` predates my involvement in RSpec (which started in 2010-11, IIRC), so it's definitely a long-term, stable API.  Our generated `spec_helper.rb` does something similar with `files_to_run.one?`:\r\n\r\nhttps://github.com/rspec/rspec-core/blob/v3.4.4/lib/rspec/core/project_initializer/spec/spec_helper.rb#L69-L77\r\n\r\n> As an aside - if there's literally only one test (weird situation, I know!), would this get run? (More for my personal understanding than anything else 😄)\r\n\r\nYes.  The `before(:suite)` hook always gets invoked before the first spec is run, regardless of how many specs have been loaded."}}
{"actor":{"display_login":"myronmarston"}}