{"action":"closed","issue":{"url":"https://api.github.com/repos/thoughtbot/factory_girl/issues/631","repository_url":"https://api.github.com/repos/thoughtbot/factory_girl","labels_url":"https://api.github.com/repos/thoughtbot/factory_girl/issues/631/labels{/name}","comments_url":"https://api.github.com/repos/thoughtbot/factory_girl/issues/631/comments","events_url":"https://api.github.com/repos/thoughtbot/factory_girl/issues/631/events","html_url":"https://github.com/thoughtbot/factory_girl/issues/631","id":29593474,"number":631,"title":"`rake stats` not working after following 'Testing Your Factories First' post","user":{"login":"cimbriano","id":572697,"avatar_url":"https://avatars.githubusercontent.com/u/572697?v=3","gravatar_id":"","url":"https://api.github.com/users/cimbriano","html_url":"https://github.com/cimbriano","followers_url":"https://api.github.com/users/cimbriano/followers","following_url":"https://api.github.com/users/cimbriano/following{/other_user}","gists_url":"https://api.github.com/users/cimbriano/gists{/gist_id}","starred_url":"https://api.github.com/users/cimbriano/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cimbriano/subscriptions","organizations_url":"https://api.github.com/users/cimbriano/orgs","repos_url":"https://api.github.com/users/cimbriano/repos","events_url":"https://api.github.com/users/cimbriano/events{/privacy}","received_events_url":"https://api.github.com/users/cimbriano/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2014-03-17T19:59:21Z","updated_at":"2016-02-07T06:09:04Z","closed_at":"2016-02-07T06:09:04Z","body":"Referenced post: http://robots.thoughtbot.com/testing-your-factories-first\r\n\r\nRakefile\r\n\r\n```ruby\r\n# Add your own tasks in files placed in lib/tasks ending in .rake,\r\n# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.\r\n\r\nrequire File.expand_path('../config/application', __FILE__)\r\n\r\nMyApp::Application.load_tasks\r\n\r\n```\r\n\r\nlib/tasks/factories.rake\r\n\r\n```ruby\r\n# Part of this technique : http://robots.thoughtbot.com/post/30994874643/testing-your-factories-first\r\n# Runs factory_specs first and fails early if they don't pass,\r\n#   if they do pass then the rest of the specs are run\r\nrequire 'rspec/core/rake_task'\r\n\r\ndesc 'Run factory specs.'\r\nRSpec::Core::RakeTask.new(:factory_specs) do |t|\r\n  t.pattern = './spec/factories_spec.rb'\r\nend\r\n\r\ntask spec: :factory_specs\r\n```\r\n\r\nspec/factories_spec.rb\r\n```ruby\r\n# Technique to test is_valid on each factory\r\n#   to avoid failing lots of tests because you forgot to\r\n#   update a factory with a new model validation\r\n#\r\n# Found here : http://robots.thoughtbot.com/post/30994874643/testing-your-factories-first\r\nrequire 'spec_helper'\r\n\r\nFactoryGirl.factories.map(&:name).each do |factory_name|\r\n  describe \"The #{factory_name} factory\" do\r\n    it 'is valid' do\r\n      FactoryGirl.build(factory_name).should be_valid\r\n    end\r\n  end\r\nend\r\n```\r\n\r\nOutput of `rake stats`\r\n\r\n```\r\nrake aborted!\r\nNot a directory - ./spec/factories_spec.rb\r\n/Users/chris/.rvm/gems/ruby-2.0.0-p195/gems/railties-4.0.0/lib/rails/code_statistics.rb:40:in `open'\r\n/Users/chris/.rvm/gems/ruby-2.0.0-p195/gems/railties-4.0.0/lib/rails/code_statistics.rb:40:in `foreach'\r\n/Users/chris/.rvm/gems/ruby-2.0.0-p195/gems/railties-4.0.0/lib/rails/code_statistics.rb:40:in `calculate_directory_statistics'\r\n/Users/chris/.rvm/gems/ruby-2.0.0-p195/gems/railties-4.0.0/lib/rails/code_statistics.rb:34:in `block in calculate_statistics'\r\n/Users/chris/.rvm/gems/ruby-2.0.0-p195/gems/railties-4.0.0/lib/rails/code_statistics.rb:34:in `map'\r\n/Users/chris/.rvm/gems/ruby-2.0.0-p195/gems/railties-4.0.0/lib/rails/code_statistics.rb:34:in `calculate_statistics'\r\n/Users/chris/.rvm/gems/ruby-2.0.0-p195/gems/railties-4.0.0/lib/rails/code_statistics.rb:15:in `initialize'\r\n/Users/chris/.rvm/gems/ruby-2.0.0-p195/gems/railties-4.0.0/lib/rails/tasks/statistics.rake:21:in `new'\r\n/Users/chris/.rvm/gems/ruby-2.0.0-p195/gems/railties-4.0.0/lib/rails/tasks/statistics.rake:21:in `block in <top (required)>'\r\nTasks: TOP => stats\r\n(See full trace by running task with --trace)\r\n```\r\n\r\n"}}