在类之间共享Rspec测试

时间:2010-12-01 23:30:02

标签: ruby-on-rails unit-testing rspec

嘿所有;在使用rspec从控制器到控制器编写测试时,我发现自己复制了一些基本测试,例如检查索引:

describe "on GET to index" do
  it "renders the index template" do
    get :index
    response.should render_template('index')
  end
end

当我添加到五个不同的控制器时,我觉得测试很重要,只是多余的。有没有办法在控制器类之间共享测试,或者在rspec中包含方法调用的特定代码块?或者,这是复制的最佳做法,在这种情况下?

1 个答案:

答案 0 :(得分:3)

you can,我认为这会带来更清晰的代码。

相关问题