テストファイルでも、ヘルパーメソッドを使いたいときってありますよね。
ApplicationHelperを使いたい場合を想定します。
複数のファイルで利用したいとき
spec/rails_helper.rbでApplicationHelperをincludeすればよいです。
spec/rails_helper.rb
include ApplicationHelper
specファイルは基本的にどれもトップレベルでrequire rails_helperしているはずなので、spec/rails_helper.rbでincludeしてあげっちゃえばよいわけです。
1つのファイルでのみ利用したいとき
対象のテストファイルでApplicationHelperをincludeすればよいです。
例にSystemSpecを挙げます。
spec/systems/sample_spec.rb
include ApplicationHelper
もしincludeを忘れたら
もしincludeを忘れたら、下記のエラー文で怒られます。
NoMethodError:
undefined method `method_name' for #<RSpec::ExampleGroups::SiteLayout:0x00007f85f17a5a70>