Application developers are free to use a different directory structure. In
order to include the correct rspec-rails support functions, the specs need
to have the appropriate corresponding metadata :type value:

Model specs: type: :model

Controller specs: type: :controller

Request specs: type: :request

Feature specs: type: :feature

View specs: type: :view

Helper specs: type: :helper

Mailer specs: type: :mailer

Routing specs: type: :routing

Job specs: type: :job

System specs: type: :system

For example, say the spec for the ThingsController is located inspec/legacy/things_controller_spec.rb. Simply tag the spec'sRSpec.describe block with the type: :controller metadata:

require "rails_helper"
RSpec.configure do |config|
config.infer_spec_type_from_file_location!
end
RSpec.describe WidgetsController do
it "responds successfully" do
get :index
expect(response.status).to eq(200)
end
end

require "rails_helper"
Rails.application.routes.draw do
get "/example" => redirect("http://example.com")
end
RSpec.configure do |config|
config.infer_spec_type_from_file_location!
end
# Due to limitations in the Rails routing test framework, routes that
# perform redirects must actually be tested via request specs
RSpec.describe "/example", :type => :request do
it "redirects to example.com" do
get "/example"
expect(response).to redirect_to("http://example.com")
end
end