In Sinatra tests, env['SERVER_NAME'] defaults to www.example.com. How can I set this to some arbitrary domain?

Capybara has .default_host method, but not using Capybara.

Or, is it possible to change the env[DEFAULT_HOST]?

Using RSpec, Sinatra, WebMock.

EDIT: Adding env['SERVER_NAME'] = 'www.foo.com' to RSpec test raises exception:

NameError: undefined local variable or method 'env' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1:0x007fe6ce3b5ff8>

有帮助吗?

解决方案

The env helper is only accessible within a Sinatra app.

One way to change it is when making a request:

get "/blah", {}, {'HTTP_SERVER_NAME' => 'www.foo.com' }

The 3rd argument of a rack/test get or post is the headers hash.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top