を使用するためにそれが動作しない場合は
私はspec_helper_integration
ファイルを作成し、そこに統合仕様に固有の機能を入れてしまうでしょう。
すべてのスペックの上部にはすでにrequire 'rails_helper'
があるはずです。お使いの統合スペックの一番上に置く:
require 'rails_helper'
require 'spec_helper_integration'
は、その後、あなたのrails_helper.rb
ファイルと同じフォルダにspec_helper_integration.rb
ファイルを作成します。
spec_helper_integration:
#I'm taking a guesstimate as to your integration spec configuration, but it's
#likely something like the following line:
#don't also have this in your spec_helper or rails_helper files:
require 'capybara/rails'
#configure your integration specs:
RSpec.configure do |config|
config.before(:each) do
allow_any_instance_of(ApplicationController).to receive(:set_seo).and_return('seo_text')
end
end
それは、それが唯一必要とする場所にコードを分離することをお勧めです。このようにすると、ApplicationControllerメソッドのスタブは、統合仕様の実行中にのみ有効になり、他の仕様(ユニットやコントローラの仕様など)では有効になりません。
今後の統合仕様固有のコードは、spec_helper_integrationファイルにのみ入れてください。
'before(:each)'が正常に動作します。 – user