我一直无法找到很多关于编写好RSpec控制器测试的文档或建议。具体来说,你应该使用Rails的assert_select
,它感觉与RSpec非常不同,还是有其他选择?对RSpec控制器测试使用assert_select是否正确?
下面的例子是最佳实践吗?
describe ArticlesController do
render_views
let(:article) { create(:article) }
describe "show" do
it "should display the article title" do
get :show, id: article
response.should be_success
assert_select "h1", article.title
end
end
end
我不想编写单独的视图测试,因为这很不方便。
Rspec的的doc住在这里:https://开头WWW .relishapp.com/rspec。但没有什么特别的关于你的问题 – apneadiving 2012-03-08 15:53:39