Подтвердить что ты не робот

Есть ли способ размотать в RSpec?

Искал документы Relish, но не нашел способ развёртывания в RSpec.

Возможно ли это?

4b9b3361

Ответ 1

rspec-mock указывает, что вы можете вызвать метод unstub. Я цитирую:

  # Removes a stub. On a double, the object will no longer respond to
  # `message`. On a real object, the original method (if it exists) is
  # restored.
  #
  # This is rarely used, but can be useful when a stub is set up during a
  # shared `before` hook for the common case, but you want to replace it
  # for a special case.
  def unstub(message)
    ::RSpec::Mocks.space.proxy_for(self).remove_stub(message)
  end

Ответ 2

С новым синтаксисом expect unstub устарел. Вы можете сделать:

# stub
allow(SomeClass).to receive(:a_method)

# do something...

# unstub
allow(SomeClass).to receive(:a_method).and_call_original

Если первый allow содержит .with или блок, я считаю, что он все равно перенесет следующий вызов, поэтому следующий allow не очищает эти вещи.