Ruby on rails 基准rspec在没有任何通知的情况下被卡住

Ruby on rails 基准rspec在没有任何通知的情况下被卡住,ruby-on-rails,rspec,benchmarking,Ruby On Rails,Rspec,Benchmarking,我正在尝试测试内存分配。然后为它选择rspec基准gem。但是发现了一些奇怪的行为我不明白。要复制它,我们可以编写如下规范: require 'rails_helper' describe ApplicationsManagement::Export do let(:applications_collection) { create_list(:application, 1 ) } describe '#call' do it 'comsumpts not more 1 MB

我正在尝试测试内存分配。然后为它选择
rspec基准
gem。但是发现了一些奇怪的行为我不明白。要复制它,我们可以编写如下规范:

require 'rails_helper'

describe ApplicationsManagement::Export do
  let(:applications_collection) { create_list(:application, 1 ) }

  describe '#call' do
    it 'comsumpts not more 1 MB' do
      i = 0
      expect { applications_collection.each { |app| puts i += 1 } }.to perform_allocation(1_048_576).bytes
    end
  end
end

当我们运行spec时,我们必须等待几分钟

ApplicationsManagement::Export
  #call
1
    comsumpts not more 1 MB (FAILED - 1)

Failures:

  1) ApplicationsManagement::Export#call comsumpts not more 1 MB
     Failure/Error: expect { applications_collection.each { |app| puts i += 1 } }.to perform_allocation(1_048_576).bytes
       expected block to perform allocation of 1048576 bytes, but allocated 10694166 bytes
     # ./spec/services/applications_management/export_spec.rb:16:in `block (3 levels) in <top (required)>'
     # ./spec/rails_helper.rb:55:in `block (3 levels) in <top (required)>'
     # ./spec/rails_helper.rb:54:in `block (2 levels) in <top (required)>'

Finished in 4 minutes 8.5 seconds (files took 21.99 seconds to load)
1 example, 1 failure
附言:

rails 4.2.9
rspec(3.5.0)
rspec磁芯(~>3.5.0)
rspec期望值(~>3.5.0)
rspec模拟(~>3.5.0)
rspec基准(0.5.1)
基准malloc(~>0.1.0)
基准性能(~>0.5.0)
基准趋势(~>0.3.0)
rspec(>=3.0.0,<4.0.0)
rspec核心(3.5.4)
rspec支持(~>3.5.0)

非常感谢你

我发现,如果我将
FactoryBot.create(…)
传递到
expect
块,那么我就得到了卡住的行为。但是如果在我初始化对象之前有一行。然后示例按预期工作

require 'rails_helper'

describe ApplicationsManagement::Export do
  let(:applications_collection) { create_list(:application, 1) }

  describe '#call' do
    it 'comsumpts not more 1 MB' do
      applications_collection
      i = 0
      expect { applications_collection.each { |app| puts i += 1 } }.to perform_allocation(1_048_576).bytes
    end
  end
end
rails 4.2.9
rspec (3.5.0)
      rspec-core (~> 3.5.0)
      rspec-expectations (~> 3.5.0)
      rspec-mocks (~> 3.5.0)
    rspec-benchmark (0.5.1)
      benchmark-malloc (~> 0.1.0)
      benchmark-perf (~> 0.5.0)
      benchmark-trend (~> 0.3.0)
      rspec (>= 3.0.0, < 4.0.0)
    rspec-core (3.5.4)
      rspec-support (~> 3.5.0)
require 'rails_helper'

describe ApplicationsManagement::Export do
  let(:applications_collection) { create_list(:application, 1) }

  describe '#call' do
    it 'comsumpts not more 1 MB' do
      applications_collection
      i = 0
      expect { applications_collection.each { |app| puts i += 1 } }.to perform_allocation(1_048_576).bytes
    end
  end
end
ApplicationsManagement::Export
  #call
1
    comsumpts not more 1 MB

Finished in 1.17 seconds (files took 21.71 seconds to load)
1 example, 0 failures