dailammoc
dailammoc

Reputation: 144

Calling spec_helper file

I'm new in rspec test. My spec directory contain various subfolders: controllers, models, views, requests, helpers(all helper file located here) etc. So if I want to call(require) /helpers/crud_helper_spec.rb from /controllers/crud_contrller_spec.rb. What should I do?

Upvotes: 0

Views: 106

Answers (1)

Ariejan
Ariejan

Reputation: 11069

Any helpers you write you can put in spec/support, like your CRUD helper in spec/support/crud_helper.rb:

module CrudHelper
  # Fancy helpers here
end

Your spec/spec_helper is probably already configured to require these files. To use the helpers in a controller spec, do the following

describe PostsController do
  include CrudHelper

  it { fancy_helper(:index) }
end

Upvotes: 1

Related Questions