我想使用 FactoryGirl 来构建模型的内存存根,然后让所有 ActiveRecord 查询仅针对这些查询运行。例如:
# Assume we start with an empty database, a Foo model,
# and a Foo factory definition.
#foo_spec.rb
stubbed_foo = FactoryGirl.build_stubbed(:foo)
# Elsewhere, deep in the guts of application
Foo.first() # Ideally would return the stubbed_foo we created
# in the test. Currently this returns nil.
解决方案可能是使用内存数据库。但上述情况可能吗?