FactoryGirl助手导致Heroku失败

时间:2015-01-31 02:56:58

标签: ruby-on-rails ruby-on-rails-3 heroku factory-bot

我的Heroku应用程序崩溃是因为缺少帮助文件助手/ factory_girl.rb',即使它适用于本地 FactoryGirl仅安装在我的Gemfile测试组中

  1. 为什么Heroku在开发时不需要我的FactoryGirl帮助器并且没有被指定为生产宝石?
  2. helpers/factory_girl.rb应该是什么样子?我在网上搜索,找不到任何东西。一个完全空白的文件会起作用吗?
  3. 我正在运行Rails 3.2.13,Ruby 2.0.0-p481和factory_girl_rails 4.4.1。

    的Gemfile:

    group :test do
      gem "factory_girl_rails", ">= 4.0"
    end
    

    Heroku日志:

    2015-01-31T02:16:01.071477+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:317:in `rescue in depend_on': Missing helper file helpers/factory_girl.rb (LoadError)
    2015-01-31T02:16:01.071484+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:312:in `depend_on'
    2015-01-31T02:16:01.071515+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.13/lib/abstract_controller/helpers.rb:135:in `block in modules_for_helpers'
    2015-01-31T02:16:01.071524+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.13/lib/abstract_controller/helpers.rb:131:in `modules_for_helpers'
    2015-01-31T02:16:01.071522+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.13/lib/abstract_controller/helpers.rb:131:in `map!'
    2015-01-31T02:16:01.071487+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:225:in `require_dependency'
    2015-01-31T02:16:01.071526+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.13/lib/action_controller/metal/helpers.rb:92:in `modules_for_helpers'
    2015-01-31T02:16:01.071530+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.13/lib/action_controller/railties/paths.rb:18:in `block (2 levels) in with'
    2015-01-31T02:16:01.071533+00:00 app[web.1]:    from /app/app/controllers/application_controller.rb:4:in `<top (required)>'
    2015-01-31T02:16:01.071535+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `require'
    2015-01-31T02:16:01.071537+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `block in require'
    2015-01-31T02:16:01.071528+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.13/lib/abstract_controller/helpers.rb:95:in `helper'
    2015-01-31T02:16:01.071538+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:236:in `load_dependency'
    2015-01-31T02:16:01.071540+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `require'
    2015-01-31T02:16:01.071581+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `require'
    2015-01-31T02:16:01.071570+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:502:in `load_missing_constant'
    2015-01-31T02:16:01.071572+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:192:in `block in const_missing'
    2015-01-31T02:16:01.071574+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:190:in `each'
    2015-01-31T02:16:01.071576+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:190:in `const_missing'
    2015-01-31T02:16:01.071583+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_suppor
    t/dependencies.rb:251:in `block in require'
    2015-01-31T02:16:01.071578+00:00 app[web.1]:    from /app/app/controllers/activations_controller.rb:1:in `<top (required)>'
    2015-01-31T02:16:01.071550+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:359:in `require_or_load'
    2015-01-31T02:16:01.071647+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/engine.rb:436:in `eager_load!'
    2015-01-31T02:16:01.071633+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/engine.rb:439:in `block (2 levels) in eager_load!'
    2015-01-31T02:16:01.071622+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:236:in `load_dependency'
    2015-01-31T02:16:01.071625+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `require'
    2015-01-31T02:16:01.071627+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:359:in `require_or_load'
    2015-01-31T02:16:01.071629+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:313:in `depend_on'
    2015-01-31T02:16:01.071631+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:225:in `require_dependency'
    2015-01-31T02:16:01.071640+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/engine.rb:438:in `each'
    2015-01-31T02:16:01.071642+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/engine.rb:438:in `block in eager_load!'
    2015-01-31T02:16:01.071644+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/engine.rb:436:in `each'
    2015-01-31T02:16:01.071648+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/application/finisher.rb:53:in `block in <module:Finisher>'
    2015-01-31T02:16:01.071654+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/initializable.rb:55:in `block in run_initializers'
    2015-01-31T02:16:01.071650+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/initializable.rb:30:in `instance_exec'
    2015-01-31T02:16:01.071652+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/initializable.rb:30:in `run'
    2015-01-31T02:16:01.071656+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/initializable.rb:54:in `each'
    2015-01-31T02:16:01.071658+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/initializable.rb:54:in `run_initializers'
    2015-01-31T02:16:01.071659+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/application.rb:136:in `initialize!'
    2015-01-31T02:16:01.071661+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/railtie/configurable.rb:30:in `method_missing'
    2015-01-31T02:16:01.071688+00:00 app[web.1]:    from /app/config/environment.rb:5:in `<top (required)>'
    2015-01-31T02:16:01.071690+00:00 app[web.1]:    from /app/config.ru:3:in `require'
    2015-01-31T02:16:01.071692+00:00 app[web.1]:    from /app/config.ru:3:in `block in <main>'
    2015-01-31T02:16:01.071693+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/lib/rack/builder.rb:51:in `instance_eval'
    2015-01-31T02:16:01.071695+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/lib/rack/builder.rb:51:in `initialize'
    2015-01-31T02:16:01.071698+00:00 app[web.1]:    from /app/config.ru:1:in `new'
    2015-01-31T02:16:01.071699+00:00 app[web.1]:    from /app/config.ru:1:in `<main>'
    2015-01-31T02:16:01.071701+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/thin-1.6.2/lib/rack/adapter/loader.rb:33:in `eval'
    2015-01-31T02:16:01.071703+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/thin-1.6.2/lib/rack/adapter/loader.rb:33:in `load'
    2015-01-31T02:16:01.071705+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/thin-1.6.2/lib/rack/adapter/loader.rb:42:in `for'
    2015-01-31T02:16:01.071707+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/thin-1.6.2/lib/thin/controllers/controller.rb:170:in `load_adapter'
    2015-01-31T02:16:01.071709+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/thin-1.6.2/lib/thin/controllers/controller.rb:74:in `start'
    2015-01-31T02:16:01.071711+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/thin-1.6.2/lib/thin/runner.rb:199:in `run_command'
    2015-01-31T02:16:01.071713+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/thin-1.6.2/lib/thin/runner.rb:155:in `run!'
    2015-01-31T02:16:01.071715+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/thin-1.6.2/bin/thin:6:in `<top (required)>'
    2015-01-31T02:16:01.071717+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/bin/thin:19:in `load'
    2015-01-31T02:16:01.071719+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/bin/thin:19:in `<main>'
    2015-01-31T02:16:01.971364+00:00 heroku[web.1]: Process exited with status 1
    2015-01-31T02:16:01.976052+00:00 heroku[web.1]: State changed from starting to crashed
    

1 个答案:

答案 0 :(得分:0)

我认为heroku的RAILS_ENV 生产如下所示。

$ heroku config                                                                                                                                                                                   
=== app_name Config Vars
CLEARDB_DATABASE_URL: mysql://...
DATABASE_URL:         mysql2://...
LANG:                 en_US.UTF-8
RACK_ENV:             production
RAILS_ENV:            production
SECRET_KEY_BASE:      ....

这就是为什么测试组中的factory_girl在heroku上运行不正常的原因。 解决方案之一就是添加生产组。但是,这不是一个好主意。

group :test, :production do
  gem "factory_girl_rails", ">= 4.0"
end

我想如果你只是在heroku上加载测试数据进行测试,我建议如下。

# run to load test data
rake db:data_import

# test data import rake file
# deta_import.rb
if Rails.env.production?
  require "factory_girl_rails"
  FactoryGirl.find_definitions
end
... test data import with FactoryGirl ...
相关问题