我对如何组织集成测试有点困惑。现在,它们根据页面结构进行组织:
post_pages_spec.rb:
require 'spec_helper'
describe "Post pages" do
describe "show page" do
describe "post destruction" do
end
describe "edit" do
end
end
describe "post creation" do
end
end
如您所见,删除和编辑位于显示操作中,因为它们显示在显示页面中。
这是组织它们的另一种方式(基于 REST 操作):
post_pages_spec.rb:
require 'spec_helper'
describe "Post pages" do
describe "show page" do
end
describe "post destruction" do
end
describe "post creation" do
end
describe "edit" do
end
end
哪种结构更清晰,更容易维护?
假设您真的在询问集成测试而不是控制器测试,我喜欢从用户的角度和用户类型来组织集成测试。 例如,一个文件用于注册用户,一个文件用于管理员,一个文件用于非注册用户等,并根据需要。
这样做的理由是,我发现,作为一个一般的启发式方法,相同的用户类型具有相同的功能先决条件,因此非常适合在一起。例如,查看帖子的注册用户可能有很多场景专注于 CRUDing 现有帖子内容,而非注册用户可能具有专注于帖子推荐的场景。由于这些不同的视角可能会有不同的设置和拆卸,因此它们也可能更容易(即。干涸等)单独维护。
此外,它读起来很:)前任:
describe "Registered User" do
context 'creating a Post' do
it "succeeds given all fields are filled out"
it "displays errors to the author if a field is missing"
end
end