如何让 Rails 服务器使用与 Cucumber 在测试期间使用的数据库相同的数据库?

发布于 2024-08-29 03:23:16 字数 327 浏览 5 评论 0原文

Cucumber 测试首先在数据库中创建一个条目并将表单发送到第二个服务器。第二个服务器在后台进行一些处理,然后使用黄瓜测试需要了解的一些数据来访问第一个应用程序(正在运行测试的地方)。

我尝试在黄瓜测试运行时通过 script/serverscript/server -e test 运行主服务器,但我似乎无法强制服务器使用与 Cucumber 运行其步骤定义时使用的数据库相同的数据库。也就是说,当第二个服务器将一些数据推送到主服务器中的控制器时,主服务器不知道 Cucumber 在数据库中创建的任何条目。如何让 Cucumber 和主服务器使用相同的数据库?

The cucumber test first makes an entry in the database and posts a form to a second server. This second server does some processing in background and then hits the first app (where the test is being run) with some data that the cucumber test needs to know about.

I've tried running the main server via script/server and script/server -e test while the cucumber test is running, but I can't seem to force the server to use the same database that cucumber is using when it runs its step definitions. That is, when the second server pushes some data to a controller in the main server, the main server doesn't know about any entries that cucumber has made in the database. How can I get cucumber and the main server to use the same database?

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

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

发布评论

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

评论(3

过潦 2024-09-05 03:23:16

您可以像这样共享环境设置。

配置/数据库.yml

test: &test
  adapter: mysql
  encoding: utf8
  reconnect: false
  database: baseproj_test
  pool: 5
  username: root
  password:
  socket: /tmp/mysql.sock

cucumber:
  <<: *test

You can share environment settings like this.

config/database.yml

test: &test
  adapter: mysql
  encoding: utf8
  reconnect: false
  database: baseproj_test
  pool: 5
  username: root
  password:
  socket: /tmp/mysql.sock

cucumber:
  <<: *test
往事随风而去 2024-09-05 03:23:16

您在评论中击中了解决方案(没有业力回复)。测试在事务中运行,并在最后回滚。因此,外部服务器不受 Cucumber 对数据库执行的任何查询的影响。禁用事务装置是可行的方法,但我不知道为什么它不起作用。

其他解决方案是 a) 重新架构您的代码,这样您就不需要通用数据库(这肯定会在其他地方引起问题),或者 b) 让您的 Cucumber 测试进入第二个服务器的数据库(通过 HTTP 请求?)。

You hit the solution on the head in your comment (don't have the karma to reply). The tests are run within a transaction, which is rolled back at the end. So, the external server is isolated from the effects of any queries Cucumber performs on the database. Disabling transactional fixtures is the way to go, but I don't know why it's not working.

Other solutions would be to a) rearchitect your code so you don't need a common database (that's bound to cause problems elsewhere), or b) have your Cucumber test reach into a the second server's database (via an HTTP request?).

千秋岁 2024-09-05 03:23:16

看来在 env.rb 中设置 Cucumber::Rails::World.use_transactional_fixtures = false 已经解决了这个问题。

编辑这不再适用于最新的 Cucumber 安装。 Rails 服务器找不到通过 Cucumber 测试放入数据库的数据。

It appears that setting Cucumber::Rails::World.use_transactional_fixtures = false in env.rb has solved this problem.

Edit this is no longer working with the latest cucumber install. The rails server isn't finding data put in the database by the cucumber test.

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