如何在Cucumber中测试不同的环境(例如开发|测试|生产)? [英] How can I test different environments (e.g. development|test|production) in Cucumber?
问题描述
采取这种情况。我有一个Google Analytics(分析)跟踪代码,我只希望它显示在生产模式。所以我可能有两个场景像这样:
Take this scenario. I have a Google Analytics tracking code, and I only want it to show up in Production mode. So I might have two scenarios like this:
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中的当前环境,我不知道如何在特定环境中运行特定的场景。是否可能?
So although I know how to check what the current environment is, and I know how to set the current environment in Rails or Sinatra, I have no idea how to run a specific scenario in a specific environment. Is it even possible?
推荐答案
你应该能够在测试代码本身强制的环境, b $ b ENV ['RACK_ENV'] ='test'
ENV ['RACK_ENV'] ='production'
You should be able to force the environment in the test code itself, something along the lines of
ENV['RACK_ENV'] = 'test'
ENV['RACK_ENV'] = 'production'
我认为这是一个非常糟糕的代码气味。
I would consider it a pretty bad code smell though.
我不得不搞砸环境之前( http://richardconroy.blogspot.com/2010/01/issues-testing-sinatra-datamapper -app.html ),以获取测试代码,以识别应针对测试环境执行。
I have had to mess about with environments before(http://richardconroy.blogspot.com/2010/01/issues-testing-sinatra-datamapper-app.html), to get test code to recognise that it should be executing against test environments. This is just doing it backwards I suppose.
仍然,不是google分析跟踪Cookie网站特定吗?在开发/测试/暂存环境中使用跟踪Cookie不应影响您的统计信息。
Still, aren't google analytics tracking cookies site specific? Having the tracking cookie in your development/test/staging environment shouldn't influence your stats.
这篇关于如何在Cucumber中测试不同的环境(例如开发|测试|生产)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!