Cannot get factory_girl running under rails 3.0.5,unexpected tCONSTANT

后端 未结 2 1092
旧时难觅i
旧时难觅i 2021-01-04 13:13

This is my Gemfile config:

group :development, :test do
    gem \'rspec-rails\'
    gem \'factory_girl\', \'~>2.0.0.beta1\'
    gem \'factory_girl_rails\'         


        
2条回答
  •  庸人自扰
    2021-01-04 13:54

    I had the same issue, but it turns out that I simply named my file wrong (factories.rb.rb, thanks to Netbeans). I discovered a few things that would be useful to this page, though.

    1. From the getting started page. Factory girl should automatically load the following files if they exist:

      test/factories.rb
      spec/factories.rb
      test/factories/*.rb
      spec/factories/*.rb
      

      Putting the following in test_helper.rb can cause double loading:

      require 'factory_girl' Factory.find_definitions

      This caused me to get a `add_as': Already defined: error.

    2. The factory_girl_rails gem automatically loads factory_girl. It's unnecessary, but doesn't appear to have any side effects.

    3. I discovered that the FactoryGirl syntax has changed quite a bit since I first learned it in March 2011. I highly recommend everyone check out the getting started page to see some of the changes.

提交回复
热议问题