以下面的场景为例。我有一个谷歌分析跟踪代码,我只希望它在生产模式下显示。所以我可能会有两个这样的场景:
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中设置当前环境,但我不知道如何在特定环境中运行特定场景。这有可能吗?
发布于 2010-08-09 05:19:50
您应该能够在测试代码本身中强制环境,类似于ENV['RACK_ENV'] = 'test' ENV['RACK_ENV'] = 'production'
不过,我会认为这是一种非常糟糕的代码味道。
我以前曾经在环境(http://richardconroy.blogspot.com/2010/01/issues-testing-sinatra-datamapper-app.html)中乱搞过,为了让测试代码认识到它应该在测试环境中执行。我想这只是倒退而已。
尽管如此,谷歌分析追踪cookie的网站不是特定的吗?在您的开发/测试/升级环境中使用跟踪cookie应该不会影响您的统计数据。
发布于 2010-08-12 10:48:01
我认为你真的应该使用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/
endhttps://stackoverflow.com/questions/3368625
复制相似问题