1

I've been in Factory land for the past few years and have decided to come back to fixtures but am running into a problem.

In my test_helper.rb I have

class ActiveSupport::TestCase
  fixtures :all
end

Then in an individual test case I might be doing something like users(:one) however the data for users(:two) and the data for other tables that I am not calling on seems to be present in the test database.

So, is this the expected behavior? I have a hard to believing it is, seems strange from an isolated testing perspective.

4

1 回答 1

1

fixtures :all发生这种情况是因为您从语句中一次加载所有固定装置。测试中的经验法则是仅加载给定测试所需的数据(不是全部)。这也可能会减慢您的测试运行时间。

如果您只想加载选定的灯具,您可以这样做

fixtures :<fixture name>

前任:

fixtures :users

阅读更多关于固定装置的信息。

还有一件事,你是否有特别的理由重返赛程。工厂是要走的路;它们允许您干净地组织您的测试数据。

阅读更多关于工厂的信息。

于 2013-04-17T04:47:06.907 回答