Ad

Running Rails Server Changes Test Result?

Related with this question, I came across a strange situation. ruby on rails - Log in test fails with RSpec / Capybara / Poltergeist - Stack Overflow


Just run test

bin/rspec spec/features/spec.rb

11871 spring server | myapp | started 32 secs ago
11877 spring app    | myapp | started 31 secs ago | test mode

I get log from PhantomJS like:

API.ajax:GET /user :failed
httpStatus:0
error
undefined

Run test with server running in development

bin/rails s and then bin/rspec spec/features/spec.rb

I get log from PhantomJS like:

API.ajax:POST /sessions :failed
httpStatus:401
error
[object Object]

It looks like PhantomJS can't even reach the /sessions url without server running in development. (It fails anyway though..)

Does anyone have same experience? I don't know why running dev server makes this change and hope there is a clue to resolve the test failure.

I'm using RSpec, Cabybara, Poltergeist, PhantomJS 2.0 and React.

Thanks!

Ad

Answer

The dev server runs on port 3000 while Capybara runs the test server on a random port unless you've set Capybara.server_port. From your description it sounds like you may have a reference to port 3000 hard coded into your JS, which would mean it wasn't it's trying to contact the dev server even when running in test mode

Ad
source: stackoverflow.com
Ad