LoginSignup
2
0

More than 5 years have passed since last update.

テストヘルパーが増えてくるとconfig.includeするのが大変めんどうです

Last updated at Posted at 2016-05-20

こう書けます

# spec/support/user_helper.rb

module UserHelper
  module Features
    def help_foo
    end

    def help_bar
    end

    def help_baz
    end
  end

  module Requests
    def help_bar
    end
  end
end

RSpec.configure do |config|
  config.include UserHelper::Features, type: :feature
  config.include UserHelper::Requests, type: :request
end

テストを支援するgemを入れると(例えばfactory_girl

RSpec.configure do |config|
  config.include FactoryGirl::Syntax::Methods
end

spec/rails_helper.rbconfigureブロックで、ヘルパーモジュールをincludeするので
テストで使うモジュールは全てここでincludeしないといけないのかなと思ってましたが
そんな事はなく、ヘルパーモジュール本体からincludeできます。

参考

clearanceで生成できるテストに含まれるヘルパー

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0