How do I change the default “www.example.com” domain for testing in rails?

后端 未结 10 670
囚心锁ツ
囚心锁ツ 2020-11-30 04:17

I have a rails application which acts differently depending on what domain it\'s accessed at (for example www.myapp.com will invoke differently to user.myapp.com). In produc

10条回答
  •  囚心锁ツ
    2020-11-30 05:00

    Yet another answer:

    request.host = "user.myapp.com"
    

    I know it resembles the correct answer, but please bear with me. I don't like assignment operation in test just to set things up, I'd prefer an explicit stub. Interestingly, stubbing like this won't work:

    allow(request).to receive(:host).and_return("user.myapp.com")
    

    I personally prefer stubbing over assignment, that way I get 2 benefit, one is that it will be validated by rspec's verify double, second is that it is explicitly saying that is a stub, not part of the test excercise.

提交回复
热议问题