问题标签 [database-cleaner]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
ruby-on-rails - 带有 Rails、Rspec、Capybara 的 Database_cleaner。烦人的删除。如何控制它们?
为了简单起见,我有一个模型 Canvas 和一个模型 Block。
在我的每个画布视图(这只是一个基本表)上,我都有一些旨在更新某些块内容的表单。
我想用 RSPEC 和 Capybara 测试更改是否正确提交。
所以我有这条线:
发送到我的 BlocksController
我可以向您保证,我的画布视图和所有控制器/模型都可以正常工作。
但是测试失败并出现此错误:
所以我查看了我的测试日志,发现 Database_cleaner 似乎在我完成工作之前删除了一些表:
如您所见,大多数情况下,更新请求甚至都没有尝试过。(我通过一次又一次地运行测试看到了它)。
所以我的问题是,有人知道如何延迟这些删除吗?
十分感谢 !
PS:
数据库清理器的配置与此链接中的一样:
我曾多次尝试改变策略,但没有任何帮助。
ruby-on-rails-3 - 数据库清理器不清理一个黄瓜场景
所以我的团队正在使用 Cucumber、Rspec 和使用这些测试框架所需的所有 gem 来推出我们的 rails 应用程序(一个调查和 lite 电子记录系统)。我正在设置 Jenkins CI 服务器,并希望在我们的测试、开发和暂存环境中标准化我们的数据库(我们最终选择了 MySQL)。
在将测试环境从 SQlite 切换到 MySQL 后,我们发现了一些与缓存相关的测试错误,我们通过使用相对 id 而不是硬编码的 id 解决了这些错误。例子:
在解决了这个失败的规范之后,我解决了一些不相关的 ajax 问题,这些问题永远困扰着我们的测试套件。想着终于掌握了测试的艺术,我自信地跑了起来rake
。我遇到了这种不友好的景象:
现在,当孤立运行时,当然会cucumber features/presenting_default_questions.feature
下雨。
失败场景:
相关步骤:
除了使用之外Capybara.javascript_driver = :webkit
,黄瓜/数据库清理器配置未修改rails g cucumber:install
。
似乎失败的 rspec 和 cucumber 测试都遇到了同样的索引问题。虽然上面提出的解决方案有效,但它非常笨拙,并提出了一个问题,即为什么简单的绝对索引不起作用(在每个场景和功能之间清理了所有数据库之后)。我的测试有问题吗?使用 database_cleaner?
如果更多代码会有所帮助,请告诉我!
相关宝石版本:
- 活动模型(3.2.14)
- 黄瓜 (1.3.6)
- 黄瓜导轨 (1.3.1)
- database_cleaner (1.0.1)
- 水豚 (2.1.0)
- 水豚 webkit (1.0.0)
- mysql2 (0.3.13)
- rspec (2.13.0)
ruby-on-rails - 将 DataBase Cleaner gem 与 DataMapper 一起使用
我正在使用 RSpec 和 FactoryGirl 编写测试。在我的模型中使用了 DataMappers。在 RSpec 中,我正在测试我的控制器的两个方法更新和索引函数,其中我使用两个对象 A、B 和 C。我使用 FactoryGirl 创建了它们,如下所示:
现在我想在每次测试后用 DataBase Cleaner Gem 清理它们。我在 Google 中搜索过它,但大多数文章都讨论了如何将 DataBase Cleaner Gem 与 ActiveRecord 一起使用,但没有一篇文章明确说明如何将 DataBaseCleaner gem 与 DataMapper 一起使用。因此,如果有人给我使用 DataMapper 的带有 DataBase 清洁器的 RSpec 文件的小示例,我将不胜感激。提前致谢。
ruby - 关于ORMs和使用事务策略清理数据库的两个问题
我正在使用现有的 Cucumber 和 Ruby 套件编写概念验证测试。我为之做这件事的公司有一个堆栈,其中包括 Java 和 DB2 等。
目前使用数据库的测试会降低我们的测试数据库,并且由于许多原因,我无法擦除数据库并用映像版本替换它。
我对使用事务策略清理数据库的想法很感兴趣,我正在考虑使用 database_cleaner gem。
似乎 database_cleaner 需要一个 ORM 才能使用。此时我无权访问架构,ActiveRecord 无法使用我的凭据访问它需要的内容。
两个问题:
- ORM 是否总是需要访问模式?
- 您是否总是需要 ORM 来使用事务策略清理数据库?
如果有人知道可以与 ruby 1.8.7(还没有 jRuby)、windows、DB2 等一起使用的 gem,那也是一个奖励。
ruby-on-rails - 为什么 DatabaseCleaner 导致此 RSpec 控制器测试失败?
我正在尝试使用 RSpec 设置 DatabaseCleaner 以确保我可以正确清理我创建的任何测试对象。如果我不使用 DatabaseCleaner,则以下测试通过。
但是,当我将 DatabaseCleaner 代码添加到我的spec_helper.rb
文件时,测试失败,如下所述。
这是控制器:
这是我spec/spec_helper.rb
文件的相关部分:
奇怪的是,删除DatabaseCleaner.clean
语句实际上也不会使测试通过。但是,删除DatabaseCleaner.start
代码确实会使测试通过。
测试失败,因为控制器找不到具有正确 ID 的 BulkJob。如果我打印出对象的计数,则在测试中 BulkJobs 的数量为 1,但在控制器内部,它为 0。当测试通过时,显然,两个点的数字都是 1。
我没有包括 Capybara 或 Selenium,所以据我了解,rspec 应该使用 rack-test 来运行这个示例。
我的配置/测试有问题吗?DatabaseCleaner 清理太早了吗?
这是失败的测试:
和我的 Gemfile:
ruby-on-rails - How can I clean my database between erroneous rspec specs?
I have added the database_cleaner gem to my rails application in order to clean my database between specs. Here's my current configuration for database_cleaner, located in spec/spec_helper.rb
:
Now, this configuration works fine, so long as every last spec that is run either passes or fails.
However, in the event of an error (rspec doesn't give you a nice little E
like minitest, it throws this sort of thing:
), the database isn't cleaned! Residual data from the spec just before the error stays in the database. I suppose this is because database_cleaner doesn't regard the erroneous spec as finishing and so doesn't clean the database.
Now, this doesn't really cause any harm until you run your specs again. The residual data then causes an error analogous to this:
Getting around this error is simple enough; running rails_env=test rake db:reset
or firing up your database shell and emptying the relevant tables with sql statements will clear this data and allow the specs to be run without a hitch.
However, this is getting annoying. One wrong character in any of my specs (anything to make it erroneous rather than a failure) causes my whole testing workflow to jam up, almost like the firing mechanism of an automatic weapon!
What are your suggestions regarding database_cleaner? Do you have any example configurations that allow for the database to be cleaned, even in the event of an erroneous test?
I'm using guard to run my rspecs that are further augmented with factory-girl:
Gemfile:
spec/spec_helper:
rspec - Rails 中的 TX 不应该有 requires_new: true 的任何原因
与此问题相关:自定义事务不适用于 rspec 中的 database_cleaner
有什么地方不想用 requires_new 开始 TX 吗?(其中嵌套 TX)
如果是这样的话,这应该是默认值。
顺便说一句,这是使用默认事务策略时,当代码的正常执行路径成功时,带有回滚的 rspec 测试将失败的原因。
这是我的 DatabaseCleaner 设置。运行导轨 4.
ruby-on-rails - Rails minitest,数据库清理器如何转use_transactional_fixtures = false
我想在 ministest 中禁用 use_transactional_fixtures = false 以捕获 after_commit 回调。我应该在哪里设置什么?
ruby-on-rails - 使用 Rails、Rspec、Selenium 和 use_transactional_fixtures 的数据库不一致
我遇到了一个问题:
- 导轨 (3.2)
- Rspec (2.14.1)
- 数据库清理器 (1.2.0)
这是我的 Rspec 配置的样子:
我会在我的块中创建记录,before(:each)
但我不会在我的应用程序代码中看到它们。
这会导致问题,因为我期望不存在的对象。
经过多次尝试,我终于找到了我的问题的答案。
ruby-on-rails - DatabaseCleaner + RSpec : what is the correct configuration?
I included database_cleaner
gem in my rails app. Followed the example given on the git repo and included the following code in spec_helper
:
Approach 1
When i run the rspec
i get error as NoMethodError:undefined method 'cleaning' for DatabaseCleaner:Module
.
So i did some research and found that i could replace the config.around
block above with something like this :
Approach 2
OR
Approach 3
Both Approach 2 and 3 work well.
I also looked in the git repo of database_cleaner and found that cleaning
method actually exists and with the following code :
which is exactly same as what i did in example 3. If it does exists then why is it not accessible? Am i missing something here. Any more setup? Or is Approach 2 or 3 preferable?