正在运行的Rails服务器会更改测试结果吗? [英] Running rails server changes test result?

查看:78
本文介绍了正在运行的Rails服务器会更改测试结果吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

与这个问题有关,我遇到了一个奇怪的情况. ruby​​ on rails-使用RSpec/Capybara登录测试失败/Poltergeist-堆栈溢出

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


bin/rspec spec/features/spec.rb

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

我从PhantomJS获得日志,如:

I get log from PhantomJS like:

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


bin/rails s 接着 bin/rspec spec/features/spec.rb

我从PhantomJS获得日志,如:

I get log from PhantomJS like:

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


如果没有在开发中运行服务器,PhantomJS甚至无法访问/sessions URL. (尽管如此它还是会失败..)

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

有人有相同的经历吗?我不知道为什么运行dev服务器会进行此更改,并希望有一条线索可以解决测试失败.

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.

我正在使用RSpec,Cabybara,Poltergeist,PhantomJS 2.0和 React .

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

谢谢!

推荐答案

除非您已设置Capybara.server_port,否则开发服务器在端口3000上运行,而Capybara在随机端口上运行测试服务器.从您的描述中听起来,您可能已经引用了对JS的port 3000硬编码的引用,这意味着即使在测试模式下运行,它也不是在尝试与开发服务器联系

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

这篇关于正在运行的Rails服务器会更改测试结果吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