Home > database >  Where should i place helper method for rspec test in Rails6?
Where should i place helper method for rspec test in Rails6?

Time:12-29

I have helper method for rspec test like this : <bla_bla_helper.rb>

Module blabla
  def bla
  end
end

Where should i place this module? This module is only for rspec test.

Past version of Rails used spec/support directory, should i use this directory?

CodePudding user response:

I usually place mine inside spec/support/helpers and include it in the configuration via rails_helper.

Here's an example of including the devise API auth helper that I am using for my application.

config.include DeviseApiAuthHelper, type: :controller

CodePudding user response:

Yes you can continue using spec/support directory.

CodePudding user response:

In RSpec you use spec/support to place the helpers, matchers, shared contexts etc that your specs need. This path is added to the load path so you can simply do require 'foo' in your specs to require spec/support/foo.rb.

Some projects use a glob in spec/spec_helper.rb to require all the files in the spec/support directory.

This is just an RSpec convention that has nothing to do with Rails, so the practice isn't going to change with Rails versions.

  • Related