rake cucumber 和 rake spec 始终使用“开发”环境

2024-05-21

我运行 Cucumber 和 RSpec 测试的 rake 任务始终使用我的development环境。

以下是相关的配置文件:

RAILS_ROOT/config/environments/cucumber.rb

# Edit at your own peril - it's recommended to regenerate this file
# in the future when you upgrade to a newer version of Cucumber.

# IMPORTANT: Setting config.cache_classes to false is known to
# break Cucumber's use_transactional_fixtures method.
# For more information see https://rspec.lighthouseapp.com/projects/16211/tickets/165
config.cache_classes = true

# Log error messages when you accidentally call methods on nil.
config.whiny_nils = true

# Show full error reports and disable caching
config.action_controller.consider_all_requests_local = true
config.action_controller.perform_caching             = false

# Disable request forgery protection in test environment
config.action_controller.allow_forgery_protection    = false

# Tell Action Mailer not to deliver emails to the real world.
# The :test delivery method accumulates sent emails in the
# ActionMailer::Base.deliveries array.
config.action_mailer.delivery_method = :test

# config.gem 'cucumber-rails',   :lib => false, :version => '>=0.3.2' unless File.directory?(File.join(Rails.root, 'vendor/plugins/cucumber-rails'))
# config.gem 'database_cleaner', :lib => false, :version => '>=0.5.0' unless File.directory?(File.join(Rails.root, 'vendor/plugins/database_cleaner'))
# config.gem 'capybara',         :lib => false, :version => '>=0.3.5' unless File.directory?(File.join(Rails.root, 'vendor/plugins/capybara'))
# config.gem 'rspec',            :lib => false, :version => '>=1.3.0' unless File.directory?(File.join(Rails.root, 'vendor/plugins/rspec'))
# config.gem 'rspec-rails',      :lib => false, :version => '>=1.3.2' unless File.directory?(File.join(Rails.root, 'vendor/plugins/rspec-rails'))

RAILS_ROOT/config/environments/test.rb

# Settings specified here will take precedence over those in config/environment.rb

# The test environment is used exclusively to run your application's
# test suite.  You never need to work with it otherwise.  Remember that
# your test database is "scratch space" for the test suite and is wiped
# and recreated between test runs.  Don't rely on the data there!
config.cache_classes = true

# Log error messages when you accidentally call methods on nil.
config.whiny_nils = true

# Show full error reports and disable caching
config.action_controller.consider_all_requests_local = true
config.action_controller.perform_caching             = false

# Configure memcached
FA_MEMCACHED_SERVER = '127.0.0.1'
FA_MEMCACHED_PORT = '11211'
config.cache_store = :mem_cache_store, [FA_MEMCACHED_SERVER, FA_MEMCACHED_PORT].join(':'), { :namespace => Rails.env.to_s }

# Disable request forgery protection in test environment
config.action_controller.allow_forgery_protection    = false

# Tell ActionMailer not to deliver emails to the real world.
# The :test delivery method accumulates sent emails in the
# ActionMailer::Base.deliveries array.
config.action_mailer.delivery_method = :test
config.log_level = :debug

RAILS_ROOT/features/support/env.rb

# IMPORTANT: This file is generated by cucumber-rails - edit at your own peril.
# It is recommended to regenerate this file in the future when you upgrade to a 
# newer version of cucumber-rails. Consider adding your own code to a new file 
# instead of editing this one. Cucumber will automatically load all features/**/*.rb
# files.

ENV["RAILS_ENV"] ||= "cucumber"
require File.expand_path(File.dirname(__FILE__) + '/../../config/environment')

require 'cucumber/formatter/unicode' # Remove this line if you don't want Cucumber Unicode support
require 'cucumber/rails/rspec'
require 'cucumber/rails/world'
require 'cucumber/rails/active_record'
require 'cucumber/web/tableish'

# allows checking outgoing email existant and content
require 'email_spec'
require 'email_spec/cucumber'

