Ruby on rails 如何为';什么是由用户决定的?
假设我正在开发一个注释功能,我想将它添加到我正在开发的应用程序中 我可以通过功能测试对其进行测试:Ruby on rails 如何为';什么是由用户决定的?,ruby-on-rails,testing,rspec,tdd,bdd,Ruby On Rails,Testing,Rspec,Tdd,Bdd,假设我正在开发一个注释功能,我想将它添加到我正在开发的应用程序中 我可以通过功能测试对其进行测试: scenario "they can comment on a book" do visit book_url(book) fill_in "Name", with: "John" fill_in "Comment", with: "This is a comment." click_button "Add Comment" expect(current_path).to
scenario "they can comment on a book" do
visit book_url(book)
fill_in "Name", with: "John"
fill_in "Comment", with: "This is a comment."
click_button "Add Comment"
expect(current_path).to eq(book_path(book))
expect(page).to have_text("Your comment is successfully added")
expect(page).to have_text(Comment.last.content)
end
但是,如果我还添加了一个功能,用户可以决定评论是否需要批准,该怎么办。如果它不需要批准,那么上面的测试就可以了。但是,如果用户更改了设置,并决定评论在发布前需要获得批准,则此测试将不起作用(此设置将通过管理面板进行调整)
编写涵盖所有这些场景的测试的好方法是什么?您是否考虑过针对每种情况的单独测试?即,分别测试不需要批准的情况和需要批准的情况。也许是这样的:
feature "making comments when approval is not required" do
background do
// turn off the "approval required" setting
end
scenario "adding a comment" do
// assertions
end
end
feature "making comments when approval is required" do
background do
// turn on the "approval required" setting
end
scenario "adding a comment" do
// assertions
end
end
请注意,我没有使用Ruby或RSpec——只是进行了一些快速搜索——因此这可能不是实现您所需的最惯用的方法
编辑:或者类似的东西
feature "making comments" do
scenario "when approval is required" do
// require approvals
// assertions
end
scenario "when approval is not required" do
// turn off approval requirement
// assertions
end
end