为 Spree 应用编写测试套件

Writing a test suite for a Spree app

我想使用 FactoryGirl 和 RSpec 为我的 Spree 应用构建一个测试套件。我应该从头开始编写测试,还是可以以某种方式利用现有资源,这样我就不会重复代码?

spree/core/spec/models/spree 中有很多 _spec.rb 个文件。如果 运行 rspec spec 和 运行 核心狂欢测试套件加上我编写的任何测试,那就太好了。

Spree documentation 推荐 运行ning bundle exec rake test_app 到 "build the appropriate test application inside of your spec directory." 当我 运行 该命令时,我收到此错误消息:

rake aborted! Don't know how to build task 'ecommerce' (see --tasks)

Spree 使用此行安装在 config/routes.db 中:mount Spree::Core::Engine, at: '/'.

我很想拥有 "appropriate files" 这样我就不必编写很多已经编写的测试,但我很难过。感谢您的任何提示。

来自 Spree 文档:

Spree consists of several different gems (see the Source Code Guide for more details.) Each of these gems has its own test suite which can be found in the spec directory. Since these gems are also Rails engines, they can't really be tested in complete isolation - they need to be tested within the context of a Rails application.

You can easily build such an application by using the Rake task designed for this purpose, running it inside the component you want to test:

$ bundle exec rake test_app

换句话说,如果您想测试 Spree 本身,请为此特定目的构建一个新的 Rails 应用程序。

我怀疑这真的是你想要做的。如果您为自己的应用程序编写测试,即使它使用 Spree,您也不需要测试 Spree 本身,只需测试您编写的代码。据推测,Spree 的作者 运行 在将每个新版本发布到野外之前进行了这些测试。