测试对象是否调用方法

时间:2014-05-17 08:16:21

标签: rspec

我对Rspec和Rails相当新。我想测试如果运行方法没有运行,并且确认为true,则不会调用execute方法。我应该怎么写这个rspec测试?

class Release

  def run(confirm=false)
    execute if confirm
  end

  def execute
    # do something
  end

1 个答案:

答案 0 :(得分:0)

it "should not execute without confirmation" do
  release = Release.new
  release.run
  expect(release).not_to have_received(:execute)
end