跨多个环境的 Rails 测试

发布于 2024-09-03 13:03:31 字数 489 浏览 2 评论 0原文

有没有办法在测试中途改变 Rails 环境?或者,设置一个测试套件的正确方法是什么,该套件可以在一个环境中启动 Rails,在其中运行测试的前半部分,然后在另一个环境中重新启动 Rails 以完成测试?这两个环境有单独的数据库。

一些必要的上下文:我正在编写一个 Rails 插件,它允许 Rails 应用程序的多个安装在用户帮助下相互通信,以便无法访问 Internet 的用户仍然可以使用该应用程序。他们将运行应用程序的本地版本,并将文件保存到拇指驱动器并将其带到网吧,从而将其工作上传到在线应用程序。

该插件为 Rails 添加了两个特殊环境:“offline-product”和“offline-test”。我想编写涉及“测试”和“离线测试”环境的功能测试,分别代表应用程序的主要在线版本和应用程序的本地离线版本。

编辑:我一直在阅读 Rack::Test,看起来这可能是可行的方法,因为它将测试框架置于 Rails 本身之外。但我仍然不知道如何使用它来进行涉及多个环境的测试。有什么想法吗?

Is there some way to change Rails environments mid-way through a test? Or, alternately, what would be the right way to set up a test suite that can start up Rails in one environment, run the first half of my test in it, then restart Rails in another environment to finish the test? The two environments have separate databases.

Some necessary context: I'm writing a Rails plugin that allows multiple installations of a Rails app to communicate with each other with user assistance, so that a user without Internet access can still use the app. They'll run a local version of an app, and upload their work to the online app by saving a file to a thumbdrive and taking it to an Internet cafe.

The plugin adds two special environments to Rails: "offline-production" and "offline-test". I want to write functional tests that involve both the "test" and "offline-test" environments, to represent the main online version of the app and the local offline version of the app respectively.

Edit: I've been reading up on Rack::Test, and it seems like it might be the way to go, because it places the testing framework outside of rails itself. But I still have no idea how I can use it to do a test that involves more than one environment. Any ideas, anyone?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

长伴 2024-09-10 13:03:32

也许从拥有多个数据库连接而不是拥有多个环境的角度来思考这个问题?你不可能真正地中途切换环境,至少在没有大量黑客攻击和搞砸事情的情况下是不可能的。 :)

http://anandmuranal.wordpress.com /2007/08/23/multiple-database-connection-in-rails/

Maybe think about the issue from the perspective of having more than one db connection, instead of having more than one environment? You can't really switch environments part way through, at least without a lot of hacking and screwing things up. :)

http://anandmuranal.wordpress.com/2007/08/23/multiple-database-connection-in-rails/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文