【发布时间】:2015-10-30 13:37:01
【问题描述】:
假设我正在开发一个 cmets 功能,我想将它添加到我正在开发的应用程序中。
我可以通过功能测试来测试它:
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
但是如果我还添加一个功能,用户可以决定评论是否需要批准。如果不需要批准,则上述测试将起作用。但是,如果用户更改设置并决定评论在发布前需要获得批准,则此测试将不起作用(此设置可通过管理面板进行调整)。
编写涵盖所有这些场景的测试的好方法是什么?
【问题讨论】:
标签: ruby-on-rails testing rspec tdd bdd