Ruby on rails 带有单元Gem和Grape的rpsec rails无法将主机设置为子域

Ruby on rails 带有单元Gem和Grape的rpsec rails无法将主机设置为子域,ruby-on-rails,ruby,api,rspec-rails,grape,Ruby On Rails,Ruby,Api,Rspec Rails,Grape,我使用的是Rails 4.2.6、Ruby 2.2.1、rspec Rails 3.4.2、Grape 0.16.2、Grape\u token\u auth 0.1.0。我为多租户安装了公寓gem(1.0.2),并尝试为grape请求编写rspec测试 但无论我尝试了什么解决方案,每次都会从rspec-rails响应方法中得到以下错误 @buf=["<!DOCTYPE html>\n<html>\n<head>\n <title>Apart

我使用的是Rails 4.2.6、Ruby 2.2.1、rspec Rails 3.4.2、Grape 0.16.2、Grape\u token\u auth 0.1.0。我为多租户安装了公寓gem(1.0.2),并尝试为grape请求编写rspec测试

但无论我尝试了什么解决方案,每次都会从rspec-rails响应方法中得到以下错误

@buf=["<!DOCTYPE html>\n<html>\n<head>\n    <title>Apartment::TenantNotFound at /content/api/v1/questions</title>\n</head>\n<body>\n
什么都不管用

我创建了一个测试用例,如下所示:

我的配置:

in spec/rails_helper.rb

config.include RSpec::Rails::RequestExampleGroup, type: :request, file_path: /spec\/requests/
rspec rails发送的此请求始终带有

url: '/content/api/v1/questions'
host: 'www.example.com'
我的测试结果显示:

$ rspec spec/requests/

F

Failures:

1) ContentManager::QuestionAPI GET /content/api/v1/questions returns an empty array of questions
  Failure/Error: response.status.should == 200

   expected: 200
        got: 500 (using ==)
 # ./spec/requests/question_spec.rb:30:in `block (3 levels) in <top (required)>'

Deprecation Warnings:

Using `should` from rspec-expectations' old `:should` syntax without      explicitly enabling the syntax is deprecated. Use the new `:expect` syntax     or explicitly enable `:should` with `config.expect_with(:rspec) { |c| c.syntax = :should }` instead. Called from /home/vagrant/gauge-slcsl/spec/requests/question_spec.rb:30:in `block (3 levels) in <top (required)>'.


If you need more of the backtrace for any of these deprecations to
identify where to make the necessary changes, you can configure
`config.raise_errors_for_deprecations!`, and it will turn the
deprecation warnings into errors, giving you the full backtrace.

1 deprecation warning total

Finished in 6.19 seconds (files took 1.93 seconds to load)
1 example, 1 failure

Failed examples:

rspec ./spec/requests/question_spec.rb:26 # ContentManager::QuestionAPI GET /content/api/v1/questions returns an empty array of questions

abhi@ubuntu-trusty-64:~/my-app$
$rspec规范/请求/
F
失败:
1) ContentManager::QuestionAPI GET/content/api/v1/questions返回一个空问题数组
失败/错误:response.status.should==200
预计:200
获得:500(使用==)
#./spec/requests/question_spec.rb:30:in'block(3层)in'
弃用警告:
使用rspec expectations'old`:should`语法而不显式启用该语法是不推荐的。使用新的“:expect”语法或显式地启用“:should`with`config.expect_with(:rspec){| c | c.syntax=:should}`。从/home/vagrant/gauge-slcsl/spec/requests/question_-spec.rb:30:in'block(3层)in'调用。
如果您需要更多的回溯,这些不推荐都可以
确定在何处进行必要的更改,您可以配置
`config.raise\u errors\u用于\u弃用!`,这将扭转局面
弃用警告转化为错误,为您提供完整的回溯。
1弃用警告总数
完成时间为6.19秒(加载文件需要1.93秒)
1例,1例失败
失败的示例:
rspec./spec/requests/question_spec.rb:26#ContentManager::QuestionAPI GET/content/api/v1/questions返回一个空问题数组
abhi@ubuntu-trusty-64:~/my app$

如果有人知道这个错误以及我在这里做错了什么,请回复/回答。

这个错误是因为,我们必须说公寓子域配置,它只排除了作为子域考虑的“www”一词

添加以下内容:

# config/initializers/apartment/subdomain_exclusions.rb
Apartment::Elevators::Subdomain.excluded_subdomains = ['www']
我在开发和测试环境中使用了better\u errorsgem。这导致rspec输出作为一个更好的错误生成html代码,并且难以理解rspec失败的原因


我从“测试”环境中删除了更好的错误,我得到了这个错误的线索,我们必须将“www”排除在子域之外。

这个错误是因为,我们必须说,公寓子域配置将“www”字排除在子域之外

添加以下内容:

# config/initializers/apartment/subdomain_exclusions.rb
Apartment::Elevators::Subdomain.excluded_subdomains = ['www']
我在开发和测试环境中使用了better\u errorsgem。这导致rspec输出作为一个更好的错误生成html代码,并且难以理解rspec失败的原因

我从“测试”环境中删除了更好的错误,我得到了这个错误的线索,我们必须排除“www”作为子域

# config/initializers/apartment/subdomain_exclusions.rb
Apartment::Elevators::Subdomain.excluded_subdomains = ['www']