require 'capybara/rails'
require 'capybara/cucumber'
require 'capybara/session'
require 'cucumber/rails/capybara_javascript_emulation' # Lets you click links with onclick javascript handlers without using @culerity or @javascript
# Capybara defaults to XPath selectors rather than Webrat's default of CSS3. In
# order to ease the transition to Capybara we set the default here. If you'd
# prefer to use XPath just remove this line and adjust any selectors in your
# steps to use the XPath syntax.
Capybara.default_selector = :css

# If you set this to false, any error raised from within your app will bubble 
# up to your step definition and out to cucumber unless you catch it somewhere
# on the way. You can make Rails rescue errors and render error pages on a
# per-scenario basis by tagging a scenario or feature with the @allow-rescue tag.
#
# If you set this to true, Rails will rescue all errors and render error
# pages, more or less in the same way your application would behave in the
# default production environment. It's not recommended to do this for all
# of your scenarios, as this makes it hard to discover errors in your application.
ActionController::Base.allow_rescue = false

# If you set this to true, each scenario will run in a database transaction.
# You can still turn off transactions on a per-scenario basis, simply tagging 
# a feature or scenario with the @no-txn tag. If you are using Capybara,
# tagging with @culerity or @javascript will also turn transactions off.
#
# If you set this to false, transactions will be off for all scenarios,
# regardless of whether you use @no-txn or not.
#
# Beware that turning transactions off will leave data in your database 
# after each scenario, which can lead to hard-to-debug failures in 
# subsequent scenarios. If you do this, we recommend you create a Before
# block that will explicitly put your database in a known state.
Cucumber::Rails::World.use_transactional_fixtures = true

# How to clean your database when transactions are turned off. See
# http://github.com/bmabey/database_cleaner for more info.
if defined?(ActiveRecord::Base)
  begin
    require 'database_cleaner'
    require 'database_cleaner/cucumber'
    DatabaseCleaner.strategy = :truncation, {:except => %w[roles]}
  rescue LoadError => ignore_if_database_cleaner_not_present
  end
end

RAILS_ROOT/spec/spec_helper.rb

# This file is copied to ~/spec when you run 'ruby script/generate rspec'
# from the project root directory.
ENV["RAILS_ENV"] = 'test'
require File.expand_path(File.join(File.dirname(__FILE__),'..','config','environment'))
require 'spec/autorun'
require 'spec/rails'

# Uncomment the next line to use webrat's matchers
#require 'webrat/integrations/rspec-rails'

# Requires supporting files with custom matchers and macros, etc,
# in ./support/ and its subdirectories.
Dir[File.expand_path(File.join(File.dirname(__FILE__),'support','**','*.rb'))].each {|f| require f}

Spec::Runner.configure do |config|
  # If you're not using ActiveRecord you should remove these
  # lines, delete config/database.yml and disable :active_record
  # in your config/boot.rb
  config.use_transactional_fixtures = true
  config.use_instantiated_fixtures  = false
  config.fixture_path = RAILS_ROOT + '/spec/fixtures/'

  # == Fixtures
  #
  # You can declare fixtures for each example_group like this:
  #   describe "...." do
  #     fixtures :table_a, :table_b
  #
  # Alternatively, if you prefer to declare them only once, you can
  # do so right here. Just uncomment the next line and replace the fixture
  # names with your fixtures.
  #
  # config.global_fixtures = :table_a, :table_b
  #
  # If you declare global fixtures, be aware that they will be declared
  # for all of your examples, even those that don't use them.
  #
  # You can also declare which fixtures to use (for example fixtures for test/fixtures):
  #
  # config.fixture_path = RAILS_ROOT + '/spec/fixtures/'
  #
  # == Mock Framework
  #
  # RSpec uses its own mocking framework by default. If you prefer to
  # use mocha, flexmock or RR, uncomment the appropriate line:
  #
  # config.mock_with :mocha
  # config.mock_with :flexmock
  # config.mock_with :rr
  #
  # == Notes
  #
  # For more information take a look at Spec::Runner::Configuration and Spec::Runner
end

RAILS_ROOT/Gemfile

group :test, :cucumber do
  gem "cucumber-rails", "0.3.2"
  gem "rspec-rails", "1.3.3"
  gem "database_cleaner", "0.5.0"
  gem "capybara", "0.3.9"
  gem "selenium-client", "1.2.18"
  gem "sqlite3-ruby",  "1.3.1"
  gem "email_spec", "~> 0.6.3", :require => 'spec'
  gem "factory_girl"
  gem "launchy"
