gpt4 book ai didi

ruby-on-rails - 如何在 Cucumber 中测试不同的环境(例如开发|测试|生产)?

转载 作者:数据小太阳 更新时间:2023-10-29 07:57:55 25 4
gpt4 key购买 nike

以这个场景为例。我有一个 Google Analytics 跟踪代码,我只希望它在生产模式下显示。所以我可能有这样两种情况:

Scenario: Don't embed tracking code in development or test mode
Given the app is not in production mode
When I go home
Then I should really not see the tracking code

Scenario: Embed tracking code in production mode
Given the app is in production mode
When I go home
Then I should really see the tracking code

所以虽然我知道如何查看当前环境是什么,我知道如何在Rails或Sinatra中设置当前环境,但我不知道如何在特定环境中运行特定场景。有可能吗?

最佳答案

我认为您真的应该使用 Cucumber 访问您网站的实时 URL;因为这可能是您真正想知道的——我的追踪是否真的在运行?

这对我有用,但你需要使用 Capybara(如果存在,也许有人会发布类似的 webrat 解决方案)。

Given /^the app is in production mode$/ do
Capybara.current_driver = :selenium
Capybara.app_host = 'http://www.joshcrews.com'
end

When /^I go home$/ do
visit("http://www.joshcrews.com")
end

Then /^I should really see the tracking code$/ do
page.body.should match /UA-7396376-1/
end

关于ruby-on-rails - 如何在 Cucumber 中测试不同的环境(例如开发|测试|生产)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3368625/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com