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

标签 ruby-on-rails ruby testing cucumber

以这个场景为例。我有一个 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/

相关文章:

ruby-on-rails - Rails 错误:未初始化常量 Sass::Plugin (NameError)

javascript - Rails Javascript 文件中的 CSS

ruby-on-rails - Ruby 模块中常量的作用域

spring-boot - Kotlin Spring WebMvcTest Mockk

ruby-on-rails - Rails 3 +Devise + RSpec : undefined method 'visit'

ruby-on-rails - update_all 不工作

ruby - 正则表达式 - 保存重复捕获的组

ruby - 将值插入到 YAML 转储的哈希中

node.js - 在 typescript 上扩展 super 测试

c# - 显示消息对话框的方法