end

group :development do
  gem "factory_girl"
  gem "ruby-prof"
end

在 RAILS_ROOT/Gemfile 上

做: 将特定的仅供测试的 gem 添加到该组:

group :test do
  gem 'cucumber-rails'
  gem 'capybara'
  gem 'database_cleaner'
end

而不是将它们设置为用于开发和其他任何地方。 这应该有效。

P.S:编辑上面的代码来设置您将用于测试的宝石,我只是复制/粘贴了我在当前打开的项目中使用的宝石作为示例。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

rake cucumber 和 rake spec 始终使用“开发”环境 的相关文章

  • 避免在 Ruby 中自动从 Fixnum 转换为 Bignum

    我正在将算法从 C 移植到 Ruby 该算法有一个方法返回一个int有时会溢出 private static int NextRandom int n return 1234567890 n 12345 该算法利用溢出来避免该函数返回的值超
  • 程序“gem”可以在以下软件包中找到

    我正在 Virtual Box Ubuntu 13 10 上安装 Ruby on Rails 以下是步骤 ruby v gt 程序 ruby 可以在以下软件包中找到 尝试 sudo apt get install 来源 我的帐户 gt 好的
  • Rails 3.0.0.beta 和 Facebooker:还有其他人看到以下内容吗?

    我的 Rails 服务器在安装 facebooker 插件后似乎崩溃了 任何有关解决此问题的建议都会很棒 我正在使用 Rails 3 0 0 beta 和 facebooker 以下是我看到的步骤和错误 rails v Rails 3 0
  • Rails 验证日期范围的唯一性

    我有一个涉及员工缺勤记录的应用程序 我需要确保每条记录的开始日期和结束日期不重叠 例如 如果我输入了从今天开始到明天结束的缺勤记录 则不可能以任何方式在该日期范围内输入另一个缺勤记录 所以我不能制作一个从前天开始 然后在后天或任何更晚的日期
  • Ruby 代码到 JAR

    我希望能够将 ruby 程序编译为 java JAR 程序 我研究过 JRuby 看到了几个能够 eval ruby 代码的 Java 应用程序示例 但是是否有更优雅的解决方案允许简单地用 ruby 编写所有内容 然后将其直接编译为 JAR
  • Rails:调用其他模型的无表模型

    我有一个 Rails 应用程序 其中包含一些模型类 例如Category Subcategory User ETC 为了实现一个不太简单的过滤器功能 我构建了一个过滤器类的层次结构 FilterCategory FilterSubcateg
  • 存根 include_recipe 调用以不采取任何操作,但仍将配方计为包含的内容

    我的食谱的默认食谱仅包含其他几个食谱 我知道我可以使用以下方法测试是否包含适当的食谱 expect chef run to include recipe cookbook recipe name 但是当我像这样存根 include reci
  • Partial、Layout、Template 渲染问题

    情况 因此 当我访问页面时 我希望能够将布局应用到部分 我想要三个具有相同布局的部分 现在 我正在尝试使用以下命令来执行此操作 where shared services essay是这样的 p blah p div blah div
  • ruby 的 StringIO 类到底是什么?

    我想我明白StringIO有点类似于Java的StringBuffer类 但我不太完全理解 您将如何定义它及其在 Ruby 中的用途 可能的用途 只是希望能够消除我的困惑 no StringIO http ruby doc org stdl
  • Ruby 在带有偏移量的数组中查找

    我正在寻找一种以更简洁的方式在 Ruby 中执行以下操作的方法 class Array def find index with offset offset block offset 1 find block end end offset a
  • 如何使用 RSpec 检查 JSON 响应?

    我的控制器中有以下代码 format json render json gt flashcard gt flashcard lesson gt lesson success gt true 在我的 RSpec 控制器测试中 我想验证特定场景
  • Ruby:在 Ubuntu 上安装 rmagick

    我正在尝试在 Ubuntu 10 04 上安装 RMagick 看起来here https stackoverflow com questions 1482823 is there an easy way to install rmagic
  • 使用Rails UJS,如何从函数提交远程表单

    我正在使用Rails UJS 我有一个表单设置来进行远程提交 如下所示
  • gem install rmagick 在 OS X El Capitan 上失败

    几天前我升级到 El Capitan 并运行了 brew update brew upgrade 它更新了 imagemagick 导致 ruby 的 rmagick gem 停止工作 我想没问题 我就跑 gem install rmagi
  • (在 Ruby 中)允许混合类方法访问类常量

    我有一个为其定义常量的类 然后我定义了一个类方法来访问该类常量 这很好用 一个例子 usr bin env ruby class NonInstantiableClass Const hello world class lt lt self
  • 在 ruby​​ 中读/写受密码保护和加密的文件

    我想加密一个 ruby 程序将从中加载数据的文件 此外 我需要程序在启动时提示输入密码 该密码将用于解密文件 换句话说 该文件需要加密地驻留在计算机上 只有拥有密码的用户才能运行该应用程序 我已经开始研究 openpgp 但据我了解 这仍然
  • 是否可以让 Capistrano 通过反向 SSH 隧道进行结帐?

    我正在开发一个驻留在公共主机上的应用程序 但我必须将其源代码保存在公司防火墙后面的 Git 存储库中 我越来越very厌倦了通过缓慢的部署scp 复制整个存储库并在每次部署时通过 SSH 传送 并且希望远程主机只需执行git pull更新
  • 由于符号链接错误,无法在 Mac OSX 10.8.1 中安装 ruby​​-1.9.2

    首先 我尝试了常见的rvm安装 rvm安装1 9 2 但是 显示了以下错误 The provided compiler usr bin gcc is LLVM based it is not yet fully supported by r
  • 错误“未初始化常量 AWS (NameError)”

    它说 AWS 未初始化 我正在使用 aws sdk core gem 我尝试使用 aws sdk gem 代替 问题仍然存在 这是initializers aws rb 文件 AWS config access key id gt ENV
  • Rails 3 - “无法解析 Yaml”

    我不知道我做错了什么 我尝试运行 rails c 但它只是给了我一个错误 10 分钟前它还在工作 C Ruby192 lib ruby 1 9 1 psych rb 148 in parse couldn t parse YAML at l

