开发者

Sharing Rspec tests between classes

开发者 https://www.devze.com 2023-01-28 02:42 出处:网络
Hey all; in writing tests from controller to controller with rspec, I\'ve found myself 开发者_如何学Cduplicating a few basic tests, such as this check for index:

Hey all; in writing tests from controller to controller with rspec, I've found myself 开发者_如何学Cduplicating a few basic tests, such as this check for index:

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

I feel that the test is important, just redundant, when added to five different controllers. Is there some way to share tests between controller classes, or include specific code blocks with a method call in rspec? Or is it best practices to duplicate, in this case?


Yes you can, and I think it will lead to cleaner code.

0

精彩评论

暂无评论...
验证码 换一张
取 消