大家好;在使用 rspec 编写从 Controller 到 Controller 的测试时,我发现自己重复了一些基本测试,例如索引检查:
describe "on GET to index" do
it "renders the index template" do
get :index
response.should render_template('index')
end
end
当添加到五个不同的 Controller 时,我觉得测试很重要,只是多余的。有没有办法在 Controller 类之间共享测试,或者在 rspec 中包含带有方法调用的特定代码块?或者在这种情况下复制是最佳实践吗?
最佳答案
是 you can ,我认为这会导致代码更简洁。
关于ruby-on-rails - 在类之间共享 Rspec 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4330221/