为什么黄瓜场景只有在运行完整的测试套件之后才会失败?

时间:2021-09-18 20:28:37

If I run the specific scenario, it's all green. If I only run the cucumber suite (aka. rake cucumber), it's all green. However, if I run the full test suite, (aka. rake), a single scenario fails.

如果我运行特定的场景,它都是绿色的。如果我只运行黄瓜套件。黄瓜耙),都是绿色的。但是,如果我运行完整的测试套件(aka)。rake),一个场景失败。

I assume this has something to do with the state of the database and my configuration. I wrote the cucumber scenarios to assume an initially empty database, and I'm building small datasets for the individual scenarios.

我假设这与数据库的状态和我的配置有关。我编写了黄瓜场景来假设一个初始的空数据库,并且我正在为每个场景构建小的数据集。

I'm using DatabaseCleaner, with the truncation strategy, and my understanding is that this will wipe the db clean. Am I mistaken? Is there data lingering that might have been created when the unit and functional tests ran? Is there a quick way to ensure that cucumber starts clean?

我使用的是DatabaseCleaner,使用的是截断策略,我的理解是这会清除db。我错了吗?当单元测试和功能测试运行时,是否存在可能创建的数据延迟?有没有快速的方法来确保黄瓜开始清洁?

Happy to start posting code and wading into config specifics...

很高兴开始发布代码并详细介绍配置……

thanks

谢谢

1 个解决方案

#1


2  

Head in hands. Deep shame.

在手中。深深的耻辱。

I was never actually cleaning the database.

我从来没有清理过数据库。

I was setting the strategy but never pulling the trigger.

我在制定策略,但从来没有扣动扳机。

features/support/env.rb

特性/支持/ env.rb

Before:

之前:

begin
  DatabaseCleaner.strategy = :truncation
rescue NameError
  raise "You need to add database_cleaner to your Gemfile (in the :test group) if you wish to use it."
end

After:

后:

begin
  DatabaseCleaner.strategy = :transaction
  DatabaseCleaner.clean
rescue NameError
  raise "You need to add database_cleaner to your Gemfile (in the :test group) if you wish to use it."
end

Don't let it happen to you.

不要让这种事发生在你身上。

Sigh.

叹息。

#1


2  

Head in hands. Deep shame.

在手中。深深的耻辱。

I was never actually cleaning the database.

我从来没有清理过数据库。

I was setting the strategy but never pulling the trigger.

我在制定策略,但从来没有扣动扳机。

features/support/env.rb

特性/支持/ env.rb

Before:

之前:

begin
  DatabaseCleaner.strategy = :truncation
rescue NameError
  raise "You need to add database_cleaner to your Gemfile (in the :test group) if you wish to use it."
end

After:

后:

begin
  DatabaseCleaner.strategy = :transaction
  DatabaseCleaner.clean
rescue NameError
  raise "You need to add database_cleaner to your Gemfile (in the :test group) if you wish to use it."
end

Don't let it happen to you.

不要让这种事发生在你身上。

Sigh.

叹息。