gpt4 book ai didi

ruby-on-rails - Rspec极慢

转载 作者:行者123 更新时间:2023-12-04 06:34:03 24 4
gpt4 key购买 nike

我的rspec测试似乎在使用 guard 队和spork的情况下运行极其缓慢。

Finished in 5.36 seconds
13 examples, 2 failures

我知道可以做一些事情来优化测试并减少与数据库的交互,但是我强烈怀疑spec_helper的设置不正确。我在与3.2版的Mongoid混在一起。每次运行后,数据库清理器都会清理一次。
spec_helper.rb

require 'rubygems'
require 'spork'
Spork.prefork do
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
require 'capybara/rspec'

Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
DatabaseCleaner[:mongoid].strategy = :truncation

RSpec.configure do |config|
config.infer_base_class_for_anonymous_controllers = false
config.order = "random"
config.filter_run focus: true
config.filter_run_excluding :remove => true
config.run_all_when_everything_filtered = true
config.include Mongoid::Matchers
config.include Capybara::DSL
ActiveSupport::Dependencies.clear
end
end


Spork.each_run do
Fabrication.clear_definitions
RSpec.configure do |config|
config.before(:each) do
DatabaseCleaner.clean
end
end
end

更新:问题出在我的一项测试中。这花了3秒钟。请检查@Sam Peacey的答案以获取我用来获得以下结果的命令
Dynamic Model should destroy collection when related source is destroyed
2.46 seconds ./spec/models/dynamic_model_spec.rb:10
Dynamic Model Validations should validate uniqueness
0.66357 seconds ./spec/models/dynamic_model_spec.rb:69

最佳答案

您可以通过运行带有-p/--profile标志的rspec来配置您的规范:

rspec spec -p [-drb, and whatever else]

这将列出10个最慢的示例及其执行时间。您可以通过为-p标志提供可选计数来更改默认值10。通过使用 rspec --help获得更多信息

关于ruby-on-rails - Rspec极慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15471586/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com