4
하위 도메인 제약 조건을 테스트하는 컨트롤러 테스트를 작성하려고합니다. 그러나 RSpec에 하위 도메인을 설정하게 할 수 없으며 하위 도메인이 정확하지 않은 경우 오류를 반환합니다.RSpec & Rails 4를 사용하여 하위 도메인 제약 조건을 테스트하는 방법
나는 사양
module FrontendAPI
class EventsController < FrontendAPI::BaseController
def index
render json: []
end
end
end
events_controller.rb
namespace :frontend_api do
constraints subdomain: 'frontend-api' do
resources :events, only: [:index]
end
end
3.4
routes.rb ~ 레일 4.2.6와 RSpec을 사용하고
RSpec.describe FrontendAPI::EventsController do
describe 'GET #index' do
context 'wrong subdomain' do
before do
@request.host = 'foo.example.com'
end
it 'responds with 404' do
get :index
expect(response).to have_http_status(:not_found)
end
end
end
end
다른 방법이 있습니까?