1

I'm implementing kinda tricky functionality with external libraries I can't mock. They needs to implement real requests to the server. So,

how can I run a web-server during tests implementation?

P.S. My config/test.exs:

config :my_reelty, MyReelty.Endpoint,
  http: [port: {:system, "PORT"}],
  url:  [host: "localhost", port: 5000] # Specific port

I'm trying to curl http://localhost:5000 but getting curl: (7) Failed to connect to localhost port 5000: Connection refused

Alex Antonov
  • 14,134
  • 7
  • 65
  • 142
  • 1
    You want to run your Phoenix app on port 5000 while you run the tests for the same app? Sorry, I'm not following what you're trying to achieve here. – Dogbert Jul 23 '16 at 12:51
  • Yes, I want to run app on port 5000 to run tests – Alex Antonov Jul 23 '16 at 13:13
  • 1
    Do you have `config :my_reelty, MyReelty.Endpoint, server: true` in `config/test.exs`? If not, try adding that. I can access the server from my tests with `server: true`. – Dogbert Jul 23 '16 at 14:26
  • Excellent, please make it answer – Alex Antonov Jul 23 '16 at 16:28
  • @asiniy, i trying to something that sounds similar to the title of your question. can you explain a little more how you did it? – fay Feb 21 '17 at 08:20

1 Answers1

2

You need to add server: true to the Endpoint's config:

config :my_reelty, MyReelty.Endpoint, server: true

The phoenix.new may have already generated similar config with server: false (it does for me in v1.2.0), so you can just change that false to true.

Dogbert
  • 212,659
  • 41
  • 396
  • 397