如何避免测试重复?

时间:2017-02-17 05:39:41

标签: ruby-on-rails rspec

此代码出现在我的两个规范中:

it 'does not add the reply' do
  expect { subject }.not_to change { replies.length }
end

it 'does not publish the event' do
  expect { subject }.not_to publish_event(:reply_event)
end

我应该如何编写规范以避免重复?

1 个答案:

答案 0 :(得分:1)

您可以在以下博客

中详细创建一个类似于show的帮助器

https://niallburkley.com/blog/rspecs-shared_examples_for/

相关问题