Running rails server changes test result?

僤鯓⒐⒋嵵緔 提交于 2019-12-12 02:37:17

问题


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!


回答1:


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



来源:https://stackoverflow.com/questions/34723157/running-rails-server-changes-test-result

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!