Rspec检查方法在块内执行

时间:2013-04-11 11:28:33

标签: ruby unit-testing rspec

class Foo
  def self.with_context
    # some preprocessing stuff
    yield
    # some postprocessing stuff
  end

  def self.bar
    with_context do
      #some stuff here
    end
  end
end

如何测试Foo.bar方法是在Foo.with_context?

中运行的

它应该传递上面的例子。

但是在下面的例子中应该失败:

class Foo
  def self.with_context
    # some preprocessing stuff
    yield
    # some postprocessing stuff
  end

  def self.bar
    #some stuff here ( not within the with_context block - FATAL)
  end
end

0 个答案:

没有答案