Rspec:是否有可能在一个类上存活?

时间:2012-10-30 13:12:14

标签: ruby rspec

问题在标题中。让我们说例如我有一个班级:

class A
  def self.something
    p 'Something'
  end

  def call_something
    self.class.something
  end
end

我想编写一个测试,instance a class A方法调用:a.call_something实际上会调用A.something。这可能吗?

1 个答案:

答案 0 :(得分:2)

尝试它怎么样?我猜这有效

describe '#call_something' do
  it 'calls something in classA' do
    a = ClassA.new
    ClassA.should_receive(:something)
    a.call_something
  end
end