简体   繁体   English

如何在rspec测试期间启动辅助Rails应用程序?

[英]How to start a secondary rails app during rspec tests?

I have 2 rails apps. 我有2个Rails应用程序。 One is a web interface (I'll call it UI ), the other one is an API server (I'll call it API ). 一个是Web界面(我将其称为UI ),另一个是API服务器(我将其称为API )。

They interact together, UI is sending json commands to API. 他们在一起互动,UI正在将json命令发送到API。 I want to test all of this in integration. 我想在集成中测试所有这些。 Today I manually start API from the command line, and I am looking for a way to automatically start the API server from the test suite. 今天,我从命令行手动启动API,并且我正在寻找一种从测试套件自动启动API服务器的方法。

I am using Capyraba, Selenium, Rspec. 我正在使用Capyraba,Selenium,Rspec。 During the tests Capybara automatically starts a UI server, I need to also start a API server. 在测试期间,水豚会自动启动UI服务器,我还需要启动API服务器。

Any hint appreciated. 任何提示表示赞赏。 Thanks 谢谢


I tried Process.spawn("cd /api/project/path && rails s -e test") but I get a ActionController::RoutingError: No route matches error saying that the path in API is not existing. 我尝试了Process.spawn("cd /api/project/path && rails s -e test")但遇到了ActionController::RoutingError: No route matches错误,指出API中的路径不存在。 But when I run API manually I don't have this error. 但是当我手动运行API时,没有此错误。

I believe Rack is getting confused with 2 environments 我相信Rack会与2种环境混淆

You need to ensure that API is running before your scenarios are started. 在启动方案之前,需要确保API正在运行。 You can add rule to start it if it is not running by adding in before hook: 您可以添加规则以在未运行时启动它,方法是before钩子before添加:

#features/supports/app_life_cycle_hooks.rb
Before do |scenario|
  start_api()   
end

def start_api()
 Process.spawn("./script/server start")
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM