Heroku 生产环境上的 FactoryBot
FactoryBot on heroku production environment
我正在尝试在 heroku 上使用 gem FactoryBot..
在本地一切正常,正确找到工厂。
我正在尝试在 spec 文件夹之外使用工厂。
我在服务中使用它invoice.rb
:
class InvoiceService
@invoices ||= FactoryBot.build_list :invoice, 50, :with_invoice_positions
end
这是我的发票工厂的样子:
FactoryBot.define do
factory :invoice do
...
trait :with_invoice_positions do
transient do
invoice_positions_count 5
end
after(:build) do |invoice, evaluator|
...
end
end
end
end
最后一件事是 Gemfile,我将 FactoryBot 行放在 :test 组之外:
ruby '2.5.0'
source 'https://rubygems.org'
gem 'rails', '~> 5.1.4'
gem 'pg', '~> 0.18'
gem 'puma', '~> 3.7'
...
gem 'factory_bot_rails', '~> 4.8.2'
gem 'faker', git: 'https://github.com/stympy/faker.git', branch: 'master'
...
group :production do
gem 'rails_12factor', '~> 0.0.3'
end
group :development, :test do
...
end
group :development do
...
end
group :test do
...
end
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
尝试 运行 rails 位于 heroku 的服务器时出错:
2018-03-16T13:13:16.816776+00:00 app[web.1]: Exiting
2018-03-16T13:13:16.816856+00:00 app[web.1]: /app/vendor/bundle/ruby/2.5.0/gems/factory_bot-4.8.2/lib/factory_bot/registry.rb:24:in `find': Factory not registered: invoice (ArgumentError)
2018-03-16T13:13:16.816893+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.5.0/gems/factory_bot-4.8.2/lib/factory_bot/decorator.rb:10:in `method_missing'
2018-03-16T13:13:16.816894+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.5.0/gems/factory_bot-4.8.2/lib/factory_bot.rb:100:in `factory_by_name'
2018-03-16T13:13:16.816895+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.5.0/gems/factory_bot-4.8.2/lib/factory_bot/factory_runner.rb:12:in `run'
2018-03-16T13:13:16.816898+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.5.0/gems/factory_bot-4.8.2/lib/factory_bot/strategy_syntax_method_registrar.rb:20:in `block in define_singular_strategy_method'
2018-03-16T13:13:16.816904+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.5.0/gems/factory_bot-4.8.2/lib/factory_bot/strategy_syntax_method_registrar.rb:32:in `block (2 levels) in define_list_strategy_method'
2018-03-16T13:13:16.816905+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.5.0/gems/factory_bot-4.8.2/lib/factory_bot/strategy_syntax_method_registrar.rb:32:in `times'
2018-03-16T13:13:16.816906+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.5.0/gems/factory_bot-4.8.2/lib/factory_bot/strategy_syntax_method_registrar.rb:32:in `each'
2018-03-16T13:13:16.816909+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.5.0/gems/factory_bot-4.8.2/lib/factory_bot/strategy_syntax_method_registrar.rb:32:in `map'
2018-03-16T13:13:16.816910+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.5.0/gems/factory_bot-4.8.2/lib/factory_bot/strategy_syntax_method_registrar.rb:32:in `block in define_list_strategy_method'
2018-03-16T13:13:16.816912+00:00 app[web.1]: from /app/app/services/invoice_service.rb:2:in `<class:InvoiceService>'
2018-03-16T13:13:16.816913+00:00 app[web.1]: from /app/app/services/invoice_service.rb:1:in `<top (required)>'
有人在生产模式下成功使用工厂机器人吗?
factory_bot 默认情况下不会在任何地方包含它自己,仅在您通常使用它的规范中。
尝试
require 'factory_bot'
FactoryBot.find_definitions
在invoice.rb
如果可行,您可以在初始化程序中添加具有相同内容的 factory_bot.rb
文件,以便在 rails 应用程序启动时加载它(取决于您的偏好)
请参阅 https://github.com/thoughtbot/factory_bot/blob/master/GETTING_STARTED.md#using-without-bundler 了解更多信息。
我正在尝试在 heroku 上使用 gem FactoryBot..
在本地一切正常,正确找到工厂。
我正在尝试在 spec 文件夹之外使用工厂。
我在服务中使用它invoice.rb
:
class InvoiceService
@invoices ||= FactoryBot.build_list :invoice, 50, :with_invoice_positions
end
这是我的发票工厂的样子:
FactoryBot.define do
factory :invoice do
...
trait :with_invoice_positions do
transient do
invoice_positions_count 5
end
after(:build) do |invoice, evaluator|
...
end
end
end
end
最后一件事是 Gemfile,我将 FactoryBot 行放在 :test 组之外:
ruby '2.5.0'
source 'https://rubygems.org'
gem 'rails', '~> 5.1.4'
gem 'pg', '~> 0.18'
gem 'puma', '~> 3.7'
...
gem 'factory_bot_rails', '~> 4.8.2'
gem 'faker', git: 'https://github.com/stympy/faker.git', branch: 'master'
...
group :production do
gem 'rails_12factor', '~> 0.0.3'
end
group :development, :test do
...
end
group :development do
...
end
group :test do
...
end
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
尝试 运行 rails 位于 heroku 的服务器时出错:
2018-03-16T13:13:16.816776+00:00 app[web.1]: Exiting
2018-03-16T13:13:16.816856+00:00 app[web.1]: /app/vendor/bundle/ruby/2.5.0/gems/factory_bot-4.8.2/lib/factory_bot/registry.rb:24:in `find': Factory not registered: invoice (ArgumentError)
2018-03-16T13:13:16.816893+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.5.0/gems/factory_bot-4.8.2/lib/factory_bot/decorator.rb:10:in `method_missing'
2018-03-16T13:13:16.816894+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.5.0/gems/factory_bot-4.8.2/lib/factory_bot.rb:100:in `factory_by_name'
2018-03-16T13:13:16.816895+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.5.0/gems/factory_bot-4.8.2/lib/factory_bot/factory_runner.rb:12:in `run'
2018-03-16T13:13:16.816898+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.5.0/gems/factory_bot-4.8.2/lib/factory_bot/strategy_syntax_method_registrar.rb:20:in `block in define_singular_strategy_method'
2018-03-16T13:13:16.816904+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.5.0/gems/factory_bot-4.8.2/lib/factory_bot/strategy_syntax_method_registrar.rb:32:in `block (2 levels) in define_list_strategy_method'
2018-03-16T13:13:16.816905+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.5.0/gems/factory_bot-4.8.2/lib/factory_bot/strategy_syntax_method_registrar.rb:32:in `times'
2018-03-16T13:13:16.816906+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.5.0/gems/factory_bot-4.8.2/lib/factory_bot/strategy_syntax_method_registrar.rb:32:in `each'
2018-03-16T13:13:16.816909+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.5.0/gems/factory_bot-4.8.2/lib/factory_bot/strategy_syntax_method_registrar.rb:32:in `map'
2018-03-16T13:13:16.816910+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.5.0/gems/factory_bot-4.8.2/lib/factory_bot/strategy_syntax_method_registrar.rb:32:in `block in define_list_strategy_method'
2018-03-16T13:13:16.816912+00:00 app[web.1]: from /app/app/services/invoice_service.rb:2:in `<class:InvoiceService>'
2018-03-16T13:13:16.816913+00:00 app[web.1]: from /app/app/services/invoice_service.rb:1:in `<top (required)>'
有人在生产模式下成功使用工厂机器人吗?
factory_bot 默认情况下不会在任何地方包含它自己,仅在您通常使用它的规范中。
尝试
require 'factory_bot'
FactoryBot.find_definitions
在invoice.rb
如果可行,您可以在初始化程序中添加具有相同内容的 factory_bot.rb
文件,以便在 rails 应用程序启动时加载它(取决于您的偏好)
请参阅 https://github.com/thoughtbot/factory_bot/blob/master/GETTING_STARTED.md#using-without-bundler 了解更多信息。