문제

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