{"id":674,"date":"2022-08-30T15:05:17","date_gmt":"2022-08-30T15:05:17","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/09\/factorygirl-and-devise-helpers-not-working-in-specs-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:05:17","modified_gmt":"2022-08-30T15:05:17","slug":"factorygirl-and-devise-helpers-not-working-in-specs-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/factorygirl-and-devise-helpers-not-working-in-specs-collection-of-common-programming-errors\/","title":{"rendered":"FactoryGirl and Devise helpers not working in specs-Collection of common programming errors"},"content":{"rendered":"<p>There is a known issue between Spork and FactoryGirl related to class reloading. The mechanism around this that I&#8217;ve used for years was once documented on the Spork Wiki, but has disappeard (why? &#8212; it seems to still be necessary). It&#8217;s still documented as a FactoryGirl issue report on github.<\/p>\n<p>In brief:<\/p>\n<p>In <code>Gemfile<\/code>, turn off the auto-requiring of FactoryGirl:<\/p>\n<pre><code>gem 'factory_girl_rails', '~&gt; 3.5.0', require: false\n<\/code><\/pre>\n<p>In <code>spec_helper.rb<\/code>, in the <code>each_run<\/code> block, require FactoryGirl and include the Syntax Methods:<\/p>\n<pre><code>Spork.each_run do\n  # This code will be run each time you run your specs.\n  require 'factory_girl_rails'\n\n  RSpec.configure do |config|\n    config.include FactoryGirl::Syntax::Methods\n  end\n\nend\n<\/code><\/pre>\n<p>This fixes the first error. On the second error, the Devise one, you need to run <code>sign_in<\/code> inside a <code>before<\/code> block, see below the fixes in your example. That should work for you.<\/p>\n<pre><code>describe \"GET index\" do\n  describe \"as logged in Person without Attendee record\" do\n    before do    \n      @person = create :person\n      sign_in @person\n    end\n\n    it \"redirects to Attendee new page\" do\n      visit school_programs_root\n      current_path.should == new_school_programs_attendees\n    end \n  end \nend \n<\/code><\/pre>\n<p id=\"rop\"><small>Originally posted 2013-11-09 21:23:15. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>There is a known issue between Spork and FactoryGirl related to class reloading. The mechanism around this that I&#8217;ve used for years was once documented on the Spork Wiki, but has disappeard (why? &#8212; it seems to still be necessary). It&#8217;s still documented as a FactoryGirl issue report on github. In brief: In Gemfile, turn [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-674","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/674","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=674"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/674\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=674"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=674"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=674"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}