let! で設定したのに、it毎に実行されてしまう、という現象に悩まされています。
いままで経験したことがなかったので(託された)システムの設定のどこかでなにかあるのか、と探っているのですが、私のRspecの知識では追いきれませんでした。
次の rspecを実行すると、
require 'rails_helper' RSpec.describe Summary, type: :model do let!(:applicant) { create :applicant } #let!(:summary) { Summary::Summary.new Applicant } it 'applicant id' do; expect(applicant.id).to eq 1 ; end it 'applicant id' do; expect(applicant.id).to eq 1 ; end it 'applicant id' do; expect(applicant.id).to eq 1 ; end end
id が1なわけはないのでみな Failするのですが、その時のgotが繰り上がって行きます。
got: 172739 got: 172740 got: 172741
どうも rspec の実行が遅い、と思っていたのですが このspecの前段階としてそこで使用する100ほどのscopeのテストのために、applicantを100ぐらい let! で作って行なったところ 10分!。 はて、とこのテストを作って確認してみた次第です。
rails_helper, spec_helper は工夫満載でしたので、以下のようにoriginal程度にまで削ったのですが、結果は同じでした。
Config/application.rb の config.generators do |g|
に g.test_framework :rspec,
の記載が有ったので削除してみましたが結果は同じでした。
Rails.root、 config 配下には、ほかに rspec の名前のあるものはありませんでした。(GemfileとGurdfileにはあります)
遅いとはいえ動くことは動くので致命的では無いのですが、中等症Ⅱ と言ったところでしょうか。
解決にはどのあたりを探れば良いかお知恵をお貸しください。
rails_helper
require 'spec_helper' ENV['RAILS_ENV'] ||= 'test' require File.expand_path('../../config/environment', __FILE__) abort('The Rails environment is running in production mode!') if Rails.env.production? require 'rspec/rails' RSpec.configure do |config| config.fixture_path = "#{::Rails.root}/spec/fixtures" config.infer_spec_type_from_file_location! config.filter_rails_from_backtrace! config.include FactoryBot::Syntax::Methods end
spec_helper
require 'ffaker' RSpec.configure do |config| config.expect_with :rspec do |expectations| expectations.include_chain_clauses_in_custom_matcher_descriptions = true end config.mock_with :rspec do |mocks| mocks.verify_partial_doubles = true end config.shared_context_metadata_behavior = :apply_to_host_groups end
環境
ruby 2.7.2
rails 6.1.3.2
rspec 3.10.0
Gemfile 中に rspecとあるもの
gem 'rspec-rails'
gem 'guard-rspec', require: false
gem 'rspec-its'
gem 'rspec-request_describer'
gem 'rspec_junit_formatter'
gem 'rspec-collection_matchers'
あなたの回答
tips
プレビュー