Following the example at http://robots.thoughtbot.com/testing-your-factories-first the line task spec: :factory_specs in the Rakefile tells rake to execute "factory_specs" task before "spec" task.

My issue is that rake spec loads the Rails environment twice, one to execute factory_specs task and then another to execute spec task.

How do I prevent my rake command from loading Rails twice?

My stack:

  • Ruby 1.9.3p484
  • Rails 3.2.13
有帮助吗?

解决方案

With the latest version of FactoryGirl, you can use FactoryGirl.lint instead of explicitly testing your factories in a separate rake task. Just update to the latest version and add this to your spec_helper.rb:

RSpec.configure do |config|
  config.before(:suite) do
    FactoryGirl.lint
  end
end

More info is in the Getting Started Guide.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top