使用子域测试路由

时间:2016-09-14 08:39:19

标签: ruby-on-rails rspec rspec-rails

我正在尝试使用子域测试我的路由,但我不知道如何测试它。我的子域工作正常,我只是难以通过子域传递当前请求。

以下是我的路线:

function newLineFunction_PDF(text, num) {
  var re = new RegExp(/.{num}\S*\s+/g);
  var arr = text.replace(re, "$&@").split(/\s+@/);
  return arr;
}

以下是我的路由测试的片段

search_finances GET /finances/search(.:format) finances#search {:subdomain=>"admin"} search_finance_finances POST /finances/search_finance(.:format) finances#search_finance {:subdomain=>"admin"} delete_finance GET /finances/:id/delete(.:format) finances#delete {:subdomain=>"admin"} finances GET /finances(.:format) finances#index {:subdomain=>"admin"} POST /finances(.:format) finances#create {:subdomain=>"admin"} new_finance GET /finances/new(.:format) finances#new {:subdomain=>"admin"} edit_finance GET /finances/:id/edit(.:format) finances#edit {:subdomain=>"admin"} finance GET /finances/:id(.:format) finances#show {:subdomain=>"admin"} PATCH /finances/:id(.:format) finances#update {:subdomain=>"admin"} PUT /finances/:id(.:format) finances#update {:subdomain=>"admin"} DELETE /finances/:id(.:format) finances#destroy {:subdomain=>"admin"} GET /finances/search_finance/:page(.:format) finances#search_finance {:subdomain=>"admin"}

spec/routing/finances_routing_spec.rb

以下是我的错误消息:

require 'rails_helper'

describe FinancesController do
  describe 'routing' do
    it 'routes to #index' do
      expect(get: '/finances').to route_to('finances#index')
    end
  end
end

如何在测试中传递子域名?我在stackoverflow上寻找关于设置1) FinancesController routing routes to #index Failure/Error: expect(get: '/finances').to route_to('finances#index') No route matches "/finances" 的其他示例,但这对我不起作用(我可能做错了)

更新:

我尝试使用此解决方案testing routes with subdomain constraints using rspec

但我不明白在哪里设置reqest.host = admin.example.com

0 个答案:

没有答案