随机推荐

  • BPEL Designer for Eclipse:如何调试 BPEL 流程

    我正在尝试调试 BPEL 流程 我使用 BPEL Designer for Eclipse 3 7 2 制作它 我使用 Ode 1 3 作为引擎 我不知道如何调试我的过程 我可以在调试会话中将它部署在 ode 上 但我真的不明白之后我能做什
  • 如何使用 Google Sheets (v4) API 修改依赖于特定单元格的特定数据行?

    我想找到一种使用 Google API 根据我提供的条件修改特定行数据的方法 类似于 SQL 的东西 UPDATE Customers SET ContactName Alfred Schmidt City Frankfurt WHERE
  • 如何打开带有预填充附件的 Outlook 新邮件窗口

    当用户单击我的应用程序中的某些按钮或链接时 我需要打开一个带有预填充附件的新电子邮件窗口 老问题 但我也遇到了这个问题 所以这里有一个复制和粘贴解决方案 Microsoft Office Interop Outlook Applicatio
  • 多个容器 POD 中的一个容器进程崩溃会发生什么情况?

    通常在单容器POD中 当容器的主进程崩溃时 Pod会重新启动 如果有多个容器 POD 如果第二个容器中的一个进程崩溃 会发生什么情况 POD 会重新启动吗 来自文档here https kubernetes io docs concepts
  • Rails 4 单选按钮表单助手,true 不验证

    我在 needs dist 上附加了简单的是或否单选按钮 当我提交表单时选择 否 它工作得很好 但是当我选择 是 时 它会抛出验证错误吗 它仅在 needs dist gt true 时有效 Model validates presence
  • 如何读取大型平面文件

    我有一个平面文件 其中包含 339276 行文本 大小为 62 1 MB 我试图读入所有行 根据我所拥有的某些条件解析它们 然后将它们插入数据库 我最初尝试使用 bufio Scan 循环和 bufio Text 来获取该行 但缓冲区空间不
  • cosmosdb 模拟器没有给出任何结果

    我不知道为什么在查询宇宙数据库时会发生这种情况 它不会显示任何文档 即使是 SELECT FROM c 但显示了 RU 但它与文档选项卡中的文档选项卡配合得很好 如果我使用任何过滤器 那么它也可以工作 但它不适用于 SQL 查询 我已经添加
  • 我如何知道 C 程序的可执行文件是在前台还是后台运行?

    在我的 C 程序中 我想知道我的可执行文件是否像这样在前台运行 a out 或者像这样 a out 如果你是前台工作 getpgrp tcgetpgrp STDOUT FILENO or STDIN FILENO or STDERR FIL
  • 验证属性被触发两次

    在我的 MVC3 应用程序中 我有模型 未删除重要属性 public class AccountViewModel StringLength 65 public string Property1 get set StringLength 6
  • 锁定 ASP.NET 应用程序变量

    我在 ASP NET 应用程序中使用第三方 Web 服务 对第 3 方 Web 服务的调用必须同步 但 ASP NET 显然是多线程的 并且可能会发出多个页面请求 从而导致对第 3 方 Web 服务的同时调用 对 Web 服务的调用封装在自
  • 如何更改对话框片段内的片段

    我想做一个空的DialogFragment with a LinearLayout然后更改里面的片段LinearLayout 例如 第一个片段是 3 个按钮 facebook google 电子邮件登录 的登录 当有人按下电子邮件时 第 2
  • 除括号之间的内容外,所有内容均小写

    考虑以下字符串 LoReM FOO IPSUM dolor BAR Samet fooBar 我正在寻找一种方法来小写所有内容 除了 brackets 之间的内容应该被忽略 所以期望的输出是 lorem FOO ipsum dolor BA
  • 角度 - 传递管道作为变量

    如何存储和使用变量中的管道信息 我已经搜索了很多 但找不到解决方案 我想要实现的是将任何有效的管道信息作为变量 小数 百分比 日期 自定义等 传递 下面是一个简单的例子 父组件 ts columnsDef value 0 35 pipeIn
  • 响应式网格布局框架[关闭]

    就目前情况而言 这个问题不太适合我们的问答形式 我们希望答案得到事实 参考资料或专业知识的支持 但这个问题可能会引发辩论 争论 民意调查或扩展讨论 如果您觉得这个问题可以改进并可能重新开放 访问帮助中心 help reopen questi
  • 在没有模型的情况下将自定义页面添加到 django admin

    我正在尝试在没有模型关联的情况下向管理员添加自定义页面 这就是我迄今为止所取得的成就 class MyCustomAdmin AdminSite def get urls self from django conf urls import
  • 每次 UIScrollView 释放时都会发生内存泄漏

    在我的应用程序中 我有一个滚动视图和四个表格视图 每次拖动然后释放时 我都会泄漏 48 字节 这确实很重要 正如您所看到的 两组泄漏都有相同的来源 有人见过这样的泄漏吗 Edit 1 当我单击泄漏旁边的箭头时 我会得到泄漏的以下信息 您所看
  • 查找其索引的乘积可被另一个数字 X 整除的对的数​​量

    给定一个数组和某个值 X 找到满足以下条件的对的数量 i lt j a i a j and i j X 0 Array size lt 10 5 我想这个问题有一段时间了 但只能想出蛮力解决方案 通过检查所有对 这显然会超时 O N 2 t
  • 使用 Objective C 将 RGB 彩色图像更改为灰度图像

    我正在开发一个将彩色图像更改为灰度图像的应用程序 然而 有些图片显示出来是错误的 我不知道代码有什么问题 也许我输入的参数有误 请帮忙 UIImage c UIImage imageNamed downRed png CGImageRef
  • 如何检查主音量是否静音

    如何在 Windows 7 操作系统中检查主音量是否静音我有静音或取消静音的代码 IE Public Const APPCOMMAND VOLUME MUTE As Integer H80000 Public Const APPCOMMAN
  • rake cucumber 和 rake spec 始终使用“开发”环境

    我运行 Cucumber 和 RSpec 测试的 rake 任务始终使用我的development环境 以下是相关的配置文件 RAILS ROOT config environments cucumber rb Edit at your o